找回密码
 注册
查看: 8339|回复: 0

R语言:nls()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 19:45:08 | 显示全部楼层 |阅读模式
nls(stats)
nls()所属R语言包:stats

                                        Nonlinear Least Squares
                                         非线性最小二乘

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Determine the nonlinear (weighted) least-squares estimates of the parameters of a nonlinear model.
确定非线性(加权)的非线性模型参数的最小二乘估计。


用法----------Usage----------


nls(formula, data, start, control, algorithm,
    trace, subset, weights, na.action, model,
    lower, upper, ...)



参数----------Arguments----------

参数:formula
a nonlinear model formula including variables and parameters.  Will be coerced to a formula if necessary.
非线性模型公式,包括变量和参数。将强制如果有必要的公式。


参数:data
an optional data frame in which to evaluate the variables in formula and weights.  Can also be a list or an environment, but not a matrix.
评估的变量formula和weights可选的数据框。也可以是一个列表或一个环境,而不是一个矩阵。


参数:start
a named list or named numeric vector of starting estimates.  When start is missing, a very cheap guess for start is tried (if algorithm != "plinear").  
一个名为列表或命名开始估计的数值向量。如果当start丢失,start尝试很便宜的猜测(algorithm != "plinear")。


参数:control
an optional list of control settings.  See nls.control for the names of the settable control values and their effect.
控制设置的可选列表。看到nls.control可设定的控制值的名字和他们的作用。


参数:algorithm
character string specifying the algorithm to use. The default algorithm is a Gauss-Newton algorithm.  Other possible values are "plinear" for the Golub-Pereyra algorithm for partially linear least-squares models and "port" for the "nl2sol" algorithm from the Port library – see the references.
字符串指定要使用的算法。默认算法是高斯 - 牛顿算法。其他可能的值是"plinear"部分线性模型和最小二乘的戈卢布-佩雷拉算法为"port"“nl2sol”从港口库的算法 - 引用。


参数:trace
logical value indicating if a trace of the iteration progress should be printed.  Default is FALSE.  If TRUE the residual (weighted) sum-of-squares and the parameter values are printed at the conclusion of each iteration. When the "plinear" algorithm is used, the conditional estimates of the linear parameters are printed after the nonlinear parameters.  When the "port" algorithm is used the objective function value printed is half the residual (weighted) sum-of-squares.
逻辑值指示是否应印有一丝迭代进度。默认FALSE。如果TRUE印在每次迭代结束的残余(加权)的总和的平方和参数值。当"plinear"算法用于印后,有条件的线性参数估计非线性参数。当"port"算法用于印刷的目标函数值是剩余的一半(加权)的总和的平方。


参数:subset
an optional vector specifying a subset of observations to be used in the fitting process.
一个可选的向量指定要在装修过程中使用的观测的子集。


参数:weights
an optional numeric vector of (fixed) weights.  When present, the objective function is weighted least squares.
一个可选的数字矢量(固定)的重量。目前,目标函数加权最小二乘。


参数:na.action
a function which indicates what should happen when the data contain NAs.  The default is set by the na.action setting of options, and is na.fail if that is unset.  The "factory-fresh" default is na.omit.  Value na.exclude can be useful.
一个函数,它表示数据时,包含NA的,应该发生什么。默认设置na.actionoptions设置,是na.fail如果没有设置。工厂新鲜的默认是na.omit。值na.exclude可能是有用的。


参数:model
logical.  If true, the model frame is returned as part of the object. Default is FALSE.
逻辑。如果情况属实,该模型框架为对象的一部分返回。默认FALSE。


参数:lower, upper
vectors of lower and upper bounds, replicated to be as long as start.  If unspecified, all parameters are assumed to be unconstrained.  Bounds can only be used with the "port" algorithm.  They are ignored, with a warning, if given for other algorithms.
上限和下限的向量,复制到start。如果未指定,假定所有参数都可以不受约束。界只能用"port"算法。它们将被忽略,一个警告,如果其他算法。


