[R] less than full rank contrast methods

Max Kuhn mxkuhn at gmail.com
Mon Dec 6 16:34:53 CET 2010


I'd like to make a less than full rank design using dummy variables
for factors. Here is some example data:

when <- data.frame(time = c("afternoon", "night", "afternoon",
                            "morning", "morning", "morning",
                            "morning", "afternoon", "afternoon"),
                   day = c("Monday", "Monday", "Monday",
                           "Wednesday", "Wednesday", "Friday",
                           "Saturday", "Saturday", "Friday"))

For a single factor, I can do this this using

> head(model.matrix(~time -1, data = when))
  timeafternoon timemorning timenight
1             1           0         0
2             0           0         1
3             1           0         0
4             0           1         0
5             0           1         0
6             0           1         0

but this breakdown muti-variable formulas such as "time + day" or
"time + dat + time:day".

I've looked for alternate contrast functions to do this and I haven't
figured out a way to coerce existing functions to get the desired
output. Hopefully I haven't missed anything obvious.

Thanks,

Max

> sessionInfo()
R version 2.11.1 Patched (2010-09-11 r52910)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



More information about the R-help mailing list