# anova(model1, model2) vs. anova(model2, model1) in R

I'm trying to figure out why there is a difference when I run anova(model1, model2) versus anova(model2, model1) in R. I know which model is nested within the other, but haven't been able to find in the documentation what the difference in syntax is actually doing.

In fact, this is all I've found: "When given a sequence of objects, anova tests the models against one another in the order specified".

• Try help(anova.lm). – chl Dec 28 '12 at 19:02

A few things you should note:

1. anova(model1, model2) and anova(model2, model1) should give you the exact same results in the comparison row (the second one). If you look at the F and the p-values, they will be identical. Even the Sum of Squares will be the same - although it will change sign depending on which model is included first.

2. The only real difference in the table is which model should get its own row on the first line. This just gives the residual degrees of freedom and the residual sum of squares for that model.

3. As hinted at in chl's comment (and made explicit in ?anova.lm), the conventional approach is to have your smallest model on the first line, and your larger models as the subsequent inputs. This is nice because you are looking at additions to what might be your "null" model, and the SS values will be positive (since you are adding larger models, there will be more variation). That being said, you could work in the other direction (start with the largest model, and enter the smaller models subsequently). Compare (based upon the anova.lm example):

fit0 <- lm(sr ~ 1, data = LifeCycleSavings)
fit1 <- update(fit0, . ~ . + pop15)
fit2 <- update(fit1, . ~ . + pop75)
fit3 <- update(fit2, . ~ . + dpi)
fit4 <- update(fit3, . ~ . + ddpi)
anova(fit0, fit1, fit2, fit3, fit4, test = "F")


against

anova(fit4, fit3, fit2, fit1, fit0, test = "F")