I would like to specify some interaction terms before all main effects in a linear model, but am finding it difficult to do in R, so I am wondering if there is a statistical reason why I shouldn't? The reason for specifying the order in the model is that next I want to use a type I ANOVA to investigate the effects of different variables.

I want this model: y ~ x1 + x2 + x1:x2 + x3 + x1:x3 + x2:x3 + x1:x2:x3

But R insists on this model (no matter what order I type the terms in)*: y ~ x1 + x2 + x3 + x1:x2 + x1:x3 + x2:x3 + x1:x2:x3

The purpose of using the first model and a type I ANOVA would be to account for all variance explained by x1 and x2 before seeing if any remaining variance is explained by x3. Is there any reason why I shouldn't be trying to do this?


  1. Actually it is not that hard to do in R.
  2. Maybe it helps to specify that in my case, x1 and x2 are factors and x3 is continuous.

2 Answers 2


It makes no sense to look at variance for x1 and x2 before x3 as long as you have the 3-factor interaction-term. Changing the order is only relevant if you remove the all interaction-terms with x1, x3 and x2, x3.

  • $\begingroup$ So I should be able to have y ~ x1 + x2 + x1:x2 + x3 + x1:x3 + x2:x3? Or just y ~ x1 + x2 + x1:x2 + x3? $\endgroup$ Jun 17, 2021 at 10:03
  • $\begingroup$ You should be able to do y ~ x1 + x2 + x1:x2 + x3 $\endgroup$
    – Kirsten
    Jun 17, 2021 at 10:34
  • $\begingroup$ Thanks - this is a useful answer, but a little more explanation on why would be helpful to people like me with a rather fuzzy understanding of what goes on behind an ANOVA :) $\endgroup$ Jun 17, 2021 at 14:54

As an addendum to Kirsten's answer, to get this to work in R you need to paste the two vectors together

x1x2 <- paste0(x1,x2)

otherwise anova will still put the interaction term last.

  • $\begingroup$ Turns out you can also use a terms object, see here :) $\endgroup$ Jun 22, 2021 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.