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
anandk
Level II

Moving average and Weighted moving average on a data set

Hi,

 

I am trying to do a moving average and a weighted moving average on the data set that I have posted below.

I want to do a moving average to the 'Mean' column.

Also can I repeat this formula by the 'Sample' group in my data set

14 REPLIES 14
anandk
Level II

Re: Moving average and Weighted moving average on a data set

I am not seeing the Col Moving Average function in JMP 12

txnelson
Super User

Re: Moving average and Weighted moving average on a data set

The Col Moving Average() function was added in JMP 13.  So, for JMP 12 you will need to used the code I provided.  And all you need to do, is to add the division by 16 to the code.  Make sure you divide the 1,2,3,4 lag subsets with the appropriate subset the the 16

Jim
anandk
Level II

Re: Moving average and Weighted moving average on a data set

If( :sample != Lag( :sample, 1 ) | Row() == 1,
counter = 0
);
counter = counter + 1;
If(
counter == 1, :Mean1,
counter == 2, Mean( Lag( ::Mean1, 1 ) * 1, Lag( ::Mean1, 1 ) * 4 ) / 16,
counter == 3,
Mean( Lag( ::Mean1, 1 ) * 1, Lag( ::Mean1, 1 ) * 4, Lag( ::Mean1, 1 ) * 6 )
/ 16,
counter == 4,
Mean(
Lag( ::Mean1, 1 ) * 1,
Lag( ::Mean1, 1 ) * 4,
Lag( ::Mean1, 1 ) * 6,
Lag( ::Mean1, 1 ) * 4
) / 16,
Mean(
Lag( ::Mean1, 1 ) * 1,
Lag( ::Mean1, 1 ) * 4,
Lag( ::Mean1, 1 ) * 6,
Lag( ::Mean1, 1 ) * 4,
Lag( ::Mean1, 1 ) * 1
) / 16
);

 

Will the formula look like this or I have to divide the Lag of weights 1 and 4 by 5 and so on?

txnelson
Super User

Re: Moving average and Weighted moving average on a data set

For the cases where "Counter" is less than 5, you need to adjust the divisor down to the sum of the weights for each of those levels, so the code should look like:

If( :sample != Lag( :sample, 1 ) | Row() == 1,
	counter = 0
);
counter = counter + 1;
If(
	counter == 1, :Mean1,
	counter == 2, Mean( Lag( ::Mean1, 1 ) * 1, Lag( ::Mean1, 1 ) * 4 ) / 5,
	counter == 3, Mean( Lag( ::Mean1, 1 ) * 1, Lag( ::Mean1, 1 ) * 4, Lag( ::Mean1, 1 ) * 6 ) / 11,
	counter == 4,
		Mean( Lag( ::Mean1, 1 ) * 1, Lag( ::Mean1, 1 ) * 4, Lag( ::Mean1, 1 ) * 6, Lag( ::Mean1, 1 ) * 4 ) /
		15,
	Mean(
		Lag( ::Mean1, 1 ) * 1,
		Lag( ::Mean1, 1 ) * 4,
		Lag( ::Mean1, 1 ) * 6,
		Lag( ::Mean1, 1 ) * 4,
		Lag( ::Mean1, 1 ) * 1
	) / 16
);
Jim
anandk
Level II

Re: Moving average and Weighted moving average on a data set

I dont see the Col Moving Average function in JMP 12