[R] less than full rank contrast methods

Greg Snow Greg.Snow at imail.org
Mon Dec 6 19:32:05 CET 2010


Have you tried setting singular.ok=TRUE in the call to lm?  This will start with the full set of contrasts, but only fit those that it is able to.

Otherwise you can set specific contrasts or subsets using the C (note case) or contrasts functions.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Max Kuhn
> Sent: Monday, December 06, 2010 8:35 AM
> To: r-help at r-project.org
> Subject: [R] less than full rank contrast methods
> 
> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list