From ggrothendieck at gmail.com  Sat Feb  9 04:54:07 2008
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 8 Feb 2008 22:54:07 -0500
Subject: [Rd] lm with factors for which only one level occurs
Message-ID: <971536df0802081954o6725fc7bk8fa392b88da3fbba@mail.gmail.com>

Consider the following:

> lm(conc ~ Type, CO2, subset = Plant == "Quebec")
Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
  contrasts can be applied only to factors with 2 or more levels

Here Type is a factor for which only one level occurs
within the "Quebec" subset.   This is something that
one would think would be possible to handle in lm.  (Note
that singular.ok = TRUE is the default.)

I came across this when automatically performing lm's
on the levels of a conditioning variable, such as Plant in the above
example, and found I had to unexpectedly special case situations
like the above.

lmList() in lme4 is likely adversely affected by this as well.



[Rd] lm with factors for which only one level occurs
Gabor Grothendieck