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

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to fit a polynomial degree 2 models with by-groups then capture the paramete...

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

Highlighted

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

Jun 15, 2017 2:51 AM
(5035 views)

I would like to create polynomial degree 2 by each (SERIAL, P1, P2, P3) and get the coefficient and constant then put in each column by using JSL.

The example data was attached in this post, but actually I will do with the data about 1 million rows.

1 ACCEPTED SOLUTION

Accepted Solutions

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

Try this script:

```
_biv=Bivariate(
Y( :y ),
X( :x ),
Fit Special(
Degree( 2 ),
Centered Polynomial( 0 ),
{Line Color( {213, 72, 87} )}
),
By( :SERIAL, :P1, :P2, :P3 )
);
_rbiv=Report(_biv[1]);
_dtParameterEst = _rbiv[Table Box(3)]<< Make Combined Data Table;
_dtParameterEst << Split(
Split By( :Term ),
Split( :Estimate ),
Group( :P3, :P2, :P1, :SERIAL ),
Remaining Columns( Drop All ),
Sort by Column Property
)
```

7 REPLIES 7

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

It would be possible to develop the script below to get what you need:

```
NamesDefaultToHere(1);
ClearLog();
dt = DataTable("Example data.jmp");
col = Column(dt, "Predicted y By SERIAL By P1 By P2 By P3");
// Get the formula generated by the platform
f = col << getFormula;
// Start to parse this formula expression
for(g = 1, g <= Narg(f) - 1, g = g + 2,
f1 = Arg(f, g);
f2 = Arg(f, g+1);
Print(f1, f2, "\!n");
);
```

But I suspect it might be simpler to send the 'MakeCombinedDataTable' message to the appropriate table in the report window if that's possible. Look in 'Help > Scripting Guide'.

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

Also, if you are using the Fit Y by X platform / Bivariate platform to generate the polynomial fits, make sure to do a "Fit Special" and use uncentered polynomials. Otherwise the fitted quadratic will be of the form

f(x) = a + b*x + c*(x-xbar)

where xbar is the mean of the x values used in the regression.

Doing the fitting with a By variable and then right clicking the parameter estimates table to make a combined data table is a very efficient way to do this.

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

Thanks MathStatChem, let me try for your suggestion.

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

Thanks ian_jmp, let me try.

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

Try this script:

```
_biv=Bivariate(
Y( :y ),
X( :x ),
Fit Special(
Degree( 2 ),
Centered Polynomial( 0 ),
{Line Color( {213, 72, 87} )}
),
By( :SERIAL, :P1, :P2, :P3 )
);
_rbiv=Report(_biv[1]);
_dtParameterEst = _rbiv[Table Box(3)]<< Make Combined Data Table;
_dtParameterEst << Split(
Split By( :Term ),
Split( :Estimate ),
Group( :P3, :P2, :P1, :SERIAL ),
Remaining Columns( Drop All ),
Sort by Column Property
)
```

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

Hi MathStatChem,

Your solution it work.

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

Re: How to create polynomial degree 2 and get the coefficient and constant?

Hi ian_jmp, My objective is get the coefficient and constant of "y = ax^2+bx+c" but in fit polynomial is "y = a(x-d)^2+bx+c". However I got the solution from user# MathStatChem by fit special.