# What models does ANOVA compare, when a single model is provided?

According to the documentation of the R function anova(), it compares linear models with variables sequentially added. The following simple test shows, however, that this is not the case:

> x <- ToothGrowth; x$$dose <- as.factor(x$$dose)
> m.0 <- lm(len ~ 1, data=x)
> m.s <- lm(len ~ supp, data=x)
> m.d <- lm(len ~ dose, data=x)
> m.s.d <- lm(len ~ supp + dose, data=x)
> anova(m.s.d)
Df  Sum Sq Mean Sq F value    Pr(>F)
supp       1  205.35  205.35  14.017 0.0004293 ***
dose       2 2426.43 1213.22  82.811 < 2.2e-16 ***
> anova(m.0, m.s)
Res.Df    RSS Df Sum of Sq      F  Pr(>F)
1     59 3452.2
2     58 3246.9  1    205.35 3.6683 0.06039 .

After trying out all possible model combinations, I have figured out that anova() compares for each varaible the full model with the model with this variable omitted:

> # reproduce first row in the above table
> anova(m.d, m.s.d)
Res.Df     RSS Df Sum of Sq      F    Pr(>F)
1     57 1025.78
2     56  820.43  1    205.35 14.017 0.0004293 ***

So far, so good. What I cannot find out, however, is which models anova() compares when an additional interaction term is given:

> m.s.d.sd <- lm(len ~ supp * dose, data=x)
> anova(m.s.d.sd)
Df  Sum Sq Mean Sq F value    Pr(>F)
supp       1  205.35  205.35  15.572 0.0002312 ***
dose       2 2426.43 1213.22  92.000 < 2.2e-16 ***
supp:dose  2  108.32   54.16   4.107 0.0218603 *

I have tried a wide variety of (nested) model combinations, but could not reproduce the first two rows in this table (the last row compares len~supp+dose with len~supp+dose+supp:dose).

Can someone please explain which models are compared in these rows?

anova(), it compares linear models with variables sequentially added

The documentation says:

When given a sequence of objects, ‘anova’ tests the models against one another in the order specified.

What I cannot find out, however, is which models anova() compares when an additional interaction term is given

If you pass a single model object to anova like in your last example anova(m.s.d.sd):

When given a single argument it produces a table which tests whether the model terms are significant

• In this case, the documentation of anova.lm must be asked, which says: "Specifying a single object gives a sequential analysis of variance table for that fit. That is, the reductions in the residual sum of squares as each term of the formula is added in turn are given in as the rows of a table". As my example above shows, this is not how anova.lm behaves, and I would like to know which models are actually compared. Commented Oct 12, 2021 at 10:57