2

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?

Updates:

  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 Answers2

1

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.

Kirsten
  • 469
1

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)
y~x1+x2+x1x2+x3

otherwise anova will still put the interaction term last.

Greg
  • 126