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

How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Hi All,

 

I would like to make a script for reliability estimation. One of my tasks is to evaluate the estimated quantile/probability.

 

In these expressions (please see the code below), if I list all the categories explicitly using list, such as {0, 1, 2, 3}, the expression works fine. However, if I use the variable for the list, then use the variable instead of explicitly writing the list in the code, the expression does not work.

 

Here is an example.

 

The following code works fine:

Lognormal Estimate Probability( Profile, {1000}, {0 ,1, 2, 3} )

 

The following code does not work:

list_Category_num = {0 ,1, 2, 3}
Lognormal Estimate Probability( Profile, {1000}, list_Category_num )

 

I tried searching this forum and so far, try to use commands such as "eval()", "eval list()", "eval expr()", but the problem still persist.

 

Below is the full body of the code:

Fit Life by X(

	// Set distribution and parameters
	Distribution( Lognormal ),
	Nested Model Tests( Location and Scale ),
	Y( :ResponseVariable ),
	X( :Category ),
	Censor( :Censor ),
	Censor Code( 1 ),
	
	// Fit Lognormal and set confidence interval
	<<Fit Lognormal,
	<<Confidence Level( 0.95 ),
	for(i = 1, i <= N_Category, i++,
		<<Add Density Curve to Scatterplot(i),
	),
	<<Add Quantile Line to Scatterplot( 0.05 ),
	<<Add Quantile Line to Scatterplot( 0.5 ),
	<<Add Quantile Line to Scatterplot( 0.95 ),
	Show Density Curves( 1 ),
	Use Transformation Scale( 0 ),
	Show Overlay by Levels( 1 ),
	<<Set Scale(
		Lognormal,
		Simultaneous,
		Show Nonparametric CI( 0 ),
		Show Parametric CI( 1 )
	),
	
	<<Set Scriptables(
		{Distribution Comparisons(
			Profiler(
				1,
				Confidence Intervals( 1 ),
				Term Value(
					Category( list_Category[1], Lock( 0 ), Show( 1 ) ),
					ResponseVariable( 1000, Min ( 0 ), Max( 3000 ), Lock( 0 ), Show( 1 ) ),
					{Label Row( Label Orientation( "Angled" ) )}
				)
			)
		),
		
		// ======================================================================================================
		// =============================== BEGIN  OF THE PART RELATED TO QUESTION ===============================
		// ======================================================================================================
		
		list_Category_num = {0 ,1, 2, 3}
		
		Lognormal Estimate Quantile( Profile, {0.001}, {0 ,1, 2, 3} ),	// PASSED: Writing list explicitly as {0, 1, 2, 3} works fine
		
		Lognormal Estimate Probability( Profile, {1000}, list_Category_num )		// FAILED: Using variable for list {0, 1, 2, 3} does not work
		
		// =====================================================================================================
		// ================================ END OF THE PART RELATED TO QUESTION ================================
		// =====================================================================================================
		}

	),
	Confidence Interval Method( Likelihood ),
	
	SendToReport(
		Dispatch(
			{"Nonparametric Overlay"},
			"1",
			ScaleBox,
			{
				Min( 1 ), 
				Max( 1000 ), 
				Inc( 1 ), 
				Minor Ticks( 0 ),
				Add Ref Line( 100, "Dotted", "Black", "", 1 )
			}
		),
		Dispatch(
			{"Scatterplot"},
			"1",
			ScaleBox,
			{Label Row( Label Orientation( "Angled" ) )}
		),
		Dispatch(
			{"Results", "Lognormal Results", "Distribution Profiler"},
			"1",
			ScaleBox,
			{Min( 0 ), Inc( 1 ), Minor Ticks( 0 ),
			Label Row( Label Orientation( "Angled" ) )}
		)
	)
);

 

Thank you very much for your help.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

You must move sending the message after launching the platform. Something like this:

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Reliability/Devalt.jmp" );
obj = dt << Fit Life by X(
	Y( :Hours ),
	X( :Temp ),
	Distribution( Lognormal ),
	Censor( :Censor ),
	Relationship( Arrhenius Celsius ),
	Freq( :Weight )
);
val = {0,1,2,3};
Eval(
	Substitute(
		Expr(
			obj << Set Scriptables( {Lognormal Estimate Probability( Profile, {1000}, vvv ) } );
		),
		Expr( vvv ), val
	)
);

