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
- :
- Discussions
- :
- Format prediction expression

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

Aug 30, 2016 11:55 PM
(4129 views)

Hi,

Within Fit Model (Least squares option), it is possible to change the format of numbers in the "parameter estimates". It is also possible to change the format (e.g. the number of decimals) for the predition expression?

Thank you,

Elie

1 ACCEPTED SOLUTION

Accepted Solutions

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

Elie,

Here is a script that illustrates what I eluded to in my last response: It uses the formula that is generated when the prediction column is generated. However, the script could also be written to just grab the parameter estimates from the Parameter Estimates table that is displayed, and to modify it and place it back into the display. This would be the programmers choice.

Names Default To Here**(** **1** **)**;

dt = Open**(** "$SAMPLE_DATA\semiconductor capability.jmp" **)**;

// Run the analysis

fm = dt << **Fit Model(**

Y**(** :NPN1 **)**,

Effects**(** :PNP1, :PNP2, :NPN2 **)**,

Personality**(** "Standard Least Squares" **)**,

Emphasis**(** "Minimal Report" **)**,

Run**(**

:NPN1 << **{****Lack of Fit(** **0** **)**, Plot Actual by Predicted**(** **0** **)**, Plot Regression**(** **0** **)**,

Plot Residual by Predicted**(** **0** **)**, Plot Effect Leverage**(** **0** **)}**

**)**

**)**;

// Output the formula to a new column

fm << **Prediction Formula**;

// Get the formula back as a character string

TheFormula = Char**(** Column**(** dt, N Cols**(** dt **)** **)** << **get formula** **)**;

// Strip out the elements and reformat the values

Intercept = Format**(** Num**(** Word**(** **1**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta1 = Format**(** Num**(** Word**(** **3**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta2 = Format**(** Num**(** Word**(** **7**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta3 = Format**(** Num**(** Word**(** **11**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

// Reconstruct the prediction formula

NewFormula = Intercept || " + " || Beta1 || " * :PNP1 + " || Beta2 ||

" * :PNP2 + " || Beta3 || " * :NPN2";

// Write it back to the displayed output

Report**(** fm **)[**"Parameter Estimates"**]** << **append(** Outline Box**(** "Prediction Formula", Text Box**(** NewFormula **)** **)** **)**;

Jim

4 REPLIES

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

Re: Format prediction expression

Aug 31, 2016 7:06 PM
(3992 views)
| Posted in reply to message from elie_maricau 08/31/2016 02:55 AM

If you double click on a column within the parameter estimates table, a window will popup that allows you to change the format of the numbers. You just have to repeat the same operation for each column. This is a feature available in JMP for all displayed tables in the output. If you want to do this using JSL, then the answer is also yes. Number Col Box() can have their formats defined.

Concerning the displayed Prediction Expression. This is actually a picture object, and isn't changeable. However, the prediction formula can be saved as a formula in a new column, and the formula could then be picked, and added to the display using whatever level of decimal significance you want.

Jim

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

Re: Format prediction expression

Hi Jim,

Thank you for the quick reply. The first part of your answer, I did know. I was, however, specifically refering to the displayed prediction expression. As I suspected it is indeed a picture object.

Could you elaborate a little bit on what you mean with "picking a saved prediction formula and adding it to the display". I do know how to save a formula (and I often use it) but I don't know what you mean with adding it to the display in whatever format you want. Is this within JMP or are you refering to manually reducing the number of decimals somewhere else?

Thank you,

Elie

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

Elie,

Here is a script that illustrates what I eluded to in my last response: It uses the formula that is generated when the prediction column is generated. However, the script could also be written to just grab the parameter estimates from the Parameter Estimates table that is displayed, and to modify it and place it back into the display. This would be the programmers choice.

Names Default To Here**(** **1** **)**;

dt = Open**(** "$SAMPLE_DATA\semiconductor capability.jmp" **)**;

// Run the analysis

fm = dt << **Fit Model(**

Y**(** :NPN1 **)**,

Effects**(** :PNP1, :PNP2, :NPN2 **)**,

Personality**(** "Standard Least Squares" **)**,

Emphasis**(** "Minimal Report" **)**,

Run**(**

:NPN1 << **{****Lack of Fit(** **0** **)**, Plot Actual by Predicted**(** **0** **)**, Plot Regression**(** **0** **)**,

Plot Residual by Predicted**(** **0** **)**, Plot Effect Leverage**(** **0** **)}**

**)**

**)**;

// Output the formula to a new column

fm << **Prediction Formula**;

// Get the formula back as a character string

TheFormula = Char**(** Column**(** dt, N Cols**(** dt **)** **)** << **get formula** **)**;

// Strip out the elements and reformat the values

Intercept = Format**(** Num**(** Word**(** **1**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta1 = Format**(** Num**(** Word**(** **3**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta2 = Format**(** Num**(** Word**(** **7**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

Beta3 = Format**(** Num**(** Word**(** **11**, TheFormula, " " **)** **)**, "Fixed Dec", **4** **)**;

// Reconstruct the prediction formula

NewFormula = Intercept || " + " || Beta1 || " * :PNP1 + " || Beta2 ||

" * :PNP2 + " || Beta3 || " * :NPN2";

// Write it back to the displayed output

Report**(** fm **)[**"Parameter Estimates"**]** << **append(** Outline Box**(** "Prediction Formula", Text Box**(** NewFormula **)** **)** **)**;

Jim

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

Re: Format prediction expression

Great idea Jim! And generalizing it to handle prediction formulas of any complexity was a good scripting exercise.

There is a function *Expr as Picture()* that may come in handy. Complex prediction formulas with multiple *Match* clauses and escaped quotation marks can be hard to read.

Here's my attempt. Seems to work but only tested for a few models.

Names Default To Here**(****1****)**;

// Fit Model and save formula to the data table

dt = Open**(**"$SAMPLE_DATA/Big Class.jmp"**)**;

fm = Fit Model**(**Y**(**:weight**)**, Effects**(**:sex, :height, :sex * :height**)**, Run**)**;

col = fm << **prediction formula**;

// Round all numbers in prediction formula to n digits

n = **2**; // Set desired number of decimals here

pos = **1**; // Substr start position

f = Char**(**col << **get formula****)**; // Pred. formula as string

// Expr: Find next raw number

raw = Expr**(**Regex**(**Substr**(**f, pos**)**, "\d+\.\d+"**))**;

// Expr: Round number (Substitute only required for locales with decimal comma)

rounded = Expr**(**Substitute**(**Char**(**Num**(**raw**)**,, n**)**, ",", "."**))**;

// Replace all numbers with rounded numbers

pos = Contains**(**f, raw**)**;

While**(**!Is Missing**(**raw**)**,

Substitute Into**(**f, raw, rounded**)**;

pos += Length**(**rounded**)**;

**)**;

Show**(**f**)**;

//Add expression to report

e = Parse**(**f**)**;

Report**(**fm**)[**Outline Box**(****2****)]** << **append****(**Outline Box**(**"Pred. formula", Expr As Picture**(**Name Expr**(**e**))))**;

fm << **show prediction expression**; // Just to compare with default