# How to find residual variance of a linear regression model in R?

## Example

x2<-rpois(5000,5)
y2<-rpois(5000,2)
Model2<-lm(y2~x2)
summary(Model2)

## Call

lm(formula = y2 ~ x2)

## Residuals

  Min 1Q Median 3Q Max
-2.0474 -0.9898 0.0030 1.0102 6.0318

## Coefficients

Estimate Std. Error t value Pr(>|t|) (Intercept) 1.953861 0.049840 39.203 <2e-16 *** x2 0.007192 0.009125 0.788 0.431 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error − 1.423 on 4998 degrees of freedom

Multiple R-squared − 0.0001243, Adjusted R-squared: -7.578e-05

F-statistic − 0.6212 on 1 and 4998 DF, p-value: 0.4306

## Example

x4<-rexp(100000,5.5)
y4<-rexp(100000,7.5)
Model4<-lm(y4~x4)
summary(Model4)

## Call

lm(formula = y4 ~ x4)

## Residuals

  Min 1Q Median 3Q Max
-0.13359 -0.09515 -0.04089 0.05144 1.39856

## Coefficients

Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1335960 0.0005972 223.697 <2e-16 *** x4 -0.0010954 0.0023153 -0.473 0.636 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error − 0.1335 on 99998 degrees of freedom

Multiple R-squared − 2.239e-06, Adjusted R-squared : -7.762e-06

F-statistic − 0.2239 on 1 and 99998 DF, p-value: 0.6361

(summary(Model4)$sigma)**2 [1] 0.01781908 ## Example x5<-sample(0:9,25000,replace=TRUE) y5<-sample(91:99,25000,replace=TRUE) Model5<-lm(y5~x5) summary(Model5) ## Call lm(formula = y5 ~ x5) ## Residuals  Min 1Q Median 3Q Max -3.9949 -1.9937 0.0075 2.0093 4.0105 ## Coefficients Estimate Std. Error t value Pr(>|t|) (Intercept) 94.989520 0.030168 3148.693 <2e-16 *** x5 0.000595 0.005641 0.105 0.916 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error − 2.57 on 24998 degrees of freedom Multiple R-squared − 4.45e-07, Adjusted R-squared : -3.956e-05 F-statistic − 0.01112 on 1 and 24998 DF, p-value − 0.916 (summary(Model5)$sigma)**2

[1] 6.604745

Updated on: 14-Oct-2020

5K+ Views