How to Iterate through variables in a regression in SAS/JMPHi Folks,
Am very new and recently trained in SAS Programming. I'm trying to take a set of independent variables and test if they are (statistically significantly) differently-correlated to two groups of data.
I've been advised that the way to do this in JMP is to make a series of linear regressions like the following,
result = group + varA + group*varA
and then examine the significance of the interaction effect, e.g., the "Prob > F" column in this "Country*Displacement" example:
(I don't have the reputation to post an image.)
Now, I need to be able to switch out one of these variables; that is, for a list of ~350 variables, say varA, varB, etc., I need to run the following regressions,
result = group + varA + group*varA
result = group + varB + group*varB
result = group + varC + group*varC
...
and get the significance of that interaction effect. Previous attempts to scripting have resulted in ~350 results windows, or ~350 model dialogs . . . any advice would be appreciated.
Edit:
For example, using the Airline Delays JMP sample data set, this is the result from one of the steps:

I need to extract the significance of the interaction effect (the 0.1397 under Effect Tests) for each of a set of variables; for example, interchanging the "Distance" variable with "Elapsed Time". But I need to interchange this variable for each in a set of ~350.
Re: How to Iterate through variables in a regression in SAS/JMPThank you @txnelson.
Re: How to Iterate through variables in a regression in SAS/JMPHere is a little different example of what @gzmorgan0 provided. this example loops across multiple runs
names default to here(1);
dt=open("$SAMPLE_DATA/Diamonds Data.jmp");
charColNamesList = dt << get column names(string,character);
effectNameList = {};
effectProbList = {};
For(i=2,i<=nitems(charColNamesList),i++,
Eval(Substitute(Expr(
fm = Fit Model(invisible,
Y( :Price ),
Effects( __VarA__, __VarB__, __VarA__ * __VarB__ ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Screening" ),
Run(
)
);),
Expr(__VarA__),parse(":" || charColNamesList[1]),
Expr(__VarB__),parse(":" || charColNamesList[i]))
);
insert into(effectProbList, (report(fm)["Effect Tests"][numbercolbox(6)]<<GET></GET>Re: How to Iterate through variables in a regression in SAS/JMPThank you @gzmorgan0, this code definetly helps me.
Re: How to Iterate through variables in a regression in SAS/JMPLook up
Main Menu > Help > Scripting Index >select Objects > scroll to Fit Model > Least Squares > scroll in message to Get Effect pvalues.
You would need to iterate over your 350 variables (likely using a for loop) where inside the loop you would have a script like the one below.
I do not recommend relying on pvalues without residual analyses, looking for outliers or violation of assumptions. I am not sure why your described task was recommended; JMP has many tools to look for most influential variables. That said, the script is a starting point.
Names default to Here(1);
Open("$sample_data/Airline Delays.jmp");
fm = Data Table("Airline Delays") << Fit Model( Invisible,
Y( :Arrival Delay ),
Effects( :Day of Week, :Distance, :Day of Week * :Distance ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
:Arrival Delay << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Lack of Fit( 0 ), Scaled Estimates( 0 ),
Plot Actual by Predicted( 0 ), Plot Residual by Predicted( 0 ),
Plot Studentized Residuals( 0 ), Plot Effect Leverage( 0 ),
Plot Residual by Normal Quantiles( 0 ), Box Cox Y Transformation( 0 )}
)
);
pv = fm << get effect pvalues;
show(pv); //look at the log or hover over pv the 3rd value pv[3] is the interaction pvalue<BR />fm << Close Window(); //to clean up the windows<BR />