Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Re: Add predicted columns to the data table

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Apr 26, 2018 1:46 PM
(4749 views)

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;
```

2 ACCEPTED SOLUTIONS

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

10 REPLIES 10

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Add predicted columns to the data table

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

Uday

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Uday

Highlighted
##

@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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Add predicted columns to the data table

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Highlighted
##

@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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Add predicted columns to the data table

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Add predicted columns to the data table

@powerpuff,

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

Best

Uday

Uday

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Add predicted columns to the data table

@uday_guntupalli yep, thanks for the help!!