Nonlinear Least Squares Regression

DESCRIPTION:
Fits a nonlinear regression model via least squares.

USAGE:
nls(formula, data, start=<<see below>>, control=<<see below>>,
    algorithm="default", trace=F)

REQUIRED ARGUMENTS:
formula:
a formula which specifies the nonlinear regression model.
data:
a data frame in which to do the computations. In addition to the usual data variables, the data frame may contain parameters (set, typically, by using the assignment form of parameters or param) that establish initial values for the model parameters.

OPTIONAL ARGUMENTS:
start:
a list or numerical vector. Although it is optional, use of start is recommended for unambiguous specification of the parameters. If start is omitted, the assumption is that any names occurring in formula that are not variables in the data frame are parameters. The list form of start allows the individual parameter names to refer to subsets of the parameters of arbitrary length. If a numeric starting vector is supplied, the named parameters must each be of length 1. In the case of partially linear models (algorithm = "plinear"), only the nonlinear parameters should be supplied.
control:
list of control values to be used in the iteration. See nls.control for the possible control options, their default settings, and their effect on the fitting.
algorithm:
character string stating which algorithm to use. The default algorithm is a Gauss-Newton algorithm. If algorithm is "plinear" the Golub-Pereyra algorithm for partially linear least-squares models is used.
trace:
logical flag or character string naming a tracing function. If trace is FALSE, then no tracing is performed. If trace is TRUE, then trace.nls is used to trace. See trace.nls for the relevant arguments if you want to write your own tracer. Note, however, that the special accumulation technique in trace.nls depends on co-operation with nls that is switched on only by setting the trace argument to TRUE.

VALUE:
an object of class "nls", containing the parameters, residuals, fitted values, and derivatives of the model at the end of the iteration. See nls.object for details.

SIDE EFFECTS:
if trace is TRUE, then the trace.nls function prints the convergence criterion and parameters at each step, and also accumulates the corresponding information in a matrix which is added to the fitted nls object as the component "trace".

DETAILS:
The function tries to estimate parameters to minimize the sum of squared differences between the response and the prediction.

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.


REFERENCES:
Chambers, J. M., and Hastie, T. J. (eds) (1992). Statistical Models in S, Chapter 10, "Nonlinear Models". Pacific Grove, CA.: Wadsworth & Brooks/Cole.

SEE ALSO:
nls.object , nls.control , nlregb , ms , lm , parameter .

EXAMPLES:
# 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)