cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
ivomdb
Level III

How to fit a customised Non linear model using multiple parameters

I have a non linear model for which I have created a new column with formula below. The model is described as being similar to a Sigmoidal curve with two defined stages for which I have three parameters characterizing each stage. An initial stage described by K1, Y1 and P1 parameters and a second stage described by K2, Y2 and P2 parameters. Also, for each parameter I have created a new column an atributed an initial value of 0.1 to facilitate the fitting (not in the script below). However, the values can vary widely between samples from 0 to 1.

 

I have a list of samples for which I need to fit the same model and retrieve these parameters values according to the best fit. The best fit I would like to measure based on minimum RMSE or maximum R2. However, I have no idea how to do this. I have created a column for the Loss function which I am calculating as the SSQ between the experimental data (:Production) and the Model (:Model) hoping this would help when fitting the model.

 

col7 = New Column("Model");
col7<< set formula (Parameter({Y1_Y1_0 = 0.001, K1_K1_0 = 0.001, P1_P1_0 = 0.001, Y2_Y2_0 = 0.001, K2_K2_0 = 0.001, P2_P2_0 = 0.001},
Y1_Y1_0 * Exp(-Exp(((K1_K1_0 * Exp()) / Y1_Y1_0) * (P1_P1_0 - :Days))) + Y2_Y2_0 * Exp(-Exp(((K2_K2_0 * Exp()) / Y2_Y2_0) * (P2_P2_0 - :Days)))));
 
col8=newcolumn("Error");
col8<< set Formula(SSQ(:Production - :Model));
col8<<Evalformula;
col8<<Get formula;

 

 

As an example of the resulting script when fitting the Model to one sample

 

Nonlinear(
Y( :Methane Yield ),
X( :Model ),
Loss( :Err ),
Iteration Limit( 1000 ),
Numeric Derivatives Only( 1 ),
Unthreaded( 1 ),
Loss is Neg LogLikelihood( 1 ),
Newton,
Finish,
Where( :Sample == "M301" )
);

 

I am trying to automatize these analyses as for now I have been using Excel Solver.

 

 

 

Could someone provide some feedback on how to run the model fitting automatically through all the samples in the data table and retrieve the parameters for when RSME is minimum (if I am correct when Loss function is minimum) or when R2 is maximum ? 

Would the parameters values in each column be updated automatically?

 

Thanks

Ivo

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: How to fit a customised Non linear model using multiple parameters

Regarding nonlinear modeling, I am only familiar with setting a convergence criterion, an objective.  Many years ago when compute power was weak compared to today, I typically used SAS to create a loop of multiple starting estimates, then compared residual results. So I cannot help with your "best model" request.

 

You did not mention which version of JMP you are using, nor your scripting knowledge. To understand this script you need to know some basic syntax. Below is a  modifictaion of the script from the JMP Scripting Index>Objects>Nonlinear>CopyByGroupScript.

It :

  • creates a "by" column, for your example this would be your :Sample column
  • Assigns  a handle/reference to the report, obj.  Here you would use your script changing Where( :Sample == "M301" ) to By(:Sample)
  • demonstrates how to create a list of results with "get" statements. See JMP Scripting Index>Objects>Nonlinear for availabe messages.
  • Alternately, you can make tables of results.  JMP reports (obj) is a nested list of display boxes. For example, from the GUI if you have a a certain table box for one by group and right click and select Make Combined Data Table, then this JSL is doing the same.  Xpath is a general method to find display boxes. Find is less flexible, but syntactically easier to read. The Xpath statement below returns a handle/reference to each outline box in the obj report that is a solution. Each Solution outline box has 2 table boxes, I know that ny looking at the structure.  All I need is the first occurence ecah of these table boxes to send the message to make a combined data table.

This should give you a place to start.  First run the script below to ensure it runs on your version of JMP then modify. Here is a picture  of a table of estimates for this example script.

image.png      

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Nonlinear Examples/US Population.jmp" );
dt << New Column( "_bycol",
	Character,
	Nominal,
	set values( Repeat( {"A", "B"}, N Rows( dt ) )[1 :: N Rows( dt )] )
);
obj = Nonlinear( Y( :pop ), X( :Name( "X-formula" ) ), Finish(), By( _bycol )) ;
obj << go;
//returns a list of vectors where each vector, contains the parameters estimates
obj << get estimates;

//also see Get SSE, Get Parameter Names, Get CI

//Alternately, make a table

_xx = obj << Xpath("//OutlineBox[@helpKey='Nonlinear Solution']");
//only 2 groups so only 2 are found; each contains two sub tables

fit_dt = (_xx[1]<<Find(TableBox(1))) << Make Combined Data Table;
est_dt = (_xx[1]<<Find(TableBox(2))) << Make Combined Data Table;
fit_dt << set Name("NonLin Fit Errors");
est_dt << set Name("NonLin Fit Estimates");

 

 

  

View solution in original post

Re: How to fit a customised Non linear model using multiple parameters

The default loss function is least squares, so JMP automatically squares the difference between the observed response and the predicted response.

 

I think that your parameter estimates will be highly so it will be difficult to converge. Again, I would resolve the issue using Nonlinear interactively before trying to automated it with a script.

 

You might want to contact JMP Technical Support about this problem. (support@jmp.com)

View solution in original post

9 REPLIES 9
gzmorgan0
Super User (Alumni)

Re: How to fit a customised Non linear model using multiple parameters

