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
- :
- JSL Script - Grab Prediction Formula Result

Topic Options

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

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

May 24, 2017 11:47 PM
(1035 views)

Hello,

I am trying to obtain the predicted value after setting the X's in a prediction formula.

For example, if Y = X1 + X2, I want to create a new row, set X1 = 2 and X2 = 4 and grab the predicted value of Y = 6.

I thought the easiest way to do this would be to save the prediction formula into a new set of columns.

I would then add a new row and set all the X's.

Then, simply access the row value of the prediction formula.

However, this does not work. The log shows that the value returns a '.'. If I run the script twice, so multiple rows are created, the value returns correctly. If I add two rows and run the script only once, I still get the 'null' or '.' in the log file. There appears to be a reason for JMP needing to run the script twice to obtain the predicted formula result of a newly added row with set X values.

Is there a better way to grab predicted values from prediction formulas using scripts?

Thank you,

Nate

1 ACCEPTED SOLUTION

Accepted Solutions

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

May 25, 2017 12:44 AM
(2047 views)

Solution

Details depend on the platform you use, but this shows the basic idea:

```
NamesDefaultToHere(1);
// Get some data
dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt << Bivariate(X(:height), Y(:weight));
// Do a regression
biv << fitLine;
/// Save the prediction formula column
biv << (curve[1] << savePredicteds);
// Add a new observation (row) that we want to predict for
Wait(2);
dt << addRows(1);
// Give predictor values and get the prediction back
Column(dt, "weight")[NRow(dt)] = 160;
Column(dt, "height")[NRow(dt)] = 65;
```

8 REPLIES

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

May 25, 2017 12:44 AM
(2048 views)

Details depend on the platform you use, but this shows the basic idea:

```
NamesDefaultToHere(1);
// Get some data
dt = Open("$SAMPLE_DATA/Big Class.jmp");
biv = dt << Bivariate(X(:height), Y(:weight));
// Do a regression
biv << fitLine;
/// Save the prediction formula column
biv << (curve[1] << savePredicteds);
// Add a new observation (row) that we want to predict for
Wait(2);
dt << addRows(1);
// Give predictor values and get the prediction back
Column(dt, "weight")[NRow(dt)] = 160;
Column(dt, "height")[NRow(dt)] = 65;
```

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

May 25, 2017 1:38 AM
(1020 views)

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

May 25, 2017 1:57 AM
(1017 views)

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

Aug 14, 2017 8:08 AM
(508 views)

Hello Ian,

I'm searching the community for saving the "Save Y Predicted Values" from the PLS in a JSL. Is there a document available saying in which Tool I adress which colum saving (e.g. prediction formulas, Confidence intervals, Predicted Values).

Thanks Peter

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

Aug 14, 2017 9:07 AM
(499 views)

Hi Peter, This should help to get you started. The 'Wait()' commands are for cosmetic effect and can be removed.

```
NamesDefaultToHere(1);
// Get some data
dt = Open( "$SAMPLE_DATA/Baltic.jmp" );
// Launch the PLS platform
plsLaunch = dt << Fit Model(
Y( :ls, :ha, :dt ),
Effects(
:v1,
:v2,
:v3,
:v4,
:v5,
:v6,
:v7,
:v8,
:v9,
:v10,
:v11,
:v12,
:v13,
:v14,
:v15,
:v16,
:v17,
:v18,
:v19,
:v20,
:v21,
:v22,
:v23,
:v24,
:v25,
:v26,
:v27
),
No Intercept( 1 ),
Center Polynomials( 0 ),
Personality( "Partial Least Squares" )
);
// Do a couple of fits
Wait(2);
plsFits = plsLaunch << Run(
Fit( Method( NIPALS ), Number of Factors( 7 ) ),
Fit( Method( NIPALS ), Number of Factors( 6 ) )
);
// Save the prediction formula for the first fit (7 factors)
Wait(2);
plsFits << (Fit[1] << savePredictionFormula);
// Save the prediction formula for the second fit (6 factors)
Wait(2);
plsFits << (Fit[2] << savePredictionFormula);
// Now save the Y residuals
Wait(2);
plsFits << (Fit[1] << saveYresiduals);
plsFits << (Fit[2] << saveYresiduals);
```

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

Aug 15, 2017 1:34 AM
(480 views)

thanks Ian

Sorry, my scripting knowledge is too restricted, your help is not accelerating me, can you please get me some more support.

First I work with JMP not with PRO. I assume that is the reason that my JMP automated PLS script looks different to yours. I attached my script.

Plenty of questions appear reading your script.

Why do you separte between PLSLAUNCH and PLSFITS. Is that necessary or just for your comfort in reading/documenting?

Is it necessary to assign PLSFITS the fits if I just have one "fits" eg. just 7 Factors (plsFits << (Fit[1] << savePredictionFormula);

plsFits << (Fit[1] << saveYresiduals); I assume that means: Save the residual of Fit[1] to the object PLSFITS (and this name can be chosen by me, it is just PLSFITS for better identification)

If I run your script I get this error in the logwindow: plsFits << (Fit[/*###*/1] << savePredictionFormula); Is that because of PRO Terminology?

Many thanks

Peter

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

Aug 15, 2017 1:52 AM
(477 views)

I was forgetting about the fact that there is additional PLS functionality in JMP Pro that is not in the regular version. For JMP it will be similar, but a little simpler:

```
NamesDefaultToHere(1);
// Get some data
dt = Open( "$SAMPLE_DATA/Baltic.jmp" );
// Do a PLS fit in JMP (also works in JMP Pro)
pls = dt << Partial Least Squares(
Y( :ls, :ha, :dt ),
X(
:v1,
:v2,
:v3,
:v4,
:v5,
:v6,
:v7,
:v8,
:v9,
:v10,
:v11,
:v12,
:v13,
:v14,
:v15,
:v16,
:v17,
:v18,
:v19,
:v20,
:v21,
:v22,
:v23,
:v24,
:v25,
:v26,
:v27
),
Validation Method( Name( "Leave-One-Out" ), Initial Number of Factors( 15 ) ),
Fit(
Method( NIPALS ),
Number of Factors( 7 ),
Show Confidence Band( 1 ),
Distance Plots( 1 ),
Scatter Scores Plots( 1 ),
Diagnostics Plots( 1 ),
Overlay Loadings Plots( 1 ),
T Square Plot( 1 ),
Overlay Coefficients Plots( 1 )
)
);
// See what messages the PLS platform understands (look in the Log Window)
ClearLog();
ShowProperties(pls);
// Save some results from the (7 factor) fit
pls << (Fit[1] << savePredictionFormula);
pls << (Fit[1] << saveYresiduals);
```

To understand why the code works, I would start with 'Help > Books > Scripting Guide' to learn the rudiments of JSL.

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

Aug 15, 2017 6:12 AM
(463 views)