View solution in original post

peng_liu
Staff

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Thank you for bringing this to my attention, @Mark_Bailey !

@Bhume_Chant first please contact support@jmp.com to report this issue. The current program expects a list of numbers, either a list of literal numbers or a list of variables, but does not expect a variable, which is a list. This should be fixed. Please contact the Tech Support. We appreciate it.

To address your current problem, here is a workaround, in line with what Mark has suggested. But I offer a little more insight so the similar technique might be useful in other places where "eval" behavior is not desirable. Here are the two code snips that work.

Here is the first

vvv = {0,1,2,3};
obj = Fit Life by X(
	Distribution( Lognormal ),
	Nested Model Tests( Location and Scale ),
	Y( :ResponseVariable ),
	X( :Category ),
	Censor( :Censor ),
	Censor Code( 1 ),
);
eval(
	substitute(
		expr(
			obj << set scriptables(
			{
				Lognormal Estimate Probability( {1000}, vvv )
			}
			)
		),
		expr(vvv), vvv
	)
);

Here is the second,

vvv = {0,1,2,3};
eval(
	substitute(
		expr(
			Fit Life by X(
				Distribution( Lognormal ),
				Nested Model Tests( Location and Scale ),
				Y( :ResponseVariable ),
				X( :Category ),
				Censor( :Censor ),
				Censor Code( 1 ),
				<< set scriptables(
				{
					Lognormal Estimate Probability( {1000}, vvv )
				}
					
				)
			)
		),
		expr(vvv),vvv
	)
);

Compare them to your script, the difference is what expression is wrapped. The above two snips wrap outside of the platform object. Your script wraps an expression which is a message.

Now I explain why wrapping around a message does not work. When a message is wrapped in side of the eval-substitute trick, that is still at the mercy of platform implementation to recognize what this eval-substitute means. In this case, the platform does not expect it is an expression. And I suspect that is true to most platforms.

So based on what I learned from this case, my suggestion is that use the eval-substitute trick above platform object level.

View solution in original post

8 REPLIES 8

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Not all functions evaluate variable arguments when called, so you must use a literal value for the argument. You can use expressions to solve this problem in the meantime. People have different styles. Here is one example to illustrate the idea.

 

list_Category_num = {0 ,1, 2, 3};

Eval(
	Substitute(
		Expr( Lognormal Estimate Probability( Profile, {1000}, vvv ) ),
		Expr( vvv ), list_Category_num
	)
);

 

Bhume_Chant
Level II

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Hi Mark, thank you very much for your help, but could you help me a bit more with this issue?

 

I tried to embed the script above, there are no errors but also no results shown. I am not sure where I did it wrong.

 

Here is the script that works as intended:

Fit Life by X(
	Distribution( Lognormal ),
	Nested Model Tests( Location and Scale ),
	Y( :ResponseVariable ),
	X( :Category ),
	Censor( :Censor ),
	Censor Code( 1 ),
	<< set scriptables(
	{
		Lognormal Estimate Probability( Profile, {1000}, {0,1,2,3} )
	}
		
	)
);

Here are the intended results:

2022-12-14 10_46_54-DummyData_FitLifeByX - Fit Life by X of ResponseVariable by Category - JMP.png

 

 

Now, I tried to replace the "Lognormal Estimate Probability" part by the script as shown below:

vvv = {0,1,2,3};
Fit Life by X(
	Distribution( Lognormal ),
	Nested Model Tests( Location and Scale ),
	Y( :ResponseVariable ),
	X( :Category ),
	Censor( :Censor ),
	Censor Code( 1 ),
	<< set scriptables(
	{
		eval(
		substitute(
			expr(Lognormal Estimate Probability( Profile, {1000}, vvv )),
			expr(vvv), vvv
			)
		)
	}
		
	)
);

There are no errors, but nothing happens as well:

2022-12-14 10_45_35-DummyData_FitLifeByX - Fit Life by X of ResponseVariable by Category - JMP.png

 

By the way, I also attached the dummy data that used for generating the results.

 

Thank you very much.

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

