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
Mitch
Level I

How do I script a for loop to run oneway ANOVA over all Y columns in a data table

I have a large data table with 10,000 different column names and a small number of rows containing replicates from 5 different sample groups, including a control group labeled "HN30".  I have a script that will run a one way ANOVA and Dunnett post-hoc mean comparisons test (i.e. Means comparison) to the control group (HN30) if I specify each Y variable one at a time. However, I don't want to type in all 10,000 different column names or be prompted to run a Dunnett test or enter the control name for every column analysis.   Can someone help me write a for loop that will iterate the commands through all columns one a at a time. Once I get the output, I know how to use the combine tables command to merge all the output P-values.  Below is what I have that works for two specified columns named "SPP1", and "ABCC2" where control group rows are labeled "HN30".  Just need to iterate across all columns. Thanks so much !

Fit Group(
	Oneway(
		Y( :SPP1 ),
		X( :Cell lline ),
		With Control( 1, {"HN30"} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons",
				"Comparisons with a control using Dunnett's Method",
				"LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)
	),
	Oneway(
		Y( :ABCC2 ),
		X( :Cell lline ),
		With Control( 1, {"HN30"} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons",
				"Comparisons with a control using Dunnett's Method",
				"LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)
	),
	<<{Arrange in Rows( 1 )}
);
4 REPLIES 4
Georg
Level VII

Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data table

Here is one example for a loop. Probably you can adapt to your needs.

You can find examples for the used commands in scripting index or in scripting reference, if needed.

 

Names Default To Here( 1 );

cdt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );

all_ys = cdt << get column names( Continuous, String );

For( i = 1, i <= n items(all_ys), i++,
	Eval( Parse( Eval Insert( "oneway( X( :SITE ), Y( :^all_ys[i]^ ) )" ) ) )
);
Georg
Mitch
Level I

Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data table

Thanks Georg,

I adapted your example to my specific table and now get all the One Way ANOVAs running for each column, so that part works.  However, I still cannot figure out  how to work in the Dunnett test to follow each ANOVA.  Not sure how to structure that subcommand with the for loop.  Here is what I have so far, but I cannot the specific Dunnett tests that I show at the bottom to run in the for loop.  Any ideas?  Thanks again

Names Default To Here( 1 );
cdt = Open( "F:/Stats/DTest.jmp" );

all_ys = cdt << get column names( Continuous, String );

For( i = 1, i <= n items(all_ys), i++,
	Eval( Parse( Eval Insert( "oneway( X( :Cell lLine ), Y( :^all_ys[i]^ ) )" ) ) )
);

	

Fit Group(
	Oneway(
		Y( :SPP1 ),
		X( :Cell lline ),
		With Control( 1, {"HN30"} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons",
				"Comparisons with a control using Dunnett's Method",
				"LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)
	),
	Oneway(
		Y( :ABCC2 ),
		X( :Cell lline ),
		With Control( 1, {"HN30"} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons",
				"Comparisons with a control using Dunnett's Method",
				"LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)
	),
	<<{Arrange in Rows( 1 )}
);
Georg
Level VII

Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data table

you can try this:

 

Names Default To Here( 1 );

cdt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );

ow_expr = Expr(
	Oneway(
		Y( Column( all_ys[i] ) ),
		X( :SITE ),
		/* 3rd site is control */
		With Control( 1, {3} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons", "Comparisons with a control using Dunnett's Method", "LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)

	)
);

all_ys = cdt << get column names( Continuous, String );

//For( i = 1, i <= n items(all_ys), i++,
For( i = 1, i <= 3, i++,
	Eval( Substitute( ow_expr, Expr( i ), i ) );
//	Eval( Substitute( Expr( oneway( X( :SITE ), Y( Column( all_ys[i] ) ) ) ), Expr( i ), i ) )
//	Eval( Parse( Eval Insert( "oneway( X( :SITE ), Y( :^all_ys[i]^ ) )" ) ) )	
);
Georg
Mitch
Level I

Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data table

Thanks so much for all your time.  Your solution works and is almost perfect.  I appreciate all the time you spent helping.  Just wondering if there is a command or syntax change that would force all the outputs from the loop to stay in just one window.  Right now, every loop makes its own window so I will have thousands of windows popping open.  Also, I cannot use the combine data table command to collate similar analyses because each result is in a separate windows.  Below is my code using your last suggestion. Obviously, I have no clue myself how to code.  Any ideas to get them all to output to the same window?

 

Names Default To Here( 1 );
cdt = Open( "F:/Stats/DTest.jmp" );

ow_expr = Expr(
	Oneway(
		Y( Column( all_ys[i] ) ),
		X( :Cell lline ),
		/* 3rd site is control */
		With Control( 1, {"HN30"} ),
		Comparison Circles( 1 ),
		SendToReport(
			Dispatch(
				{"Means Comparisons", "Comparisons with a control using Dunnett's Method", "LSD Threshold Matrix"},
				"p-Value",
				NumberColBox,
				{Set Format( "Fixed Dec", 15, 15 )}
			)
		)

	)
);

all_ys = cdt << get column names( Continuous, String );

//For( i = 1, i <= n items(all_ys), i++,
For( i = 1, i <= n items(all_ys), i++,
	Eval( Substitute( ow_expr, Expr( i ), i ) );
//	Eval( Substitute( Expr( oneway( X( :Cell lline ), Y( Column( all_ys[i] ) ) ) ), Expr( i ), i ) )
//	Eval( Parse( Eval Insert( "oneway( X( :Cell lline ), Y( :^all_ys[i]^ ) )" ) ) )	
);