cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
Ake
Ake
Level III

Adjustable Lag Difference?

Don't know how to title this but here goes. I have data sets with several time points per batch. For each batch I want to calculate the difference in results from time point zero. I used to compare each result to column min or max (as suitable) which worked fine, but when results are a bit jumpy, the max or min may happen at another time point than zero.

 

I want the (desired) diff as below. Is there a simple way to do this in a formula? 

 

Ake_0-1683127236504.png

jmp 17.1

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Adjustable Lag Difference?

If the results are ordered, you could use something like this:

:Result - :Result[Col Min(Row(), :Batch)]

Col Min(Row(), :Batch) will get the first row for specific batch and then we can access that row by using :Result[rownr].

jthi_0-1683129377019.png

If the data isn't always ordered it isn't really a problem, but it will require different formula

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Adjustable Lag Difference?

If the results are ordered, you could use something like this:

:Result - :Result[Col Min(Row(), :Batch)]

Col Min(Row(), :Batch) will get the first row for specific batch and then we can access that row by using :Result[rownr].

jthi_0-1683129377019.png

If the data isn't always ordered it isn't really a problem, but it will require different formula

-Jarmo
Ake
Ake
Level III

Re: Adjustable Lag Difference?

Thanks for extremely fast, and useful, response! I will ponder how, but I see it works!

jthi
Super User

Re: Adjustable Lag Difference?

Easiest way (in my opinion) to see how it works is to divide that formula into three different formulas

First one (BatchMinRow)

Col Min(Row(), :Batch)

Second using the just created BatchMinRow (BatchMinVal)

:Result[:BatchMinRow]

and finally third one

:Result - :BatchMinVal

this makes it much easier to see what the different parts in the formula do

-Jarmo
jthi
Super User

Re: Adjustable Lag Difference?

Just adding few possible options if the data isn't always sorted.

Using matrix calculations to get the indices

 

As Constant(
	times = :Time << get as matrix;
	batches = :Batch << get as matrix;
);

batch_rows = Loc(batches, :Batch);
batch_first_time_row = batch_rows[Loc Min(times[batch_rows])];
:Result - :Result[batch_first_time_row];

and using Col Sum to get the minimum value with comparison and product (if :Time isn't the smallest multiplier is 0).

:Result - Col Sum((:Time == Col Min(:Time, :Batch)) * :Result, :Batch);

 

 

 

-Jarmo