Subscribe Bookmark RSS Feed

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

galactus3000

Contributor

Joined:

Nov 9, 2016

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
galactus3000

Contributor

Joined:

Nov 9, 2016

Solution

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 click X, Predictor Formula, . Then click OK.

 


 

10 REPLIES
markbailey

Staff

Joined:

Jun 23, 2011

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.

galactus3000

Contributor

Joined:

Nov 9, 2016

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.

 

 

markbailey

Staff

Joined:

Jun 23, 2011

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?

galactus3000

Contributor

Joined:

Nov 9, 2016

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.

 

markbailey

Staff

Joined:

Jun 23, 2011

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:

  1. Select Tables > Stack.
  2. Select all the response columns (2-82 in your example) and click Stack.
  3. Make sure that the option to copy the formulas is selected.
  4. Enter a name for the Data column, such as Response.
  5. Enter a name for the Label column, such as Curve.
  6. Click OK.
  7. Select Analyze > Specialized Models > Nonlinear.
  8. Select the predictor column (83 in your example) and click X
  9. Select the model column (1 in your example) and click Y.
  10. Select the Curve column and click By.
  11. Click OK.
  12. Now click Go for each Curve. (This is the tedious part.)
  13. 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.

markbailey

Staff

Joined:

Jun 23, 2011

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.

 

galactus3000

Contributor

Joined:

Nov 9, 2016

Solution

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 click X, Predictor Formula, . Then click OK.

 


 

galactus3000

Contributor

Joined:

Nov 9, 2016

I figured it out!

Thank you!

galactus3000

Contributor

Joined:

Nov 9, 2016

it errors out at this step 

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