Choose Language Hide Translation Bar
Highlighted
powerpuff
Community Trekker

Add predicted columns to the data table

I have a script in my JMP table named "Outlier Analysis". I open the script, hit the little red triangle and select Save Columns--> Prediction Formula. How can I script this? 

Here is my approach:

 

dt = current data table();
a = Eval( dt << get table property( "Outlier Analysis" ) ); 
abc = a << Report;
abc << prediction formula;

 

0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
gzmorgan0
Super User

Re: Add predicted columns to the data table

See the Scripting Guide and search for Scripting-Only Messages and Arguments by Platform. The messages and options are different by model.

Standard Least Squares
The following JSL messages return the requested item from the fitted model, such as variance components, p-values, parameter estimates, and so on:
   fit_model_object << Get Variance Components( );
   fit_model_object << Get Effect Names( );
   fit_model_object << Get Effect PValues( );
   fit_model_object << Get Estimates( );
   fit_model_object << Get Parameter Names( );
   fit_model_object << Get Random Effect Names( );
   fit_model_object << Get Std Errors( );
   fit_model_object << Get X Matrix( );
   fit_model_object << Get XPX Inverse( );
   fit_model_object << Get Y Matrix( );
The following message for Standard Least Squares objects is available only in JSL:
   obj << Get SQL prediction expression;

___________________________________________________________________________________

For the last example,  xx = FM << get prediction Formula; show(xx); 

 