Regarding nonlinear modeling, I am only familiar with setting a convergence criterion, an objective.  Many years ago when compute power was weak compared to today, I typically used SAS to create a loop of multiple starting estimates, then compared residual results. So I cannot help with your "best model" request.

 

You did not mention which version of JMP you are using, nor your scripting knowledge. To understand this script you need to know some basic syntax. Below is a  modifictaion of the script from the JMP Scripting Index>Objects>Nonlinear>CopyByGroupScript.

It :

  • creates a "by" column, for your example this would be your :Sample column
  • Assigns  a handle/reference to the report, obj.  Here you would use your script changing Where( :Sample == "M301" ) to By(:Sample)
  • demonstrates how to create a list of results with "get" statements. See JMP Scripting Index>Objects>Nonlinear for availabe messages.
  • Alternately, you can make tables of results.  JMP reports (obj) is a nested list of display boxes. For example, from the GUI if you have a a certain table box for one by group and right click and select Make Combined Data Table, then this JSL is doing the same.  Xpath is a general method to find display boxes. Find is less flexible, but syntactically easier to read. The Xpath statement below returns a handle/reference to each outline box in the obj report that is a solution. Each Solution outline box has 2 table boxes, I know that ny looking at the structure.  All I need is the first occurence ecah of these table boxes to send the message to make a combined data table.

This should give you a place to start.  First run the script below to ensure it runs on your version of JMP then modify. Here is a picture  of a table of estimates for this example script.

image.png      

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Nonlinear Examples/US Population.jmp" );
dt << New Column( "_bycol",
	Character,
	Nominal,
	set values( Repeat( {"A", "B"}, N Rows( dt ) )[1 :: N Rows( dt )] )
);
obj = Nonlinear( Y( :pop ), X( :Name( "X-formula" ) ), Finish(), By( _bycol )) ;
obj << go;
//returns a list of vectors where each vector, contains the parameters estimates
obj << get estimates;

//also see Get SSE, Get Parameter Names, Get CI

//Alternately, make a table

_xx = obj << Xpath("//OutlineBox[@helpKey='Nonlinear Solution']");
//only 2 groups so only 2 are found; each contains two sub tables

fit_dt = (_xx[1]<<Find(TableBox(1))) << Make Combined Data Table;
est_dt = (_xx[1]<<Find(TableBox(2))) << Make Combined Data Table;
fit_dt << set Name("NonLin Fit Errors");
est_dt << set Name("NonLin Fit Estimates");

 

 

  

ivomdb
Level III

Re: How to fit a customised Non linear model using multiple parameters

My experience on JSL is minimal. I have just started unfortunately. I am using JMP14. Thanks for the feedback.

I have modified your script as you suggested (below) and ran it. It does give me the estimates but it does not run the iterations until "infinite" as I think the command :Finish would request. Is that correct? It goes only until 60. Hence, the output fitting is not great and the parameters estimates are to high or negative which means I might need to set parameter constrains

obj = Nonlinear(Y( :Methane Yield ), X( :Model ), Loss( :Err ), Finish(), By( :Sample ));
obj << go;
obj << get estimates;
_xx = obj << Xpath("//OutlineBox[@helpKey='Nonlinear Solution']");
fit_dt = (_xx[1]<<Find(TableBox(1))) << Make Combined Data Table;
est_dt = (_xx[1]<<Find(TableBox(2))) << Make Combined Data Table;
fit_dt << set Name("NonLin Fit Errors");
est_dt << set Name("NonLin Fit Estimates");
/*:

{"NonLin Fit Estimates"}

Re: How to fit a customised Non linear model using multiple parameters

First, the Finish option does not mean go forever. It is the same as clicking the Go button instead of the Step button in the user interface. It goes until one of the stopping rules (criterion) is achieved. The default limit on the number of iterations is 60. You can run again to make Nonlinear work harder to get a good solution. You can also change (relax or strengthen) the other criteria if necessary.

 

Second, the slow convergence might be an indication of poor choices for the starting values. How do you determined those values for your data?

ivomdb
Level III

Re: How to fit a customised Non linear model using multiple parameters

The starting values were used based on the results achieved on Excel Solver for the same data.

It is a bit surprising that JMP does not achieve similar results or that does not achieve good convergence. Also, JMP struggles to run the iterations using the Loss function and eventually crashes. When running it without Loss function it does not achieve any convergence.

Re: How to fit a customised Non linear model using multiple parameters

One more comment: I recommend working with Nonlinear interactively until you determine the best set up. It will probably go faster and easier this way than trying to get the scripting working at the same time. You can then save the script to continue development.

Re: How to fit a customised Non linear model using multiple parameters

Is this the model that you are trying to fit:

 

Capture.PNG

 

The loss function should not use the SSQ() function. The nonliinear platform will combine the loss in each row automatically.

ivomdb
Level III

Re: How to fit a customised Non linear model using multiple parameters

yes that is the model I am using. what function should I use then to specify the Loss function?

Re: How to fit a customised Non linear model using multiple parameters

The default loss function is least squares, so JMP automatically squares the difference between the observed response and the predicted response.

 

I think that your parameter estimates will be highly so it will be difficult to converge. Again, I would resolve the issue using Nonlinear interactively before trying to automated it with a script.

 

You might want to contact JMP Technical Support about this problem. (support@jmp.com)

ivomdb
Level III

Re: How to fit a customised Non linear model using multiple parameters

Thanks.