cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lazzybug
Level III

Need Help to automate stepwise model selection!

Hi JMP experts,

 

I need your help to revise my code to automate stepwise model selection with p value threshold. This attached JSL can run stepwise automatically based on assigned effects and response. I need to add more functions to make my work more efficient.

1. I want to this script can generate interaction and quadratic automatically based on predictors (it's better to have it, but not necessary)

2. The script needs to generate model for each response in the response_col list.

3. After Run model, I want this response report has the following plots or tables:

 

{Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Effect Tests( 0 ), Effect Details( 0 ),
Lack of Fit( 0 ), Scaled Estimates( 0 ), Plot Actual by Predicted( 1 ),
Plot Regression( 0 ), Plot Residual by Predicted( 0 ),
Plot Studentized Residuals( 1 ), Plot Effect Leverage( 0 ),
Plot Residual by Normal Quantiles( 1 ), Box Cox Y Transformation( 0 ),
Press( 1 )}

4. I want to save this report into JMP table with an assigned name such as stepwise_response.

5. Save all those plots and table into separate graphs under an assigned folder, so that I don't need to copy the model results one by one into PowerPoint or word document.

 

4 REPLIES 4

Re: Need Help to automate stepwise model selection!

The following page is useful to understand how to handle expressions.

https://community.jmp.com/t5/JSL-Cookbook-Archived/Insert-one-expression-into-another-using-Eval-Ins... 

For stepwize regression, here is an example;

For( i = 1, i <= N Items( response_col ), i++,
	Eval(
		Parse(
			Eval Insert(
				"\[step_wise = Fit Model(
	                               Y( ^response_col[i]^  ),
	                                          Effects( ^effects_term^ ),
	                                          Personality( Stepwise ),
	                                          Run Model(
			                                           Stopping Rule( "P-value Threshold" ),
			                                           Prob to Enter( 0.05 ),
			                                           Prob to Leave( 0.25 ),
	                                           ),
	                                           Run
                                         );
                            ]\"
			)
		)
	);
	step_wise << Finish;
	Wait( 0 );
	fit_model = step_wise << Run model;
	step_wise << close window();

);//end of loop

Please see attached file for full script.

(I found a mistake and edited the script. 19 Apr 2023)

lazzybug
Level III

Re: Need Help to automate stepwise model selection!

Hi @yuichi_katsumur   Thank you so much for your previous help about JSL stepwise. It worked well, the stepwise only has one P-value threshold, but this example below has two Stepwise method, one is P-value threshold, the other one is Minimum BIC. When I used your code to save the model it has two models, I have to use code to delete last script every time after saving models. Is there any way to remove minimum BIC in the graph below? 

 

The direction for stepwise I used is "Mixed", but the graph below only shows "Forward", so what's actual direction used in the script?

 

@jthi can you help take a look as well?

 

lazzybug_0-1681845373661.png

 

 

sdt = Open("$SAMPLE_DATA/Boston Housing.jmp");
response_col = {" :mvalue", ":crim"};
effects_term = {:zn, :indus, :chas, :nox, :rooms, :age, :distance, :radial, :tax, :pt, :b,
:lstat};
var1= 0.05;
var2 = 0.25;

For( i = 1, i <= N Items( response_col ), i++,
Eval(
Parse(
Eval Insert(
"\[step_wise = Fit Model(
Y( ^response_col[i]^ ),
Effects( ^effects_term^ ),
Personality( Stepwise ),
Run Model(
Stopping Rule( "P-value Threshold" ),
Prob to Enter( ^var1^ ),
Prob to Leave( ^var2^ );
Direction ("Mixed");
Rules("Combine");
),
Run
);
]\"
)
)
);
step_wise << Finish;
Wait( 0 );
fit_model = step_wise << Run model;
/* step_wise << close window();*/
);

lazzybug
Level III

Re: Need Help to automate stepwise model selection!

I just noticed that the direction is forward only. How can we change it to "mixed" in the code above?

Re: Need Help to automate stepwise model selection!

Hi @lazzybug,

I'm sorry, I found an error in my script. Please replace ; with ,.

// Previous script
Prob to Leave( ^var2^ );
Direction ("Mixed");
Rules("Combine");

// Correct one
Prob to Leave( ^var2^ ),
Direction ("Mixed"),
Rules("Combine"),