# ANOVA Table for Model In R

I'm trying to figure out how to produce an ANOVA Table in R for a multiple regression model. So far I can only produce it for each regressor, and the Mean Square is calculating as the same as Sum Of Squares.

> anova(nflwin.lm)
Analysis of Variance Table

Response: wins
Df  Sum Sq Mean Sq F value    Pr(>F)
pass_yard     1  76.193  76.193  26.172 3.100e-05 ***
percent_rush  1 139.501 139.501  47.918 3.698e-07 ***
oppo_rush     1  41.400  41.400  14.221 0.0009378 ***
Residuals    24  69.870   2.911
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


I'm trying to produce something like

Analysis of Variance Table

Response: wins
Df  Sum Sq Mean Sq F value    Pr(>F)
Model         3  76.193  76.193  26.172 3.100e-05 ***
Residuals    24  69.870   2.911
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


The anova function will compare two models if one is nested in the other.To get the output you want you can just compare the model you want to estimate to a simpler (nested) model that omits the number of predictors you want to test. So, if I wanted an ANOVA source table that provided the 3df test of x1, x2, and x3, I could have code that looks like this:

modx <- lm(dv ~ x1 + x2 + x3) # Complex model
mod0 <- lm(dv ~ 1) # Intercept only model (omitting all three predictors)
anova(mod0, modx) # List the least complex model first


You will end up with output like this:

Model 1: dv ~ 1
Model 2: dv ~ x1 + x2 + x3
Res.Df    RSS Df Sum of Sq      F    Pr(>F)
1    199 658.17
2    196 433.78  3    224.39 33.796 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


In your output the MS is the same as the SS because you are executing 1 degree of freedom tests rather than multiple df test. MS is calculated by taking the SS divided by the degrees of freedom.

• Thanks! And now I can calculate my model MS by SS divided by Df. – bizzle Apr 12 '15 at 23:57