I am trying to write a script that would open a new column for the new parameter estimates.
After running the Nonlinear fit I get the estimates and errors. I then keep only the data tables of interest and try to somehow get the values of interest to be used in a new column with the same model formula. The idea would be to specify the model parameters based on the estimates.
I need some help as I do not know if this is the right way of doing it or if I need to use other functions. The script below may be a bit complicated to follow but that is probably because I have almost non experience in programming. The script obviously works up
@Mark_Bailey wrote:
I am teaching now so I am not free to check but Nonlinear might save the formula with the different sets of parameters for you. The Match() function is useful here. You match on group and replicate the model for each result but apply the unique parameter estimates for each group. It becomes a branching of sorts. Like a CASE statement in some languages.
until the part in BOLD:
col9 = New Column("Model");
col9<< set formula (Parameter({Y1_Y1_0 = 0.2, K1_K1_0 = 0.01, P1_P1_0 = 0.004, Y2_Y2_0 = 0.15, K2_K2_0 = 0.06, P2_P2_0 = 0.3}, If(:Days>0, (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)))),0)));
col10=newcolumn("Err");
col10<< set Formula((:Average - :Model) ^ 2);
col10<<Evalformula;
col10<<Get formula;
obj = Nonlinear(Y( :Average ), X( :Model ), Loss( :Err ), Iteration Limit( 5000 ), By( :Sample ));
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");
Names Default To Here( 1 );
DontClose = {"dt4", "NonLin Fit Errors", "NonLin Fit Estimates"}; // Example names of tables you want to leave
// Loop backwards through the list, so the table numbers do not change
For( i = N Table(), i >= 0, i--,
If( Contains( DontClose, Data Table( i ) << get name ),
Continue(),
Close( Data Table( i ), "No Save" )
)
);
dt = Data Table("NonLin Fit Estimates");
dt2<<column("Estimates")<<values({Y1_Y1_0, K1_K1_0, P1_P1_0, Y2_Y2_0, K2_K2_0, P2_P2_0}, By(:Sample));
myList=:Estimates<<get values
dt0 = Data Table ("dt4");
dt0<< New Column("Fitted Model By Sample");
col11="Fitted Model By Sample";
col11 << set formula (Parameter({Y1_Y1_0, K1_K1_0, P1_P1_0, Y2_Y2_0, K2_K2_0, P2_P2_0}, If(:Days>0, (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)))),0), Set Property("Predicting", {:Average, Creator("Nonlinear")}), By (:Sample)));
For each Row(col11= set formula (Match("Parameter", "Estimates")));
col11<<Evalformula;
col11<<Get formula;
Any suggestions?