lm(stats)
lm()所属R语言包:stats
Fitting Linear Models
线性模型的拟合
译者:生物统计家园网 机器人LoveR
描述----------Description----------
lm is used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance (although aov may provide a more convenient interface for these).
lm是用来满足线性模型。它可以用来进行回归,单地层分析,方差和协方差分析(虽然aov可能为这些服务提供更方便的接口)。
用法----------Usage----------
lm(formula, data, subset, weights, na.action,
method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE,
singular.ok = TRUE, contrasts = NULL, offset, ...)
参数----------Arguments----------
参数:formula
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under "Details".
类对象"formula"(或一个可以强制这一类):将装有模型的一个象征性的描述。在“详细信息”型号规格的细节。
参数:data
an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.
一个可选的数据框,列表或环境(as.data.frame到一个数据框或对象强制转换)包含在模型中的变量。如果没有找到data,environment(formula),通常是从哪个lm被称为环境变量。
参数:subset
an optional vector specifying a subset of observations to be used in the fitting process.
一个可选的向量指定要在装修过程中使用的观测的子集。
参数:weights
an optional vector of weights to be used in the fitting process. Should be NULL or a numeric vector. If non-NULL, weighted least squares is used with weights weights (that is, minimizing sum(w*e^2)); otherwise ordinary least squares is used. See also "Details",
在装修过程中要使用一个可选的权重向量。应该是NULL或数字向量。如果非NULL,加权最小二乘配重使用weights(是,最大限度地减少sum(w*e^2)),否则普通最小二乘使用。另见“详细资料”,
参数: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. Another possible value is NULL, no action. Value na.exclude can be useful.
一个函数,它表示数据时,包含NA的,应该发生什么。默认设置na.actionoptions设置,是na.fail如果没有设置。工厂新鲜的默认是na.omit。另一种可能的值是NULL,没有行动。值na.exclude可能是有用的。
参数:method
the method to be used; for fitting, currently only method = "qr" is supported; method = "model.frame" returns the model frame (the same as with model = TRUE, see below).
要使用的方法;进行拟合,目前只有method = "qr"支持method = "model.frame"返回的模型框架(model = TRUE,见下文相同)。
参数:model, x, y, qr
logicals. If TRUE the corresponding components of the fit (the model frame, the model matrix, the response, the QR decomposition) are returned.
逻辑值。如果TRUE返回合适的模型框架,模型矩阵,响应,QR分解的相应部件。
参数:singular.ok
logical. If FALSE (the default in S but not in R) a singular fit is an error.
逻辑。如果FALSE(S中的默认,但不是在R)奇异适合是一个错误。
参数:contrasts
an optional list. See the contrasts.arg of model.matrix.default.
可选列表。参见contrasts.argmodel.matrix.default。
参数:offset
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be NULL or a numeric vector of length equal to the number of cases. One or more offset terms can be included in the formula instead or as well, and if more than one are specified their sum is used. See model.offset.
这可以被用来指定一个先验已知的组件包括在装修过程中的线性预测。这应该是NULL或数字矢量的长度相等的情况数目。一个或多个offset条款可以包括在公式代替,以及,如果超过指定使用它们的总和。看到model.offset。
参数:...
additional arguments to be passed to the low level regression fitting functions (see below).
额外的参数被传递到低的水平回归拟合函数(见下文)。
Details
详情----------Details----------
Models for lm are specified symbolically. A typical model has the form response ~ terms where response is the (numeric) response vector and terms is a series of terms which specifies a linear predictor for response. A terms specification of the form first + second indicates all the terms in first together with all the terms in second with duplicates removed. A specification of the form first:second indicates the set of terms obtained by taking the interactions of all terms in first with all terms in second. The specification first*second indicates the cross of first and second. This is the same as first + second + first:second.
lm模型指定的象征。一个典型的模型的形式response ~ terms其中response(数字)的响应向量和terms是指定response的线性预测一系列的条款。一个条款规范的形式first + second表示firstsecond重复删除的所有条款的所有条款。一个规范的形式first:second表示的条款集first与second所有条款所有条款的相互作用获得。规范first*second表示first和second交叉。这是相同的first + second + first:second。
If the formula includes an offset, this is evaluated and subtracted from the response.
如果公式中包含一个offset,这是评估和减去从响应。
If response is a matrix a linear model is fitted separately by least-squares to each column of the matrix.
response如果是一个线性模型最小二乘矩阵的每一列分别装有矩阵。
See model.matrix for some further details. The terms in the formula will be re-ordered so that main effects come first, followed by the interactions, all second-order, all third-order and so on: to avoid this pass a terms object as the formula (see aov and demo(glm.vr) for an example).
看到model.matrix一些进一步的细节。公式中的条款将重新排列,使主效应放在第一位,其次,所有二阶的相互作用,所有三阶等terms公式为对象,以避免这一关(看到aov和一个例子demo(glm.vr))。
A formula has an implied intercept term. To remove this use either y ~ x - 1 or y ~ 0 + x. See formula for more details of allowed formulae.
公式有一个隐含的截距项。要删除此使用或者y ~ x - 1或y ~ 0 + x。看到formula允许的公式的更多细节。
Non-NULL weights can be used to indicate that different observations have different variances (with the values in weights being inversely proportional to the variances); or equivalently, when the elements of weights are positive integers w_i, that each response y_i is the mean of w_i unit-weight observations (including the case that there are w_i observations equal to y_i and the data have been summarized).
非NULLweights可以用来表示不同的意见,有不同的差异(weights是成反比的差异值),或等价地,当<元素X>是正整数weights,每个响应w_iy_i单位重量的意见(包括有w_i<意见平等的情况下的平均x>和数据已总结)。
lm calls the lower level functions lm.fit, etc, see below, for the actual numerical computations. For programming only, you may consider doing likewise.
lm呼吁较低层次的功能lm.fit等,见下文实际的数值计算。仅用于编程,你可以考虑做同样。
All of weights, subset and offset are evaluated in the same way as variables in formula, that is first in data and then in the environment of formula.
所有weights,subset和offset被评为formula变量以同样的方式,即先在data然后在环境formula。
值----------Value----------
lm returns an object of class "lm" or for multiple responses of class c("mlm", "lm").
lm返回一个对象class"lm"类c("mlm", "lm")多个响应。
The functions summary and anova are used to obtain and print a summary and analysis of variance table of the results. The generic accessor functions coefficients, effects, fitted.values and residuals extract various useful features of the value returned by lm.
职能summary和anova被用来获取和打印的总结和方差分析结果表。通用存取功能coefficients,effects,fitted.values和residuals由lm返回的值中提取各种有用的功能。
An object of class "lm" is a list containing at least the following components:
"lm"类的对象是一个列表,至少包含以下组件:
参数:coefficients
a named vector of coefficients
命名为向量的系数
参数:residuals
the residuals, that is response minus fitted values.
残差,是响应减去拟合值。
参数:fitted.values
the fitted mean values.
拟合的平均值。
参数:rank
the numeric rank of the fitted linear model.
拟合线性模型的数字排名。
参数:weights
(only for weighted fits) the specified weights.
(加权配合)指定的重量。
参数:df.residual
the residual degrees of freedom.
自由的剩余度。
参数:call
the matched call.
匹配的呼叫。
参数:terms
the terms object used.
terms对象使用。
参数:contrasts
(only where relevant) the contrasts used.
(只在相关)的对比。
参数:xlevels
(only where relevant) a record of the levels of the factors used in fitting.
(只有在有关)创纪录的水平在装修中使用的因素。
参数:offset
the offset used (missing if none were used).
偏移(失踪,如果没有被使用)。
参数:y
if requested, the response used.
如果需要,使用的响应。
参数:x
if requested, the model matrix used.
如果要求,使用的模型矩阵。
参数:model
if requested (the default), the model frame used.
如果请求(默认),使用的模型框架。
参数:na.action
(where relevant) information returned by model.frame on the special handling of NAs.
返回的信息(如有关)model.frameNA的特殊处理。
In addition, non-null fits will have components assign, effects and (unless not requested) qr relating to the linear fit, for use by extractor functions such as summary and effects.
此外,非空配合,将有组件assign,effects“(除非不要求)qr有关线性拟合提取功能,如summary使用, effects。
利用时间序列----------Using time series----------
Considerable care is needed when using lm with time series.
使用lm时间序列时,需要相当谨慎。
Unless na.action = NULL, the time series attributes are stripped from the variables before the regression is done. (This is necessary as omitting NAs would invalidate the time series attributes, and if NAs are omitted in the middle of the series the result would no longer be a regular time series.)
除非na.action = NULL,时间序列属性剥离变量回归前完成。 (这是省略必要NA的失效时间序列属性,如果NA的结果将不再是一个固定的时间序列的一系列中间省略)。
Even if the time series attributes are retained, they are not used to line up series, so that the time shift of a lagged or differenced regressor would be ignored. It is good practice to prepare a data argument by ts.intersect(..., dframe = TRUE), then apply a suitable na.action to that data frame and call lm with na.action = NULL so that residuals and fitted values are time series.
即使保留时间序列的属性,他们没有排队系列,这样的时间滞后或差的回归量移将被忽略。准备datats.intersect(..., dframe = TRUE)参数,它是很好的做法,然后申请一个合适的na.action到该数据框,并调用lmna.action = NULL这样的残差拟合值时间序列。
注意----------Note----------
Offsets specified by offset will not be included in predictions by predict.lm, whereas those specified by an offset term in the formula will be.
offset指定偏移不会被列入predict.lm,而那些公式抵消长期指定将在预测。
作者(S)----------Author(s)----------
The design was inspired by the S function of the same name described
in Chambers (1992). The implementation of model formula by Ross Ihaka
was based on Wilkinson & Rogers (1973).
参考文献----------References----------
Linear models. Chapter 4 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Symbolic descriptions of factorial models for analysis of variance. Applied Statistics, 22, 392–9.
参见----------See Also----------
summary.lm for summaries and anova.lm for the ANOVA table; aov for a different interface.
summary.lm摘要anova.lmANOVA表;aov不同的接口。
The generic functions coef, effects, residuals, fitted, vcov.
通用功能coef,effects,residuals,fitted,vcov。
predict.lm (via predict) for prediction, including confidence and prediction intervals; confint for confidence intervals of parameters.
predict.lm(通过predict)预测,包括信心和预测区间;confint参数的置信区间。
lm.influence for regression diagnostics, and glm for generalized linear models.
lm.influence回归诊断,glm广义线性模型。
The underlying low level functions, lm.fit for plain, and lm.wfit for weighted regression fitting.
底层的低级别的功能,lm.fit纯lm.wfit加权回归拟合。
More lm() examples are available e.g., in anscombe, attitude, freeny, LifeCycleSavings, longley, stackloss, swiss.
lm()例子是可用的,例如,在anscombe,attitude,freeny,LifeCycleSavings,longley,stackloss,swiss。
biglm in package biglm for an alternative way to fit linear models to large datasets (especially those with many cases).
biglm包biglm另一种方式,以适应大型数据集(尤其是那些许多情况下)的线性模型。
举例----------Examples----------
require(graphics)
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".[#吕秀莲多布森(1990)“广义线性模型简介”。]
## Page 9: Plant Weight Data.[#9:植物重量数据。]
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
lm.D90 <- lm(weight ~ group - 1) # omitting intercept[省略拦截]
anova(lm.D9)
summary(lm.D90)
opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
plot(lm.D9, las = 1) # Residuals, Fitted, ...[残值,合身,...]
par(opar)
### less simple examples in "See Also" above[#那么简单的例子,在“请参阅”以上]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|