参数:...
Additional optional arguments.  None are used at present.
额外的可选参数。目前没有使用。


Details

详情----------Details----------

An nls object is a type of fitted model object.  It has methods for the generic functions anova, coef, confint, deviance, df.residual, fitted, formula, logLik, predict, print, profile, residuals, summary, vcov and weights.
nls对象是拟合模型对象的类型。它具有通用功能的方法anova,coef,confint,deviance,df.residual,fitted,formula, logLik,predict,print,profile,residuals,summary,vcov和weights。

Variables in formula (and weights if not missing) are looked for first in data, then the environment of formula and finally along the search path.  Functions in formula are searched for first in the environment of formula and then along the search path.
变量formula(weights如果不缺)第一看着data,则formula终于在搜索路径的环境。搜索功能formula首次在formula然后沿搜索路径环境。

Arguments subset and na.action are supported only when all the variables in the formula taken from data are of the same length: other cases give a warning.
参数subset和na.action支持只有当所有的公式中的变量取自data长度相同的是:其他情况下,给予警告。

Note that the anova method does not check that the models are nested: this cannot easily be done automatically, so use with care.
注意anova方法不检查,该模型是嵌套:这不容易被自动完成,因此请小心使用。


值----------Value----------

A list of
一个列表


参数:m
an nlsModel object incorporating the model.
nlsModel对象纳入模型。


参数:data
the expression that was passed to nls as the data argument.  The actual data values are present in the environment of the m component.
通过nls作为数据参数的表达。 m组件的环境中存在的实际数据值。


参数:call
the matched call with several components, notably algorithm.
与几个组件匹配的电话,尤其是algorithm。


参数:na.action
the "na.action" attribute (if any) of the model frame.
"na.action"属性(如果有的话)的模型框架。


参数:dataClasses
the "dataClasses" attribute (if any) of the "terms" attribute of the model frame.
"dataClasses"属性(如果有的话)"terms"属性的模型框架。


参数:model
if model = TRUE, the model frame.
如果model = TRUE,模型的框架。


参数:weights
if weights is supplied, the weights.
weights如果提供的重量。


参数:convInfo
a list with convergence information.
与收敛的信息列表。


参数:control
the control list used, see the control argument.
控制list,看到control参数。


参数:convergence, message
for an algorithm = "port" fit only, a convergence code (0 for convergence) and message.  To use these is deprecated, as they are available from convInfo now.  
algorithm = "port"只适合收敛代码(0收敛)和消息。要使用这些已过时,因为他们是从convInfo现在。


警告----------Warning----------

Do not use nls on artificial "zero-residual" data.
不使用nls人工“零残留”的数据。

The nls function uses a relative-offset convergence criterion that compares the numerical imprecision at the current parameter estimates to the residual sum-of-squares.  This performs well on data of
nls函数使用相对偏移的收敛准则,剩余平方和比较,在当前的参数估计的数值不精确。这表现良好的数据

(with var(eps) > 0).  It fails to indicate convergence on data of the form
(var(eps) > 0)。它未能表明对表单数据的衔接

because the criterion amounts to comparing two components of the round-off error.  If you wish to test nls on artificial data please add a noise component, as shown in the example below.
因为标准相当于比较两个组件的舍入误差。如果你想测试nls请人工数据添加噪声成分,如在下面的例子所示。

The algorithm = "port" code appears unfinished, and does not even check that the starting value is within the bounds. Use with caution, especially where bounds are supplied.
algorithm = "port"代码出现画完了,甚至不检查,初始值的范围内。谨慎使用,特别是在边界提供。


注意----------Note----------

Setting warnOnly = TRUE in the control argument (see nls.control) returns a non-converged object (since R version 2.5.0) which might be useful for further convergence analysis, but not for inference.
设置warnOnly = TRUEcontrol参数(见nls.control)返回一个非融合的对象(因为R版本2.5.0)作进一步的收敛性分析这可能是有用的,但不是推理。


