cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
HarriBradbeer
Level II

Lag formula not working when scripted

I have some experimental data that takes a measurement every minute for 10 minutes.

I then want to take an average for a subset of data points in the middle of the set.

My solution is to have a hidden column (:Range) with a formula that contains the criteria (input via a modal window) and sets each row as either 1 or 0 if it's to be included in the calculation.

My output column then uses the Col Mean function to take the average of the points of interest.

 

This part is working great, but I also want the first blank row (not included in the calculation) to take the value of the next row, which will help with further data manipulation down the line. I've added the Lag function as below.

 

 

If( :Range == 1,
	Col Mean( :Measurement, :ID, :Range ),
	Lag( :Measurement, -1 )
)

The issue is that when I run this as a script, the Lag function does not work. If I manually enter the formula above it works fine, but the below script only populates rows where :Range == 1, despite the fact I can see the formula is correctly applied to the column.

 

 

New Column( "Mean Measurement", Formula(
If( :Range == 1,
Col Mean( :Measurement, :ID, :Range ),
Lag( :Measurement, -1 ))))

Is there any reason for this, and any way I can force the column to re-evaluate the formula to run properly?

Note, the rerun formulas function does not seem to do anything

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Lag formula not working when scripted

The Lag() function operates on specified rows, it is not a "vectorized" function.  In a column function, the row is implicit (the row of the table), so it works in the column formula without issue.  

 

For your script, if you specify the row using the Row()==<row number> command prior to the lag function statement, then the Lag  should return a value.  

 

Row() = 3;
If( :Range == 1,
	Col Mean( :Measurement, :ID, :Range ),
	Lag( :Measurement, -1 )
)

Also, just to make sure you are aware, the lag number argument for the Lag(:column, <lag number>), if it is a negative number, this actually is "forward lag".  In the example you show above, it would look for the value in the next row, not the previous row.  

View solution in original post

2 REPLIES 2

Re: Lag formula not working when scripted

The Lag() function operates on specified rows, it is not a "vectorized" function.  In a column function, the row is implicit (the row of the table), so it works in the column formula without issue.  

 

For your script, if you specify the row using the Row()==<row number> command prior to the lag function statement, then the Lag  should return a value.  

 

Row() = 3;
If( :Range == 1,
	Col Mean( :Measurement, :ID, :Range ),
	Lag( :Measurement, -1 )
)

Also, just to make sure you are aware, the lag number argument for the Lag(:column, <lag number>), if it is a negative number, this actually is "forward lag".  In the example you show above, it would look for the value in the next row, not the previous row.  

Re: Lag formula not working when scripted

Why do you take 10 measurements at 1-minute intervals? Why do you use a mean of a few observations in the middle of the time course?

 

You might get more information if you analyze the entire curve as a response value. See the Functional Data Explorer for more ideas. You can analyze a 'functional DOE' with JMP Pro.