cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lazzybug
Level III

How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

Hi JSL experts,

 

I have a DoE OLS or REML model with prediction profiler like below. How I can find all the X variable ranges to meet LSL and USL automatically with JSL by fixing other variables? For example, X1 must be below 34.6 to meet spec.  Thank you so much for your help.

 

 

lazzybug_1-1681847039483.png

 

 

 

14 REPLIES 14
lazzybug
Level III

Re: How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

@Mark_Bailey Below is one of my examples. I need a generic code which needs to read the scripts from Fit group model, and then get the Term Value into a factors list. Once I have the list, I will compare with column name in the data table to determine they are number or character so that I can make my simulation code.  The last part is my code, but it's too complicated and it won't work if there are multiple Term Value in the profiler. So it's better to leave only Profiler on.  I wonder if you have easier way to finish the same task? Thank you so much for your help.

 

factors = {"ELONG", "HARDNESS(+/-0.2)", "ABRASION For example (%)", "MODULUS"}

This is the script from an example model:

Fit Group(
	Fit Model(
		Y( :"SILICA (%)"n ),
		Effects( :ELONG, :"HARDNESS(+/-0.2)"n ),
		Personality( "Standard Least Squares" ),
		Emphasis( "Minimal Report" ),
		Run(
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value(
					ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
					"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
				)
			),
			:"SILICA (%)"n << {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 )}
		)
	),
	Fit Model(
		Y( :SILANE Value ),
		Effects(
			:"ABRASION For example (%)"n, :MODULUS, :ELONG, :"HARDNESS(+/-0.2)"n,
			:MODULUS * :ELONG
		),
		Personality( "Standard Least Squares" ),
		Emphasis( "Minimal Report" ),
		Run(
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value(
					"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
					MODULUS( 1255, Lock( 0 ), Show( 1 ) ),
					ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
					"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
				)
			),
			:SILANE Value << {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 )}
		)
	),
	Fit Model(
		Y( :SULFUR ),
		Effects( :ELONG ),
		Personality( "Standard Least Squares" ),
		Emphasis( "Minimal Report" ),
		Run(
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value( ELONG( 417.5, Lock( 0 ), Show( 1 ) ) )
			),
			:SULFUR << {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 )}
		)
	),
	<<{Profiler(
		1,
		Confidence Intervals( 1 ),
		Term Value(
			ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
			"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) ),
			"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
			MODULUS( 1255, Lock( 0 ), Show( 1 ) )
		)
	)}
);

This is my code to make factors list:

 

Names Default To Here( 1 );
dt = Current Data Table();
curep = Current Report();
dtname = dt << Get Name;
//Check how many prediction profiles, if >1 it's fit group, =1 it's fit model
pred_objs = curep << XPath( "//OutlineBox[ contains( text(), 'Prediction Profile' ) ]" );
num_objs = N Items( pred_objs );
If( num_objs < 1,
	Throw( "No prediction profile is found!" )
);
If( num_objs == 1,
	textind = "Profiler(",
	textind = "{Profiler("
);

//Read the Model Term list
modelobj = curep[Outline Box( 1 )] << get scriptable object;
modeltext = Char( modelobj << get script );
//Show( modeltext );
posA = Contains( modeltext, textind );
termstext = Right( modeltext, Length( modeltext ) - posA + 1 );
/*Show( termstext );*/
posB = Contains( termstext, "Term Value" );
posC = Contains( termstext, "Show(1))", -1 );
termvalue = Left( termstext, posC + 7 ) || ","; //Make sure all terms end with )),
termvalue = Right( termvalue, Length( termvalue ) - posB - 10 );
/*Show( termvalue );
Show( posB );
Show( posC );
Show( posD );*/

//Check how many factors or main effects in the final model
words = Words( termvalue, "," );
termnum = 0;
For( i = 1, i <= N Items( words ), i++,
	If( Contains( words[i], "Show" ),
		termnum = termnum + 1
	)
);

//Get the term with default value
term list = {};
For( k = 1, k <= termnum, k++, 
	//show(firstpos);
	pos1 = Contains( termvalue, "))," ) + 3;
	term1 = Left( termvalue, pos1 );
	//show(term1);
	termvalue = Right( termvalue, Length( termvalue ) - pos1 );
	//show(termvalue);
	Insert Into( term list, term1 );
);
Show( term list );

