[R-sig-ME] Summarizing the fitted model takes more RAM than

Gabor Grothendieck ggrothendieck at gmail.com
Mon Dec 15 17:46:42 CET 2008

On Mon, Dec 15, 2008 at 11:35 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
> On Mon, Dec 15, 2008 at 10:16 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> Note that the fitted method in lme had a level= argument that is no
>> longer available in lmer presumably because lmer does not assume
>> a hierarchy -- but do we have or will we have an easy way to get the
>> same effect as fitted(..., level=) in lmer?
> One would need to define such a method carefully.  If the factors
> defining random effects form a strictly nested sequence then there is
> an interpretation of level.  If you do not have a strictly nested
> sequence then I can only make sense of having all the random effects
> defining fitted values (which is what the method for fitted returns
> now) or having none of them.  The second is using the fixed-effects
> coefficients only.
>> library(nlme)
>> # example from plot.lme
>> fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)
>> fit0 <- fitted(fm1, level = 0)
>> fit1 <- fitted(fm1, level = 1)
>> (Maybe this is a bad example since its actually not so hard:
>>   fitted(lmer(distance ~ age + (age|Subject), Orthodont))
>> gives level 1 and
>>  fitted(lm(distance ~ age, Orthodont))
>> gives level 0 but even here it involved the complexity of using different
>> approaches to get them whereas with lme one could do it in a
>> unified manner.)
> I don't know if fitted(lm(distance ~ age, Orthodont)) produces the

> desired result. Removing the random effects from the prediction is not
> always the same as removing the random effects from the fit.  I would
> get the fitted values for the fixed effects only using
> as.vector(model.matrix(fm1) %*% fixef(fm1))

They do seem to be the same here:

> all.equal(fitted(fm1, level = 0), fitted(lm(distance ~ age, Orthodont)), check.attributes = FALSE)
[1] TRUE

but your idea is better since it seems more general allowing at least
fixed vs. all effects which in many cases many be sufficient.  Some
easy way of specifying just the fixed effects might be nice as arg to fitted.

By the way, one other annoyance is that one cannot write:

# fixed effects only
lmer(distance ~ age, Orthodont)

which would be nice when comparing models so that one stays in the same
function, lmer, rather than switching from lmer to lm when the model changes
slightly, and so one is sure that the various outputs are in consistent forms.

>> On Mon, Dec 15, 2008 at 10:19 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
>>> I believe you are using the terminology of multilevel modeling where
>>> one characterizes factors as being at the first level, the second
>>> level, etc.  One can fit multilevel models using lmer but one can also

More information about the R-sig-mixed-models mailing list