[R] model.matrix for non-hierarchical models

Lukas Meier meier at stat.math.ethz.ch
Fri Nov 4 15:09:36 CET 2005


Dear R-users,

Using the function model.matrix I noticed the following
behaviour (example below): Using the formula "~ a + a:b" will
give a matrix of the same dimension as using "~ a * b". In the
first case there are additional columns for the interaction (to
compensate for the missing main-effect).

dd <- data.frame(a = gl(3,4), b = gl(4,1,12))
model.matrix(~ a*b, dd, contrasts = list(a="contr.sum", 
             b="contr.sum"))
model.matrix(~ a + a:b, dd, contrasts = list(a="contr.sum", 
             b="contr.sum"))

Is there any way to get the design matrix corresponding to "~ a
+ a:b" or do I have to do this manually?

Thanks for your help,

Lukas Meier




More information about the R-help mailing list