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
- :
- Script? Applying non-linear model column formula to multiple columns

Topic Options

- Start Article
- 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

Dec 8, 2016 6:50 AM
(5193 views)

I have a model formula in column 1 with 2 parameters and I would like to fit this model to 80 different data columns (Cols 2 - 82), where each data column has those 2 parameters custom-fit for it. Is there an easy way to do this?

Would I have to write a script?

1 ACCEPTED SOLUTION

Accepted Solutions

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

Thank you!

Testing now ...

received following error upon debugging

Cannot subscript Display Box in access or evaluation of 'Subscript' , Report( nl fit )[/*###*/"Parameter Estimates"]

@markbailey wrote:This solution turns out to be a bit tricky. It only works if the model you are using is NOT one of those in the Fit Curve library. (If it is, then Nonlinear launches Fit Curve, which expects the model to be specified by name, which this script doesn't provide.) Based on your claim that the actual model is more complicated, then I took the chance that it is not in the Fit Model library and wrote this script:

Names Default to Here( 1 ); dlg = Column Dialog( Title( "Nonlinear Regression" ), yCol = Col List( "Y, Response", Data Type( Numeric ), Min Col( 1 ) ), xCol = Col List( "X, Predictor Formula", Data Type( Numeric ), Min Col( 1 ), Max Col( 1 ) ) ); If( dlg["Button"] != 1, Throw( "User cancelled" ); ); Remove From( dlg ); Eval List( dlg ); dt = Current Data Table(); n fits = N Items( yCol ); formula = xCol[1] << Get Formula; n parms = N Items( Arg( formula, 1 ) ); parm = J( n fits, n parms, . ); For( f = 1, f <= n fits, f++, nl fit = dt << Nonlinear( Y( yCol[f] ), X( xCol[1] ), Newton, Finish ); parm[f,0] = Transpose( Report( nl fit )["Parameter Estimates"][NumberColBox(1)] << Get As Matrix ); ); As Table( parm );Open the JMP data table first, then open and run this script. Select all of the response columns (columns 2-82 in your example) and click

Y, Response. Click the column with the model formula (column 1 in your example) and clickX, Predictor Formula, . Then clickOK.

10 REPLIES 10

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

Re: Script? Applying non-linear model column formula to multiple columns

What is your non-linear model that is stored as a formula in column 1? This formula is usually a function of the predictor variable. Which column holds the predictor values?

If this case is simple, I can write a script.

Learn it once, use it forever!

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

Re: Script? Applying non-linear model column formula to multiple columns

Yes, a predictor variable exists in another column.

We can call it column 83 if you like.

And I suppose my target output would be a table which shows the best fit values of the two parameters per column with associated confidence intervals.

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

Re: Script? Applying non-linear model column formula to multiple columns

I will ask again: what is the non-linear model ( f(X) ) expressed in the column 1 formula? What are the two parameters?

Verifying: predictor (X) is last column and it is used in formula in column 1?

Verifying: the individual responses (Y) are in columns 2-82?

Verifying: you want to fit Y = f(X) separately to each Y and capture the parameter estimates for each Y?

Learn it once, use it forever!

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

Re: Script? Applying non-linear model column formula to multiple columns

Mark,

Thank you.

The responses to all your Verifying questions are yes.

The formula can be anything, but let's say its y = h*exp(-b*x^(0.65)) for simplicity, with h and b as parameters and x>0.

The actual formula is much more complicated, but that extra complication shouldn't impact the solution.

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

Re: Script? Applying non-linear model column formula to multiple columns

You can do it without a script but it will involve a lot of clicking. Assuming that you already have set up the non-linear model as a column formula, follow these steps:

- Select Tables > Stack.
- Select all the response columns (2-82 in your example) and click Stack.
- Make sure that the option to copy the formulas is selected.
- Enter a name for the Data column, such as Response.
- Enter a name for the Label column, such as Curve.
- Click OK.
- Select Analyze > Specialized Models > Nonlinear.
- Select the predictor column (83 in your example) and click X
- Select the model column (1 in your example) and click Y.
- Select the Curve column and click By.
- Click OK.
- Now click Go for each Curve. (This is the tedious part.)
- Right-click on any Parameter Estimates report and select Make Combined Data Table.

This process should give you a new data table with all of the parameter estimates.

Learn it once, use it forever!

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

Re: Script? Applying non-linear model column formula to multiple columns

This solution turns out to be a bit tricky. It only works if the model you are using is NOT one of those in the Fit Curve library. (If it is, then Nonlinear launches Fit Curve, which expects the model to be specified by name, which this script doesn't provide.) Based on your claim that the actual model is more complicated, then I took the chance that it is not in the Fit Model library and wrote this script:

```
Names Default to Here( 1 );
dlg = Column Dialog(
Title( "Nonlinear Regression" ),
yCol = Col List( "Y, Response",
Data Type( Numeric ),
Min Col( 1 )
),
xCol = Col List( "X, Predictor Formula",
Data Type( Numeric ),
Min Col( 1 ),
Max Col( 1 )
)
);
If( dlg["Button"] != 1,
Throw( "User cancelled" );
);
Remove From( dlg );
Eval List( dlg );
dt = Current Data Table();
n fits = N Items( yCol );
formula = xCol[1] << Get Formula;
n parms = N Items( Arg( formula, 1 ) );
parm = J( n fits, n parms, . );
For( f = 1, f <= n fits, f++,
nl fit = dt << Nonlinear( Y( yCol[f] ), X( xCol[1] ), Newton, Finish );
parm[f,0] = Transpose( Report( nl fit )["Parameter Estimates"][NumberColBox(1)] << Get As Matrix );
);
As Table( parm );
```

Open the JMP data table first, then open and run this script. Select all of the response columns (columns 2-82 in your example) and click **Y, Response**. Click the column with the model formula (column 1 in your example) and click **X, Predictor Formula**, . Then click **OK**.

Learn it once, use it forever!

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

Thank you!

Testing now ...

received following error upon debugging

Cannot subscript Display Box in access or evaluation of 'Subscript' , Report( nl fit )[/*###*/"Parameter Estimates"]

@markbailey wrote:This solution turns out to be a bit tricky. It only works if the model you are using is NOT one of those in the Fit Curve library. (If it is, then Nonlinear launches Fit Curve, which expects the model to be specified by name, which this script doesn't provide.) Based on your claim that the actual model is more complicated, then I took the chance that it is not in the Fit Model library and wrote this script:

Names Default to Here( 1 ); dlg = Column Dialog( Title( "Nonlinear Regression" ), yCol = Col List( "Y, Response", Data Type( Numeric ), Min Col( 1 ) ), xCol = Col List( "X, Predictor Formula", Data Type( Numeric ), Min Col( 1 ), Max Col( 1 ) ) ); If( dlg["Button"] != 1, Throw( "User cancelled" ); ); Remove From( dlg ); Eval List( dlg ); dt = Current Data Table(); n fits = N Items( yCol ); formula = xCol[1] << Get Formula; n parms = N Items( Arg( formula, 1 ) ); parm = J( n fits, n parms, . ); For( f = 1, f <= n fits, f++, nl fit = dt << Nonlinear( Y( yCol[f] ), X( xCol[1] ), Newton, Finish ); parm[f,0] = Transpose( Report( nl fit )["Parameter Estimates"][NumberColBox(1)] << Get As Matrix ); ); As Table( parm );Open the JMP data table first, then open and run this script. Select all of the response columns (columns 2-82 in your example) and click

Y, Response. Click the column with the model formula (column 1 in your example) and clickX, Predictor Formula, . Then clickOK.

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

Re: Script? Applying non-linear model column formula to multiple columns

I figured it out!

Thank you!

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

Re: Script? Applying non-linear model column formula to multiple columns

it errors out at this step

parm[f,0] = Transpose( Report( nl fit )["Parameter Estimates"][NumberColBox(1)] << Get As Matrix );