cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
rk3
rk3
Level I

Fit some models: how can i run and save all fits to the datatable?

in JMP 17: I have completed a dsd with many outputs (over 100 outputs).  I can use fit definitive screening to open an interface and enter all the inputs, all the outputs and it proceeds to fit a model for each output.  What i want to do now is "Run Model" (for each model) and then "Save script to datatable" (for each fit model).  How would i write a script to do this?  chatgpt suggests the following, but i keep getting errors that it can't resolve

 

// Assume the Fit DSD platform is open and assigned to a variable
// Replace "FitDSDObj" with the actual variable holding your platform reference
FitDSDObj = Current Report();

// Loop through each response modeling section
ForEach(
	FitDSDObj << Report As List,
	ResponseSection,

	// Check if this section has a "Run Model" button
	If(
		ResponseSection << Contains("Run Model"),
		
		// Click "Run Model" button
		(ResponseSection << Button Box("Run Model")) << Click,

		// Wait briefly to allow model to fit
		Wait(0.5);

		// Click "Save Columns to Data Table" (could also be labeled "Save Prediction Formula" or similar)
		If(
			ResponseSection << Contains("Save Columns"),
			(ResponseSection << Button Box("Save Columns")) << Click,
			
			// Fallback if specific button names are known
			If(
				ResponseSection << Contains("Save Prediction Formula"),
				(ResponseSection << Button Box("Save Prediction Formula")) << Click
			)
		)
	)
);
3 REPLIES 3
Victor_G
Super User

Re: Fit some models: how can i run and save all fits to the datatable?

Hi @rk3,

 

Welcome in the Community !

 

I would recommend not using ChatGPT or other AI-assisted tools for JSL coding, as JSL is not a standard language that these assistants have encountered. Therefore, the syntax is very often (if not always) wrong/false by default. 
You could perhaps run the analysis by "point and click" using the JMP platforms (and using CTRL + click to "Run model" for all the responses you have entered in the Fit DSD platform) and use the JSL script recorded by the JMP Log to create the script you need ? 

Using the "Extraction Data" dataset from JMP, creating 2 responses so that several responses could be taken into consideration, here are the JSL parts created by the log recorder when fitting several models using Fit DSD, then running models, and finally saving prediction formula in datatable :

 

// Open Data Table: Extraction Data.jmp
Open( "$SAMPLE_DATA/Design Experiment/Extraction Data.jmp" );

// Creation of 2 new responses Y2 and Y3

// Launch platform: Fit Definitive Screening for 3 responses Yield, Y2 and Y3
New Window( "Extraction Data - Fit Definitive Screening",
	Outline Box( "Fit Definitive Screening",
		<<SetHorizontal( 1 ),
		Data Table( "Extraction Data" ) <<
		Fit Definitive Screening(
			Y( :Yield ),
			X( :Methanol, :Ethanol, :Propanol, :Butanol, :pH, :Time ),
			Quadratic Terms Obey Strong Heredity( 1 ),
			Interactions Obey Strong Heredity( 1 )
		),
		Data Table( "Extraction Data" ) <<
		Fit Definitive Screening(
			Y( :Y2 ),
			X( :Methanol, :Ethanol, :Propanol, :Butanol, :pH, :Time ),
			Quadratic Terms Obey Strong Heredity( 1 ),
			Interactions Obey Strong Heredity( 1 )
		),
		Data Table( "Extraction Data" ) <<
		Fit Definitive Screening(
			Y( :Y3 ),
			X( :Methanol, :Ethanol, :Propanol, :Butanol, :pH, :Time ),
			Quadratic Terms Obey Strong Heredity( 1 ),
			Interactions Obey Strong Heredity( 1 )
		),
		<<Set Base Font( "Title" ),
		<<SetHorizontal( 1 )
	)
);
// Save Columns: Prediction Formula Yield
Local( {obj},
	obj = Data Table( "Extraction Data" ) <<
	Fit Model(
		Y( :Yield ),
		Effects(
			:Methanol, :Time, :Methanol * :Time, :Methanol * :Methanol,
			:Time * :Time
		),
		Personality( "Standard Least Squares" ),
		Emphasis( "Effect Screening" ),
		Run(
			:Yield << {Summary of Fit( 0 ), Analysis of Variance( 0 ),
			Parameter Estimates( 1 ), Effect Details( 0 ), Sorted Estimates( 0 ),
			Plot Actual by Predicted( 1 ), Plot Regression( 0 ),
			Plot Residual by Predicted( 1 ), Plot Studentized Residuals( 1 ),
			Plot Effect Leverage( 0 ), Plot Residual by Normal Quantiles( 0 ),
			Box Cox Y Transformation( 0 ), Profiler(
				1,
				Confidence Intervals( 1 ),
				Desirability Functions( 1 ),
				Term Value(
					:Methanol( 5, Lock( 0 ), Show( 1 ) ),
					:Time( 1.5, Lock( 0 ), Show( 1 ) )
				)
			)}
		)
	);
	obj << Prediction Formula;
	obj << Close Window;
);

