Rev 29771 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{nls}\alias{nls}%\alias{anova.nls}%\alias{anovalist.nls}%\alias{coef.nls}%\alias{deviance.nls}%\alias{df.residual.nls}%\alias{fitted.nls}%\alias{logLik.nls}%\alias{print.nls}%\alias{residuals.nls}%\alias{summary.nls}%\alias{print.summary.nls}%\alias{weights.nls}%\alias{vcov.nls}\title{Nonlinear Least Squares}\description{Determine the nonlinear least-squares estimates of the nonlinear modelparameters and return a class \code{nls} object.}\usage{nls(formula, data = parent.frame(), start, control = nls.control(),algorithm = "default", trace = FALSE, subset,weights, na.action, model = FALSE)}\arguments{\item{formula}{a nonlinear model formula including variables and parameters}\item{data}{an optional data frame in which to evaluate the variables in\code{formula}}\item{start}{a named list or named numeric vector of starting estimates}\item{control}{an optional list of control settings. See\code{nls.control} for the names of the settable control values andtheir effect.}\item{algorithm}{character string specifying the algorithm to use.The default algorithm is a Gauss-Newton algorithm. The otheralternative is "plinear", the Golub-Pereyra algorithm forpartially linear least-squares models.}\item{trace}{logical value indicating if a trace of the iterationprogress should be printed. Default is \code{FALSE}. If\code{TRUE} the residual sum-of-squares and the parameter valuesare printed at the conclusion of each iteration. When the\code{"plinear"} algorithm is used, the conditional estimates ofthe linear parameters are printed after the nonlinear parameters.}\item{subset}{an optional vector specifying a subset of observationsto be used in the fitting process.}\item{weights}{an optional numeric vector of (fixed) weights. Whenpresent, the objective function is weighted least squares. \emph{notyet implemented}}\item{na.action}{a function which indicates what should happenwhen the data contain \code{NA}s.}\item{model}{logical. If true, the model frame is returned as part ofthe object.}}\details{\bold{Do not use \code{nls} on artificial "zero-residual" data.}The \code{nls} function uses a relative-offset convergence criterionthat compares the numerical imprecision at the current parameterestimates to the residual sum-of-squares. This performs well on data ofthe form \deqn{y=f(x,\theta)+\epsilon}{y = f(x, theta) + eps} (with\code{var(eps) > 0}). Itfails to indicate convergence on data of the form\deqn{y=f(x,\theta)}{y = f(x, theta)} because the criterion amounts tocomparing two components of the round-off error. If you wish to test\code{nls} on artificial data please add a noise component, as shownin the example below.An \code{nls} object is a type of fitted model object. It has methodsfor the generic functions \code{\link{coef}}, \code{\link{formula}},\code{\link{resid}}, \code{\link{print}}, \code{\link{summary}},\code{\link{AIC}}, \code{\link{fitted}} and \code{\link{vcov}}.Variables in \code{formula} are looked for first in \code{data}, thenthe environment of \code{formula} (added in 1.9.1) and finally alongthe search path. Functions in \code{formula} are searched for firstin the environment of \code{formula} (added in 1.9.1) and then alongthe search path.}\value{A list of\item{m}{an \code{nlsModel} object incorporating the model}\item{data}{the expression that was passed to \code{nls} as the dataargument. The actual data values are present in the environment ofthe \code{m} component.}}\references{Bates, D.M. and Watts, D.G. (1988)\emph{Nonlinear Regression Analysis and Its Applications},WileyBates, D. M. and Chambers, J. M. (1992)\emph{Nonlinear models.}Chapter 10 of \emph{Statistical Models in S}eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.}\author{Douglas M. Bates and Saikat DebRoy}\seealso{\code{\link{nlsModel}}}\examples{data( DNase )DNase1 <- DNase[ DNase$Run == 1, ]## using a selfStart modelfm1DNase1 <- nls( density ~ SSlogis( log(conc), Asym, xmid, scal ), DNase1 )summary( fm1DNase1 )## using conditional linearityfm2DNase1 <- nls( density ~ 1/(1 + exp(( xmid - log(conc) )/scal ) ),data = DNase1,start = list( xmid = 0, scal = 1 ),alg = "plinear", trace = TRUE )summary( fm2DNase1 )## without conditional linearityfm3DNase1 <- nls( density ~ Asym/(1 + exp(( xmid - log(conc) )/scal ) ),data = DNase1,start = list( Asym = 3, xmid = 0, scal = 1 ),trace = TRUE )summary( fm3DNase1 )## weighted nonlinear regressiondata(Puromycin)Treated <- Puromycin[Puromycin$state == "treated", ]weighted.MM <- function(resp, conc, Vm, K){## Purpose: exactly as white book p.451 -- RHS for nls()## Weighted version of Michaelis-Menten model## ------------------------------------------------------------## Arguments: 'y', 'x' and the two parameters (see book)## ------------------------------------------------------------## Author: Martin Maechler, Date: 23 Mar 2001, 18:48pred <- (Vm * conc)/(K + conc)(resp - pred) / sqrt(pred)}Pur.wt <- nls( ~ weighted.MM(rate, conc, Vm, K), data = Treated,start = list(Vm = 200, K = 0.1),trace = TRUE)## The two examples below show that you can fit a model to## artificial data with noise but not to artificial data## without noise.x = 1:10y = x # perfect fityeps = y + rnorm(length(y), sd = 0.01) # added noisenls(yeps ~ a + b*x, start = list(a = 0.12345, b = 0.54321),trace = TRUE)\dontrun{nls(y ~ a + b*x, start = list(a = 0.12345, b = 0.54321),trace = TRUE)}}\keyword{nonlinear}\keyword{regression}\keyword{models}