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
lukasz
Level IV

How to calculate the median for a group of data

Hello everybody,
I have test groups A and B, 4 different items, Param2 (being the maximum of Param1 values) saved in the first cell of corresponding item. The values of Param2 are sometimes provided per hand. Now I would like to calculate the median of Param2 for each test group and save it again
in the first cell where each test group starts, like in the table below. I would appreciate for hints how I can do that in script.
Thank you and best regards.

jmp_median.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to calculate the median for a group of data

Use Col Median to calculate median over groups. Then combine that with if-statement which checks for first row of the group using Col Min

Example:

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("Group", Character, "Nominal", Set Values({"A", "A", "A", "A", "B", "B", "B", "B"})),
	New Column("Param", Numeric, "Continuous", Format("Best", 12), Set Values([5, ., ., 6, 3, ., 2, .])),
	New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., ., ., ., ., .]))
);


dt << New Column("Med", Numeric, Continuous, Formula(
	If(Row() == Col Min(Row(), :Group),
		Col Median(:Param, :Group)
	,
		.
	)
));

jthi_0-1665327438208.png

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How to calculate the median for a group of data

Use Col Median to calculate median over groups. Then combine that with if-statement which checks for first row of the group using Col Min

Example:

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("Group", Character, "Nominal", Set Values({"A", "A", "A", "A", "B", "B", "B", "B"})),
	New Column("Param", Numeric, "Continuous", Format("Best", 12), Set Values([5, ., ., 6, 3, ., 2, .])),
	New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., ., ., ., ., .]))
);


dt << New Column("Med", Numeric, Continuous, Formula(
	If(Row() == Col Min(Row(), :Group),
		Col Median(:Param, :Group)
	,
		.
	)
));

jthi_0-1665327438208.png

 

-Jarmo
lukasz
Level IV

Re: How to calculate the median for a group of data

Hi,

thank you for suggestion. It is working, however I noticed that I have in data some other even high-level groups for which median within lower-level groups need to be calculated. I slightly adapted the if statement:

Best regards

dt << New Column("Med", Numeric, Continuous, Formula(
	If(Row() == Col Min(Row(), :High_level_Group, :Low_level_Group),
		Col Median(:Param, :High_level_Group, :Low_level_Group)
	,
		.
	)
));