Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
nikles
Level IV

How to control distribution options in JSL?

Hi.  I'm having some issues modifying some Distribution platform options in JSL (e.g. Outlier Box Plot, Normal Quantile Plot, etc).  I'm writing a script that would allow users to create distributions for an arbitrary list of columns.  Additionally, I'd like to give the user the ability to specify if Outlier Box Plots or Normal Quantile Plots are enabled for all plots.  Having some problems though and hoping someone can offer some insight.  

 

For the record, I'm running JMP Pro 14.3.0 on a Mac.

 

First I tried this:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
tcol_lis = {"height", "weight"};

//First approach
nqplopt = 1;		//This is meant to turn on the Normal Quantile Plot option
Distribution(		
	Column(EvalList(tcol_lis)),
	Normal Quantile Plot(nqplopt),
);

nqplopt = 0;		//But it has no effect
Distribution(		
	Column(EvalList(tcol_lis)),
	Normal Quantile Plot(nqplopt),
);

Seems like it should've worked, but setting "nqplopt" to 1 or 0 has no effect.  In my case the quantile plot was generated both times.  Interesting since that option is off in my preferences.

 

Next, I tried to send a message to the distribution after creation instead.

//Second approach - send the Normal Quantile option as a message
nqplopt = 1;		
dist = Distribution(		
	Column(EvalList(tcol_lis))
);
dist << Normal Quantile Plot(nqplopt);		

nqplopt = 0;		
dist = Distribution(		
	Column(EvalList(tcol_lis))
);
dist << Normal Quantile Plot(nqplopt);	//No difference from when nqplopt = 1

As before, no difference when nqplopt is 1 or 0.  I'm doubtful this would work for me anyway since the object "dist" refers to multiple distributions and I'm not sure how JSL would handle sending a message to that.

 

Lastly, I went to my go-to solution, force the substitutions I want using a JSL Quote:

//Third approach - make substitutions via JSL Quote
nqplopt = 0;		
dist_jst = JSL Quote(
	Distribution(		
		Column(EvalList(tcol_lis)),
		Normal Quantile Plot(nqplopt_ph),
	);
);
SubstituteInto(dist_jst,
	Expr(nqplopt_ph), nqplopt
);
Show(dist_jst);			//The "nqplopt_ph" remains unchanged for some reason.
Eval(Parse(dist_jst));	//Dist. created with a Normal Quantile Plot, as if nqplopt = 1 

Still, like an out-of-work croupier, no dice.  When I show the modified dist_jst string, it's as if the SubstituteInto command were never issued.  I'm curious why is this?  I've used JSL Quote before many times, but I cannot understand why it seems unable to make this modification?

 

Any thoughts or workarounds?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
gzmorgan0
Super User

Re: How to control distribution options in JSL?

@nikles,

Congratulations on finding a solution that works for you.  Below is an alternative. 

EvalExpr() replaces each Expr(variable) with its value and returns an expression with values.  So Eval( EvalExpr() ) with replace the variables with values and run the resulting expression.  Note I added and commented out Ignore Platform Preferences(1). If a user has different preferences than the scripter the report might not be the same. Ignore Platform Preferences(1) turns off all preferences for this analysis, so the scripter must specify all that should be visible.  However, it ensures the user will see the same analysis as other users.

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
tcol_lis = {"height", "weight"};

//First approach
nqplopt = 1;		//This is meant to turn on the Normal Quantile Plot option
Eval(EvalExpr(Distribution( //Ignore Platform Preferences(1),		
	Column( EvalList(tcol_lis)),
	Normal Quantile Plot(nqplopt),
)));

nqplopt = 0;		//But it has no effect
Eval( Eval Expr(Distribution(//Ignore Platform Preferences(1),		
	Column(EvalList(tcol_lis)),
	Normal Quantile Plot(Expr(nqplopt)),
)) );

  

View solution in original post

4 REPLIES 4
Highlighted
nikles
Level IV

Re: How to control distribution options in JSL?

Well...I may have come up with an answer to my own question.  I'm still curious why the JSL Quote route did not work, but the solution I adopted was to use a literal quoted string instead.  As shown here:

//Fourth approach - make substitutions via a literal string quote
nqplopt = 0;		
dist_str = 
	"Distribution(		
		Column(EvalList(tcol_lis)),
		Normal Quantile Plot(nqplopt_ph),
	)";
SubstituteInto(dist_str,
	"nqplopt_ph", Char(nqplopt)
);
Show(dist_str);			//The "nqplopt_ph" is successfully changed to 0.
Eval(Parse(dist_jst));	//Finally, it works.

I'm told this is not generally considered "good practice" (putting the entire command in quotes), but meh...it works.

Highlighted
nikles
Level IV

Re: How to control distribution options in JSL?

*Eval(Parse(dist_str)), not Eval(Parse(dist_jst) in the last line of my script above. My mistake.
Highlighted
gzmorgan0
Super User

Re: How to control distribution options in JSL?

@nikles,

Congratulations on finding a solution that works for you.  Below is an alternative. 

EvalExpr() replaces each Expr(variable) with its value and returns an expression with values.  So Eval( EvalExpr() ) with replace the variables with values and run the resulting expression.  Note I added and commented out Ignore Platform Preferences(1). If a user has different preferences than the scripter the report might not be the same. Ignore Platform Preferences(1) turns off all preferences for this analysis, so the scripter must specify all that should be visible.  However, it ensures the user will see the same analysis as other users.

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
tcol_lis = {"height", "weight"};

//First approach
nqplopt = 1;		//This is meant to turn on the Normal Quantile Plot option
Eval(EvalExpr(Distribution( //Ignore Platform Preferences(1),		
	Column( EvalList(tcol_lis)),
	Normal Quantile Plot(nqplopt),
)));

nqplopt = 0;		//But it has no effect
Eval( Eval Expr(Distribution(//Ignore Platform Preferences(1),		
	Column(EvalList(tcol_lis)),
	Normal Quantile Plot(Expr(nqplopt)),
)) );

  

View solution in original post

Highlighted
nikles
Level IV

Re: How to control distribution options in JSL?

Thanks! I'll give that a try! Plus - was not aware about the Ignore Platform Prefs command. That makes life a lot easier.
Article Labels

    There are no labels assigned to this post.