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