作者(S)----------Author(s)----------


Douglas M. Bates and Saikat DebRoy



参考文献----------References----------

Nonlinear Regression Analysis and Its Applications, Wiley
Nonlinear models. Chapter 10 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
documentation.

参见----------See Also----------

summary.nls, predict.nls, profile.nls.
summary.nls,predict.nls,profile.nls。


举例----------Examples----------



require(graphics)

DNase1 <- subset(DNase, Run == 1)

## using a selfStart model[#使用自起动模式]
fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1)
summary(fm1DNase1)
## the coefficients only:[#系数只有:]
coef(fm1DNase1)
## including their SE, etc:[#包括东南等:]
coef(summary(fm1DNase1))

## using conditional linearity[#使用条件的线性]
fm2DNase1 <- nls(density ~ 1/(1 + exp((xmid - log(conc))/scal)),
                 data = DNase1,
                 start = list(xmid = 0, scal = 1),
                 algorithm = "plinear")
summary(fm2DNase1)

## without conditional linearity[#没有条件的线性]
fm3DNase1 <- nls(density ~ Asym/(1 + exp((xmid - log(conc))/scal)),
                 data = DNase1,
                 start = list(Asym = 3, xmid = 0, scal = 1))
summary(fm3DNase1)

## using Port's nl2sol algorithm[#使用港口nl2sol算法]
fm4DNase1 <- nls(density ~ Asym/(1 + exp((xmid - log(conc))/scal)),
                 data = DNase1,
                 start = list(Asym = 3, xmid = 0, scal = 1),
                 algorithm = "port")
summary(fm4DNase1)

## weighted nonlinear regression[#加权非线性回归]
Treated <- Puromycin[Puromycin$state == "treated", ]
weighted.MM <- function(resp, conc, Vm, K)
{
    ## Purpose: exactly as white book p. 451 -- RHS for nls()[#目的:完全一样的白色书页。 451  - 右轴(免入息审查)]
    ##  Weighted version of Michaelis-Menten model[#加权版本米氏模型]
    ## ----------------------------------------------------------[#------------------------------------------------- ---------]
    ## Arguments: 'y', 'x' and the two parameters (see book)[#参数:Y,x和两个参数(见书)]
    ## ----------------------------------------------------------[#------------------------------------------------- ---------]
    ## Author: Martin Maechler, Date: 23 Mar 2001[#作者:。马丁Maechler,日期:23日2001年3月]

    pred <- (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))
summary(Pur.wt)

## Passing arguments using a list that can not be coerced to a data.frame[#传递参数使用,不能强迫数据框的列表]
lisTreat <- with(Treated,
                 list(conc1 = conc[1], conc.1 = conc[-1], rate = rate))

weighted.MM1 <- function(resp, conc1, conc.1, Vm, K)
{
     conc <- c(conc1, conc.1)
     pred <- (Vm * conc)/(K + conc)
    (resp - pred) / sqrt(pred)
}
Pur.wt1 <- nls( ~ weighted.MM1(rate, conc1, conc.1, Vm, K),
               data = lisTreat, start = list(Vm = 200, K = 0.1))
stopifnot(all.equal(coef(Pur.wt), coef(Pur.wt1)))

## Chambers and Hastie (1992) Statistical Models in S  (p. 537):[#钱伯斯和哈斯蒂(1992)的统计模型(第537页):]
## If the value of the right side [of formula] 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 parameter.[#响应的长度和每个参数的一列。]

weighted.MM.grad <- function(resp, conc1, conc.1, Vm, K)
{
  conc <- c(conc1, conc.1)

  K.conc <- K+conc
  dy.dV <- conc/K.conc
  dy.dK <- -Vm*dy.dV/K.conc
  pred <- Vm*dy.dV
  pred.5 <- sqrt(pred)
  dev <- (resp - pred) / pred.5
  Ddev <- -0.5*(resp+pred)/(pred.5*pred)
  attr(dev, "gradient") <- Ddev * cbind(Vm = dy.dV, K = dy.dK)
  dev
}

