简体   繁体   English

R中lm()回归的summary()中的“残留标准误差”是什么意思?

[英]What is the meaning of the "Residual standard error" in summary() for lm() regression in R?

When I use R to run lm() regression, I get the "Residual standard error" from summary().当我使用 R 运行 lm() 回归时,我从 summary() 得到“残留标准误差”。 Why there is just one value of the residual standard error rather than the list of residual standard errors for each observation?为什么每个观测值只有一个残差标准误差值而不是残差标准误差列表?

What is the meaning of this value showed in summary()?在summary()中显示的这个值是什么意思? Is the "Residual standard error" showed in summary() the mean of the list of residual standard errors for each observation? summary() 中显示的“残差标准误差”是每个观测值的残差标准误差列表的平均值吗? Thanks.谢谢。

Residual standard error: 0.8498 on 44848 degrees of freedom
  (7940 observations deleted due to missingness)
Multiple R-squared:  0.4377,    Adjusted R-squared:  0.4375

The residual standard error is a measure of the variability of the residuals from a linear model.残差标准误差是线性模型残差可变性的度量。 Its square is used in the denominator of the F test used to assess the fit of the model.它的平方用于 F 检验的分母,用于评估模型的拟合。 It can be retrieved directly using sigma可以使用sigma直接检索

fm <- lm(mpg ~., mtcars)
sigma(fm)
## [1] 2.650197

or derived as following (provided none of the coefficients are NA):或推导如下(假设没有一个系数是 NA):

sqrt(deviance(fm) / (nobs(fm) - length(coef(fm))))
## [1] 2.650197

Here deviance(fm) gives the sum of squares of the residuals:这里deviance(fm)给出残差的平方和:

deviance(fm)
## [1] 147.4944

sum(resid(fm)^2)  # same
## [1] 147.4944

The residual standard error is also displayed in the output of summary :残差标准误差也显示在summary的输出中:

summary(fm)
# ...snip...
## Residual standard error: 2.65 on 21 degrees of freedom
## Multiple R-squared:  0.869,     Adjusted R-squared:  0.8066 
## F-statistic: 13.93 on 10 and 21 DF,  p-value: 3.793e-07

F value F值

The F statistic compares the variability of the fitted values (in its numerator) to the variability of the residuals (in its denominator). F 统计量将拟合值的变异性(在其分子中)与残差的变异性(在其分母中)进行比较。 For the the variability of the residuals part it uses the residual standard error, sigma(fm) , squared.对于残差部分的可变性,它使用残差标准误差sigma(fm)平方。 For models with an intercept it can be computed as follows.对于具有截距的模型,可以按如下方式计算。

# F value shown in summary

num <- sum( (fitted(fm) - mean(fitted(fm)))^2 ) / (length(coef(fm)) - 1) 
den <- sigma(fm)^2
num / den
# [1] 13.93246

Special Case -- Intercept only model特殊情况——仅拦截模型

In the special case of an intercept only model the residual standard error equals the standard deviation of the residuals but in general these are not equal.在仅截距模型的特殊情况下,残差标准误差等于残差的标准偏差,但通常它们不相等。

# for intercept only model residual standard error equals sd(residuals)

fm0 <- lm(mpg ~ 1, mtcars)
sigma(fm0)
## [1] 6.026948

sd(resid(fm0))
## [1] 6.026948

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM