Consider again a nonlinear regression of the form
. An easy
way to find initial estimates for the parameters is to regress x2y on
x1 and x2 :
fm0 <- lm(x2*y x1 + x2 - 1, data=biochem)
th <- coef(fm0)
To name the parameters and associate them with the biochem is done as follows:
parameters(biochem) <- list(t1=th[1], t2=th[2])
Now to fit the nonlinear regression model:
fm <- nls(y t1*x1/(x2 - t2), data=biochem)
At this point we could use the summary() function and most of the other generics to investigate the model and display information. To extract the coefficients we could now use, for example
th <- coef(fm)
and to make these least squares estimates the new values of the parameters associated with biochem we could simply repeat the step
parameters(biochem) <- list(t1=th[1], t2=th[2])
Note that the function parameters() may either be used as an expression, in which case it extracts the list of parameters from a data frame, or it may be used as the target for an assignment, in which case it accepts a parameter list for a specified data frame. In this respect it is very similar to the attributes() function. There is also a function param() analogous to attr(), which handles one parameter at a time under a character string name.