[R-sig-ME] Fixed effects structure

Ben Bolker bbolker at gmail.com
Fri Dec 3 01:16:59 CET 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>> Cliff notes:
>> is: ~ trt + trt:grp
>> versus: ~ trt + grp + trt:grp
>> okay?

  It may not have the effect you want or think -- it
will just reparameterize the effects, not change the df expended.

For example:

> d <- expand.grid(trt=factor(1:5),grp=factor(1:3))
> ncol(model.matrix(~trt+trt:grp,data=d))
[1] 15
> ncol(model.matrix(~trt+grp+trt:grp,data=d))
[1] 15


  For a little more detail, using only two levels of each factor for
clarity:

> d <- expand.grid(trt=factor(1:2),grp=factor(1:2))


> model.matrix(~trt+grp+trt:grp,data=d)
  (Intercept) trt2 grp2 trt2:grp2
1           1    0    0         0
2           1    1    0         0
3           1    0    1         0
4           1    1    1         1
attr(,"assign")
[1] 0 1 2 3
attr(,"contrasts")
attr(,"contrasts")$trt
[1] "contr.treatment"

attr(,"contrasts")$grp
[1] "contr.treatment"


> model.matrix(~trt+trt:grp,data=d)
  (Intercept) trt2 trt1:grp2 trt2:grp2
1           1    0         0         0
2           1    1         0         0
3           1    0         1         0
4           1    1         0         1
attr(,"assign")
[1] 0 1 2 2
attr(,"contrasts")
attr(,"contrasts")$trt
[1] "contr.treatment"

attr(,"contrasts")$grp
[1] "contr.treatment"


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkz4NvsACgkQc5UpGjwzenMtVgCbBY8WINmHfRfPZcgpnEPZxcZe
CQYAnjj+S+WOHTaZOfQo1LspYAnRGHAS
=xIeI
-----END PGP SIGNATURE-----




More information about the R-sig-mixed-models mailing list