cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Sebnem
Level II

rolling moving average

Hi,

 

I want to create a new column "moving average" and want this column to do rolling average of temp based on ID. I attached a sample file here. Can you please help with the formula?

 

thanks!

7 REPLIES 7
txnelson
Super User

Re: rolling moving average

Assuming that your definition of "Rolling Average" is a "Moving Average" the formula is

Col Moving Average( :Temp, :ID )

Documentation and Examples of the Col Moving Average() are in the Scripting Index

     Help==>Scripting Index 

Jim
Sebnem
Level II

Re: rolling moving average

Hi Jim

 

I used this formula but this does not deliver what I was expecting.

 

First: I want to create column which is the mean of temp by ID

Then, I want to mean of the new column over "X (X is user defined)" number of IDs.

Can you please help with that?

 

txnelson
Super User

Re: rolling moving average

If you read the documentation on the Col Moving Average() function, it allows for the setting of what I believe you are referring to as X.

Could you please provide some sample results.  I am still not understanding your request.

Jim
Sebnem
Level II

Re: rolling moving average

I looked into big class sample data set and created a column:

 

Col Moving Average( :height, 1, 5, 0, :sex )

 

What does 5 do in the calculation?

 

I was able to manually calculate the moving average until the row#9---How was 58.833333333 calculated? I am not able to generate the same number manually

txnelson
Super User

Re: rolling moving average

The 5 in the function call is specifying the number of rows before the current row to include in the moving average.  You can actually specify the function in the following way.....which is really the way it should be called, to make the script more readable

Col Moving Average( :height, weighting=1, Before=5, after=0, :sex )

In your manual calculation you have to remember that the moving average is being tracked for both Males and Females.  And the average does not restart every time the data changes from F to M or M to F.  It is treating the calculations as if there are 2 separate columns.

Jim
AdamChoen
Level IV

Re: rolling moving average

I guess sometimes the data needs to be sorted (e.g. time-dependent column).
Or is there an argument in the function that is referring to such cases?

Thanks, Adam
txnelson
Super User

Re: rolling moving average

Col Moving Average() will be calculated separately for each level of the By() columns, such as the Sex column in my example, however, the moving average will be calculated in row order.  So the data may have to be sorted to get the desired results. 

Jim