//get term name without default value
factors = {};
For( k = 1, k <= N Items( term list ), k++,
	termK = term list[k];
	firstchar = Left( termK, 1 );
	If( firstchar == "\!"",
		pos2 = Contains( termK, "\!"", -1 );
		term2 = Left( termK, pos2 + 1 );
	,
		pos2 = Contains( termK, "(" ); //Categorical terms cannot have "()" in the column name
		term2 = Left( termK, pos2 - 1 );
	);
	Insert Into( factors, char(parse(term2)) );
);
Show( factors );

 

Re: How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

I think that there is a more elegant and robust approach. See the end of this example for the approach of which I am thinking.

 

Names Default to Here( 1 );

// JMP Pro 16.2

// start with example of a model script
model = Expr(
	Fit Group(
		Fit Model(
			Y( :"SILICA (%)"n ),
			Effects( :ELONG, :"HARDNESS(+/-0.2)"n ),
			Personality( "Standard Least Squares" ),
			Emphasis( "Minimal Report" ),
			Run(
				Profiler(
					1,
					Confidence Intervals( 1 ),
					Term Value(
						ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
						"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
					)
				),
				:"SILICA (%)"n << {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 )}
			)
		),
		Fit Model(
			Y( :SILANE Value ),
			Effects(
				:"ABRASION For example (%)"n, :MODULUS, :ELONG, :"HARDNESS(+/-0.2)"n,
				:MODULUS * :ELONG
			),
			Personality( "Standard Least Squares" ),
			Emphasis( "Minimal Report" ),
			Run(
				Profiler(
					1,
					Confidence Intervals( 1 ),
					Term Value(
						"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
						MODULUS( 1255, Lock( 0 ), Show( 1 ) ),
						ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
						"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) )
					)
				),
				:SILANE Value << {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 )}
			)
		),
		Fit Model(
			Y( :SULFUR ),
			Effects( :ELONG ),
			Personality( "Standard Least Squares" ),
			Emphasis( "Minimal Report" ),
			Run(
				Profiler(
					1,
					Confidence Intervals( 1 ),
					Term Value( ELONG( 417.5, Lock( 0 ), Show( 1 ) ) )
				),
				:SULFUR << {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 )}
			)
		),
		<<{Profiler(
			1,
			Confidence Intervals( 1 ),
			Term Value(
				ELONG( 417.5, Lock( 0 ), Show( 1 ) ),
				"HARDNESS(+/-0.2)"n( 69.775, Lock( 0 ), Show( 1 ) ),
				"ABRASION For example (%)"n( 133.1, Lock( 0 ), Show( 1 ) ),
				MODULUS( 1255, Lock( 0 ), Show( 1 ) )
			)
		)}
	);
);

// last argument is in-line message send for Profiler
last = N Arg( model );
profilerExpr = Arg( model, last );

// unwrap Send() and its list argument
profilerExpr = Arg( profilerExpr, 1 )[1];

// find term values
termVals = Associative Array();
termExpr = Arg( profilerExpr, 3 );
nArgs = N Arg( termExpr );
For( i = 1, i <= nArgs, i++,
	Insert Into( termVals,
		Char( Head( Arg( termExpr, i ) ) ),
		Arg( Arg( termExpr, i ), 1 )
	)
);

// use resulting dictionary for term values
Show( termVals );
lazzybug
Level III

Re: How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

@Mark_Bailey Your solution is great and much easier than mine. Thank you so much for your help. 

 

But I got another problem with this method. Can you help me out?

 

factors = {"Kilometer (kg)"n, "Temperature (ºC)"n};
responses_sim = "";
values = {1.23,2.34};
for (i=1, i<=N Items(factors), i++,
	responses_sim = responses_sim || factors[i] || "<< Add Random Noise(" || char(values[i]) || "),"
);

show(responses_sim);

responses_sim = "Kilometer (kg)<< Add Random Noise(1.23),Temperature (ºC)<< Add Random Noise(2.34),";

I want to get this result below, how to do it? responses_sim = "Kilometer (kg)"n << Add Random Noise(1.23), "Temperature (ºC)"n << Add Random Noise(2.34),"

 

 

Re: How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

What you show at the end as your desired value of the variable str is not a string.

 

How will you use str in your script? Will it be an argument to a function?

lazzybug
Level III

Re: How to use JSL to find X variable range to meet spec limit by fixing other variables in Prediction Profiler?

@Mark_Bailey str is just a variable name, during my code below I actually used random_sim and responses_sim, by chaning this two variables in my for loop, I can simulate all factors once a time. The code I used before to extract Y and Term Value have "\! in the string, but your way to extract argument doesn't have "\!, which is the only difference.

 

			simu model script = Parse(
				Eval Insert(
					"\[
				simobj << Simulator(
				1,
				Factors( ^random_sim^),
				Responses( ^responses_sim^ ),
				Resimulate
				);
				]\"
				)
			);
			Show( simu model script );
			Eval( simu model script );