/*Log

xx = New Column("y", Numeric, Formula((-2.69577290612704) + Match(:Drug, "a", -1.18503653738055, "d", -1.07606520517145, "f", 2.261101742552, .) + 0.987183811129848 * :x), Set Property("Predicting", {:y, Creator("Fit Least Squares")}));

 

Are you asking how to write a script to get the formulas from an already created window with a fitted report?  If yes, let's see if I can emulate that situation: Help> Scripting Index>Objects>Fit Model > Least Squares then run the sample script.

 

obj the reference to the Least Squares Fit is only recognized within that script.  To be able to get the formula you needto get a handle to the model object. There might be another method, but here is my method:

 - prompt for the window or use window name to create a handle to the report

 - get its child and the first OutlIne Box

- get the scriptable Object

- get the formula.

 

If your script has multiple models, I recommend you use Xpath to get all instances.  The attached script gets the formulas from the Scripting Index script. The report has 2 responses (2 models) and creates an associative array of formulas.

 

I am not sure this is what you were asking for.   By the way, once you have a handle(reference) to the scrtiptable object you can send it messages to save the formulas to the table. One of the nice features of Xpath, and get scriptable object,  it might find 20 models, but you can send the message once and it is applied to each of the models.

 

If this isn't your question, please clarify. 

View solution in original post

0 Kudos
Highlighted
powerpuff
Community Trekker

Re: Add predicted columns to the data table

I am sorry, but I realized it was the easiest. 

Just two lines of code have saved my formula 

a = Eval( dt << get table property( "Outlier Analysis" ) ); 
a << save prediction formula;

Thank you for the help and I am so sorry for the confusion. I only added "save" which I somehow missed. 

View solution in original post

0 Kudos
10 REPLIES 10
Highlighted
uday_guntupalli
Community Trekker

Re: Add predicted columns to the data table

@powerpuff

Look at the example below. 

dt = Open( "$SAMPLE_DATA/Boston Housing.jmp" );
obj = Partition(
	Y( :mvalue ),
	X(
		:crim,
		:zn,
		:indus,
		:chas,
		:nox,
		:rooms,
		:age,
		:distance,
		:radial
	),
	Method( "Boosted Tree" ),
	Validation Portion( .2 ),
	Go
);
obj << Save Prediction Formula;
Best
Uday
Highlighted
powerpuff
Community Trekker

Re: Add predicted columns to the data table

I get it, but I already have the script ready. I dont want to add the Partition part again. For example, 

 

 

a = Eval( dt << get table property( "Outlier Analysis" ) ); 
abc = a << Report;
dta = abc["Summary of Fit"][Table Box( 1 )] << Make Combined data table;

 

This script helped me open up the Summary of Fit table from the "Outlier Analysis" script. Is there any way I can add Prediction Formula that way? @uday_guntupalli

 

0 Kudos
Highlighted
uday_guntupalli
Community Trekker

Re: Add predicted columns to the data table

@powerpuff
        I am not sure I followed what ou said however based on what I understand, here : 

For a Fit Model analysis, that you do, you can capture the formula directly into the table this way. You dont need to extract the formula separately. 

dt = Open( "$SAMPLE_DATA/Drug.jmp" );
FM = dt << Fit Model(
	Y( :y ),
	Effects( :Drug, :x ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Minimal Report" ),
	Run(
		:y << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
		Parameter Estimates( 1 ), Show Prediction Expression( 1 ),
		Plot Actual by Predicted( 0 ), Plot Residual by Predicted( 0 ),
		Plot Effect Leverage( 0 )}
	)
);


FM << Get Prediction Formula; 

Check your log and the formula is printed. When you mean get the formula that way, I presume you want to access it from the report. If that is what you are after, you can add as shown above - Show Prediction Expression(1) to your Fit Model and then access the expression 

Best
Uday
0 Kudos
powerpuff
Community Trekker

Re: Add predicted columns to the data table

@uday_guntupalli but I have a fit group with a lot of fit models. Plus, I don't want to limit doing this to only one script. 

0 Kudos
Highlighted
gzmorgan0
Super User

Re: Add predicted columns to the data table

See the Scripting Guide and search for Scripting-Only Messages and Arguments by Platform. The messages and options are different by model.

Standard Least Squares
The following JSL messages return the requested item from the fitted model, such as variance components, p-values, parameter estimates, and so on:
   fit_model_object << Get Variance Components( );
   fit_model_object << Get Effect Names( );
   fit_model_object << Get Effect PValues( );
   fit_model_object << Get Estimates( );
   fit_model_object << Get Parameter Names( );
   fit_model_object << Get Random Effect Names( );
   fit_model_object << Get Std Errors( );
   fit_model_object << Get X Matrix( );
   fit_model_object << Get XPX Inverse( );
   fit_model_object << Get Y Matrix( );
The following message for Standard Least Squares objects is available only in JSL:
   obj << Get SQL prediction expression;

___________________________________________________________________________________

For the last example,  xx = FM << get prediction Formula; show(xx); 

 

/*Log

xx = New Column("y", Numeric, Formula((-2.69577290612704) + Match(:Drug, "a", -1.18503653738055, "d", -1.07606520517145, "f", 2.261101742552, .) + 0.987183811129848 * :x), Set Property("Predicting", {:y, Creator("Fit Least Squares")}));

 

Are you asking how to write a script to get the formulas from an already created window with a fitted report?  If yes, let's see if I can emulate that situation: Help> Scripting Index>Objects>Fit Model > Least Squares then run the sample script.

 

obj the reference to the Least Squares Fit is only recognized within that script.  To be able to get the formula you needto get a handle to the model object. There might be another method, but here is my method:

 - prompt for the window or use window name to create a handle to the report

 - get its child and the first OutlIne Box

- get the scriptable Object

- get the formula.

 

If your script has multiple models, I recommend you use Xpath to get all instances.  The attached script gets the formulas from the Scripting Index script. The report has 2 responses (2 models) and creates an associative array of formulas.

 

I am not sure this is what you were asking for.   By the way, once you have a handle(reference) to the scrtiptable object you can send it messages to save the formulas to the table. One of the nice features of Xpath, and get scriptable object,  it might find 20 models, but you can send the message once and it is applied to each of the models.

 

If this isn't your question, please clarify. 

View solution in original post

0 Kudos
Highlighted
powerpuff
Community Trekker

Re: Add predicted columns to the data table

@gzmorgan0 yes, I meant getting formulas from an already existing report. How can I write a more generalized script to achieve this? So, I have a fitted model in the Peanuts sample dataset. How can I add (using JSL) the prediction formula or studentized residuals to the existing Peanuts data table? I manually do: Save Columns--> for this.

0 Kudos
Highlighted
powerpuff
Community Trekker

Re: Add predicted columns to the data table

I am sorry, but I realized it was the easiest. 

Just two lines of code have saved my formula 

a = Eval( dt << get table property( "Outlier Analysis" ) ); 
a << save prediction formula;

Thank you for the help and I am so sorry for the confusion. I only added "save" which I somehow missed. 

View solution in original post

0 Kudos
Highlighted
uday_guntupalli
Community Trekker

Re: Add predicted columns to the data table

@powerpuff
 Which is what I kept referring you to . Glad it finally worked. 

Best
Uday
0 Kudos
Highlighted
powerpuff
Community Trekker

Re: Add predicted columns to the data table

@uday_guntupalli yep, thanks for the help!!

0 Kudos