[R] less than full rank contrast methods

Gabor Grothendieck ggrothendieck at gmail.com
Tue Dec 7 13:54:46 CET 2010


'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:


etc.


-- 
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