Skip to content
Prev 303018 / 398506 Next

Simple question about formulae in R!?

Dear Michael and list,

R in general tries hard to prohibit this behavior (i.e., including an interaction but not the main effect). When removing a main effect and leaving the interaction, the number of parameters is not reduced by one (as would be expected) but stays the same, at least when using model.matrix:

d <- data.frame(A = rep(c("a1", "a2"), each = 50), B = c("b1", "b2"), value = rnorm(10))
ncol(model.matrix(~ A*B, data = d))
#  [1] 4
ncol(model.matrix(~ A*B - A, data = d))
#  [1] 4

I actually don't know understand how R parametrizes the model in the second case, but I am pretty sure someone here might do so and be able to explain.

I have asked a question on how to get around this "limitation" on stackoverflow with helpful answers by Ben Bolker and Joshua Wiley: http://stackoverflow.com/q/11335923/289572
(this functionality is now used in function mixed() in my new package afex for obtaining "type 3" p-values for mixed models)

Cheers,
Henrik

Am 10.08.2012 15:48, schrieb R. Michael Weylandt: