[R] less than full rank contrast methods

Gabor Grothendieck ggrothendieck at gmail.com
Tue Dec 7 15:33:04 CET 2010

On Tue, Dec 7, 2010 at 7:54 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> 'On Tue, Dec 7, 2010 at 5:19 AM, mxkuhn <mxkuhn at gmail.com> wrote:
>> Greg and Frank,
>> Thanks for the replies. I didn't express myself very well; I'm not interest in the model fitting aspect. I'd just like to get the full set of dummy variables (optimally from model.matrix)
> Try this:
> levels(when$time) <- c("morning", "afternoon", "night")
> levels(when$day) <- c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
> contr.dummy <- function(n, ...) diag(n)
> mm <- suppressWarnings(model.matrix(~ day + time, when))
> mm[is.na(mm)] <- 1
> mm
> You might also want to set the levels of your factors first so that it
> includes levels that are not in the data and so that the levels are
> sorted in an order other than alphabetical:

The levels(when$day) lines should be:

levels(when$day) <- c("Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday")

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

More information about the R-help mailing list