How do I script a for loop to run oneway ANOVA over all Y columns in a data tableI 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 )}
);ScriptingRe: How do I script a for loop to run oneway ANOVA over all Y columns in a data tableHere 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]^ ) )" ) ) )
);
Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data tableThanks 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 )}
);Re: How do I script a for loop to run oneway ANOVA over all Y columns in a data tableyou 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]^ ) )" ) ) )
);