Choose Language Hide Translation Bar
Highlighted
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!

5 REPLIES 5
Highlighted
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
Highlighted
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?

 

Highlighted
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
Highlighted
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

Highlighted
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
Article Labels