Solved – how to create an anova table from R output

anovaregression

I need to construct an ANOVA table by hand using this information. i think the total df is 225, but I'm not sure how to find the rest of the values for the table

> summary(lm(homicide~year+fahrenheit))

Call:
lm(formula = homicide ~ year + fahrenheit)

Residuals:
Min      1Q  Median      3Q     Max 
-31.298 -10.185  -0.804   8.423  55.262 

Coefficients:
          Estimate Std. Error t value Pr(>|t|)    
(Intercept) -3922.1684   337.3552 -11.626  < 2e-16 ***
year            1.9844     0.1700  11.670  < 2e-16 ***
fahrenheit      0.8441     0.1798   4.695 4.64e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 14.06 on 225 degrees of freedom
Multiple R-squared:  0.416, Adjusted R-squared:  0.4108 
F-statistic: 80.14 on 2 and 225 DF,  p-value: < 2.2e-16

> vcov(lm(homicide~year+fahrenheit))
          (Intercept)          year    fahrenheit
(Intercept) 113808.511043 -5.733256e+01 -0.9428619539
year           -57.332561  2.891534e-02 -0.0005588921
fahrenheit      -0.942862 -5.588921e-04  0.0323255678

Best Answer

You can get the full ANOVA table using the anova function, like this:

anova(lm(mpg ~ hp + wt, data = mtcars))

The resulting table looks like this:

Analysis of Variance Table

Response: mpg
          Df Sum Sq Mean Sq F value    Pr(>F)    
hp         1 678.37  678.37 100.862 5.987e-11 ***
wt         1 252.63  252.63  37.561 1.120e-06 ***
Residuals 29 195.05    6.73                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The total DF is the sum of the values in the DF column; in your case, that would probably be 227 (one for each predictor variable, 225 for the residuals).

Related Question