Pur.wt.grad <- nls( ~ weighted.MM.grad(rate, conc1, conc.1, Vm, K),
                   data = lisTreat, start = list(Vm = 200, K = 0.1))

rbind(coef(Pur.wt), coef(Pur.wt1), coef(Pur.wt.grad))

## In this example, there seems no advantage to providing the gradient.[#在这个例子中,似乎也没有优势,提供梯度。]
## In other cases, there might be.[#在其他情况下,有可能。]


## 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:10
y &lt;- 2*x + 3                            # perfect fit[完美契合]
yeps &lt;- y + rnorm(length(y), sd = 0.01) # added noise[添加噪声]
nls(yeps ~ a + b*x, start = list(a = 0.12345, b = 0.54321))
## Not run: [#无法运行:]
## terminates in an error, because convergence cannot be confirmed:[#终止在一个错误,因为不能确定收敛:]
nls(y ~ a + b*x, start = list(a = 0.12345, b = 0.54321))

## End(Not run)[#结束(不运行)]

## the nls() internal cheap guess for starting values can be sufficient:[#免入息审查贷款计划()内部便宜的猜测起始值可以有足够的:]

x <- -(1:100)/10
y <- 100 + 10 * exp(x / 2) + rnorm(x)/10
nlmod <- nls(y ~  Const + A * exp(B * x))

plot(x,y, main = "nls(*), data, true function and fit, n=100")
curve(100 + 10 * exp(x / 2), col=4, add = TRUE)
lines(x, predict(nlmod), col=2)


## The muscle dataset in MASS is from an experiment on muscle[#在大众的肌肉集是从对肌肉的实验]
## contraction on 21 animals.  The observed variables are Strip[#21动物的收缩。观测变量是地带]
## (identifier of muscle), Conc (Cacl concentration) and Length[#(肌肉标识符),浓(氯化钙浓度)和长度]
## (resulting length of muscle section).[#(导致肌节长度)。]
utils::data(muscle, package = "MASS")

## The non linear model considered is[#非线性模型认为是]
##       Length = alpha + beta*exp(-Conc/theta) + error[#长度=阿尔法+β* exp(-Conc/theta)的+错误]
## where theta is constant but alpha and beta may vary with Strip.[theta是恒定的,而是α和β可能与地带的不同而有所差异。]

with(muscle, table(Strip)) # 2,3 or 4 obs per strip[2,3或4个带OBS]

## We first use the plinear algorithm to fit an overall model,[#我们首先使用的plinear的算法,以适应整体模型,]
## ignoring that alpha and beta might vary with Strip.[#忽略α和β可能会有所不同地带。]

musc.1 <- nls(Length ~ cbind(1, exp(-Conc/th)), muscle,
              start = list(th=1), algorithm="plinear")
summary(musc.1)

## Then we use nls' indexing feature for parameters in non-linear[#然后我们使用非线性参数的免入息审查贷款计划“的索引功能]
## models to use the conventional algorithm to fit a model in which[#模型使用传统的算法,以适应模型]
## alpha and beta vary with Strip.  The starting values are provided[#α和β随地带。提供的起始值]
## by the previously fitted model.[#由以前的拟合模型。]
## Note that with indexed parameters, the starting values must be[#需要注意的是索引参数的初始值必须]
## given in a list (with names):[#列表中(名):]
b <- coef(musc.1)
musc.2 <- nls(Length ~ a[Strip] + b[Strip]*exp(-Conc/th),
              muscle,
              start = list(a=rep(b[2],21), b=rep(b[3],21), th=b[1]))
summary(musc.2)


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-25 03:45 , Processed in 0.021047 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表