[R] model.matrix for non-hierarchical models

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Nov 4 17:04:57 CET 2005


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.
 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list