cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

How to find the mean between rows by a group with missing data in a forward-looking format?

I'm running into this issue where I have two sets of datapoints across my timeline. One is collected at every point in the interval "Temperature (Celsius)", the other is collected sporadically "Residual Glucose (g/L)". When placed together in a data table, one of the columns is missing data in the interval. I attached a data table as an example but essentially looks like this:

PruningTheBird9_0-1782827462592.png

What I need is to get the mean of the "Temperature (Celsius)" column between rows that contain data in the "Residual Glucose (g/L)" column. The caveat is that this has to be forward-looking . E.g. at row 1, the result should just be "32".  At row 7, the result should be the mean of everything in [Row 2, Row 7] = "32.1". The results should show in the cells highlighted green.

I have been doing this by creating a helper column, using sort, and then tabulating but this is very time consuming. I am hoping to get help automating this as I keep adding data to my table. I would appreciate any help and/or guidance!

2 REPLIES 2
jthi
Super User

Re: How to find the mean between rows by a group with missing data in a forward-looking format?

If you already have done it manually, you could quite easily create workflow to automate it.

Here is formula which might do what you are looking for (I suggest breaking it into parts to make it easier to understand)


If(!IsMissing(:"Residual Glucose (g/L)"n),
	Col Mean(
		:"Temperature (Celsius)"n,
		Col Cumulative Sum(
			!Is Missing(Lag(:"Residual Glucose (g/L)"n)) & Is Missing(:"Residual Glucose (g/L)"n),
			:Batch ID
		),
		:Batch ID
	)
,
	.
);
-Jarmo
txnelson
Super User

Re: How to find the mean between rows by a group with missing data in a forward-looking format?

You can create a new column that adds a grouping column that has different group values for each of the non Residual Gluecose value rows.

txnelson_0-1782834531970.png

Here is the formula for the calculation of the group variable

As Constant( x = 0 );
If( Is Missing( :"Residual Glucose (g/L)"n ) == 0,
	x
	++);
If( Is Missing( :"Residual Glucose (g/L)"n ) == 1,
	x
);

Then using Col Mean you can get the means you want

txnelson_1-1782834967329.png

Here is the formula for the group mean calculation

If( Is Missing( :group ) == 0,
	Col Mean( :"Temperature (Celsius)"n, :group )
)
Jim

Recommended Articles