简体   繁体   中英

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(). 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()? Is the "Residual standard error" showed in summary() the mean of the list of residual standard errors for each observation? 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. It can be retrieved directly using sigma

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

or derived as following (provided none of the coefficients are 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)
## [1] 147.4944

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

The residual standard error is also displayed in the output of 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

The F statistic compares the variability of the fitted values (in its numerator) to the variability of the residuals (in its denominator). For the the variability of the residuals part it uses the residual standard error, sigma(fm) , squared. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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