You must move sending the message after launching the platform. Something like this:

 

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Reliability/Devalt.jmp" );
obj = dt << Fit Life by X(
	Y( :Hours ),
	X( :Temp ),
	Distribution( Lognormal ),
	Censor( :Censor ),
	Relationship( Arrhenius Celsius ),
	Freq( :Weight )
);
val = {0,1,2,3};
Eval(
	Substitute(
		Expr(
			obj << Set Scriptables( {Lognormal Estimate Probability( Profile, {1000}, vvv ) } );
		),
		Expr( vvv ), val
	)
);

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Here is another way from the example in the Scripting Index:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Reliability/Devalt.jmp" );
obj = dt << Fit Life by X(
	Y( :Hours ),
	X( :Temp ),
	Distribution( Lognormal ),
	Censor( :Censor ),
	Relationship( Arrhenius Celsius ),
	Freq( :Weight )
);
p = obj << Probability( Lognormal, 30000, 10 );
Show( p );
Bhume_Chant
Level II

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

It works now! 

 

Thank you so much!

 

 

peng_liu
Staff

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Thank you for bringing this to my attention, @Mark_Bailey !

@Bhume_Chant first please contact support@jmp.com to report this issue. The current program expects a list of numbers, either a list of literal numbers or a list of variables, but does not expect a variable, which is a list. This should be fixed. Please contact the Tech Support. We appreciate it.

To address your current problem, here is a workaround, in line with what Mark has suggested. But I offer a little more insight so the similar technique might be useful in other places where "eval" behavior is not desirable. Here are the two code snips that work.

Here is the first

vvv = {0,1,2,3};
obj = Fit Life by X(
	Distribution( Lognormal ),
	Nested Model Tests( Location and Scale ),
	Y( :ResponseVariable ),
	X( :Category ),
	Censor( :Censor ),
	Censor Code( 1 ),
);
eval(
	substitute(
		expr(
			obj << set scriptables(
			{
				Lognormal Estimate Probability( {1000}, vvv )
			}
			)
		),
		expr(vvv), vvv
	)
);

Here is the second,

vvv = {0,1,2,3};
eval(
	substitute(
		expr(
			Fit Life by X(
				Distribution( Lognormal ),
				Nested Model Tests( Location and Scale ),
				Y( :ResponseVariable ),
				X( :Category ),
				Censor( :Censor ),
				Censor Code( 1 ),
				<< set scriptables(
				{
					Lognormal Estimate Probability( {1000}, vvv )
				}
					
				)
			)
		),
		expr(vvv),vvv
	)
);

Compare them to your script, the difference is what expression is wrapped. The above two snips wrap outside of the platform object. Your script wraps an expression which is a message.

Now I explain why wrapping around a message does not work. When a message is wrapped in side of the eval-substitute trick, that is still at the mercy of platform implementation to recognize what this eval-substitute means. In this case, the platform does not expect it is an expression. And I suspect that is true to most platforms.

So based on what I learned from this case, my suggestion is that use the eval-substitute trick above platform object level.

Bhume_Chant
Level II

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Thank you very much Peng!

 

First, I just sent an email to JMP support team as you suggested. This case was assigned the case number as: TS-00030985.

 

Second, I am very grateful that you also explain in detail about wrapping the platform object and wrapping the message. I will remember this important practice when I need to write JSL in the future.

 

By the way, regarding the code that you showed, both of them works but I have to add the word "profile, " in front of {1000} like this one:

 

This code works with the JMP version I am using:

Lognormal Estimate Probability(profile, {1000}, vvv )

 

This code does not generate errors, but nothing happens with the JMP version I am using:

Lognormal Estimate Probability({1000}, vvv )

 

I am not sure whether the reason I need to add "profile" related to the JMP version I am using or not. I am currently using an older version of JMP (version 16.2).

peng_liu
Staff

Re: How can I make the list's variable works for quantile/probability estimate in the "Fit Life by X"?

Thank you for reporting the issue to Tech Support, @Bhume_Chant 

And I missed "profile". Your observation is correct. In JMP 16, "profile" is needed. And that is to choose "Likelihood CI" type. Please add "profile" in your script.

peng_liu_0-1671112088423.png

Starting in JMP 17, "profile" is no longer required. Both Wald and Lifelihood CIs are reported.