// Save Columns: Prediction Formula Y2
Local( {obj},
	obj = Data Table( "Extraction Data" ) <<
	Fit Model(
		Y( :Y2 ),
		Effects( :Methanol, :Ethanol, :pH ),
		Personality( "Standard Least Squares" ),
		Emphasis( "Effect Screening" ),
		Run(
			:Y2 << {Summary of Fit( 0 ), Analysis of Variance( 0 ),
			Parameter Estimates( 1 ), Effect Details( 0 ), Lack of Fit( 0 ),
			Sorted Estimates( 0 ), Plot Actual by Predicted( 1 ),
			Plot Regression( 0 ), Plot Residual by Predicted( 1 ),
			Plot Studentized Residuals( 1 ), Plot Effect Leverage( 0 ),
			Plot Residual by Normal Quantiles( 0 ), Box Cox Y Transformation( 0 ),
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value(
					:Methanol( 5, Lock( 0 ), Show( 1 ) ),
					:Ethanol( 5, Lock( 0 ), Show( 1 ) ),
					:pH( 7.5, Lock( 0 ), Show( 1 ) )
				)
			)}
		)
	);
	obj << Prediction Formula;
	obj << Close Window;
);


// Save Columns: Prediction Formula
Local( {obj},
	obj = Data Table( "Extraction Data" ) <<
	Fit Model(
		Y( :Y3 ),
		Effects(
			:Methanol, :Ethanol, :Propanol, :Methanol * :Ethanol,
			:Methanol * :Propanol, :Ethanol * :Propanol, :Propanol * :Propanol
		),
		Personality( "Standard Least Squares" ),
		Emphasis( "Effect Screening" ),
		Run(
			:Y3 << {Summary of Fit( 0 ), Analysis of Variance( 0 ),
			Parameter Estimates( 1 ), Effect Details( 0 ), Lack of Fit( 0 ),
			Sorted Estimates( 0 ), Plot Actual by Predicted( 0 ),
			Plot Regression( 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 ),
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value(
					:Methanol( 5, Lock( 0 ), Show( 1 ) ),
					:Ethanol( 5, Lock( 0 ), Show( 1 ) ),
					:Propanol( 5, Lock( 0 ), Show( 1 ) )
				)
			)}
		)
	);
	obj << Prediction Formula;
	obj << Close Window;
);

This script won't be directly usable for your task, but it may help you understand the JSL structure. You can also look at JMP Scripting Index to better understand the language format used by JSL.
I'm sure other experienced JSL members of the Community will be able to provide a working script for your task.

 

Best,

Victor GUILLER

"It is not unusual for a well-designed experiment to analyze itself" (Box, Hunter and Hunter)
rk3
rk3
Level I

Re: Fit some models: how can i run and save all fits to the datatable?

Thank you!  I'll try this.

 

Edit: on 2nd thought, this unfortunately looks just as tedious as I will have to manually go through and adjust all the term values.  

 

I really need this to be rolled into some kind of for-loop.

statman
Super User

Re: Fit some models: how can i run and save all fits to the datatable?

My suggestion is to first evaluate the correlation between the numerous response variables.  For the ones that correlate you will likely get similar models.  

 

Really model building can't be done with just statistics.  The statistics need to be interpreted in the context they were acquired. You need SME to evaluate the reasonableness of the model from a practical standpoint.  I don't know how you "automate" this?  The model needs to be practical, useful and as simple as possible following William of Occam's advice.

"All models are wrong, some are useful" G.E.P. Box

Recommended Articles