nls(formula, data, start=<<see below>>, control=<<see below>>, algorithm="default", trace=F)
For the default algorithm the left side of formula is the response to be fitted. The right side should evaluate to a numeric vector of the same length as the response. If the value of the right side has an attribute called "gradient" this should be a matrix with the number of rows equal to the length of the response and one column for each of the parameters. The skeleton of functions to provide this can be formed using deriv.
When there are linear parameters in the model as well as nonlinear parameters, the "plinear" algorithm can be used. The right side of the formula should evaluate to the derivative matrix for the linear parameters, conditional on the nonlinear parameters. This matrix can be given instead as a vector whose length is a multiple of the length of the left side. If the "gradient" attribute is included, it should be an array of dimension the number of observations by number of linear parameters by number of nonlinear parameters.
Caution is advised when calling nls with analytic gradients when only the right side of the operator is supplied. Although it might seem reasonable to define the gradient in this case as if the response were a vector of zeros, this assumption will lead to incorrect results. The assumption made in nls is rather that the analytic gradient is that of the prediction and thus the negative gradient of the residual.
# fitting Michaelis and Menten's original data conc <- c(0.3330, 0.1670, 0.0833, 0.0416, 0.0208, 0.0104, 0.0052) vel <- c(3.636, 3.636, 3.236, 2.666, 2.114, 1.466, 0.866) Micmen <- data.frame(conc=conc, vel=vel) param(Micmen,"K") <- 0.02; param(Micmen,"Vm") <- 3.7 fit <- nls(vel~Vm*conc/(K+conc),Micmen)