[R] model.matrix for non-hierarchical models
Lukas Meier
meier at stat.math.ethz.ch
Fri Nov 4 17:17:27 CET 2005
Peter Dalgaard writes:
> Lukas Meier <meier at stat.math.ethz.ch> writes:
>
> > 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?
>
> The design matrix corresponding to ~ a + a:b is what you go above. If
> that wasn't what you wanted, perhaps you should tell us what you did
> want.
The problem is that when using "~ a + a:b" a model matrix with
the same number of columns like the matrix for the full model
(~a*b) is created. I'd like that when using "~ a + a:b" I get
the same matrix as the full model up to the deletion of the
columns corresponding to the main-effect of b.
Regards,
Lukas Meier
More information about the R-help
mailing list