[R] Predicted values in lmer modeling
Douglas Bates
bates at stat.wisc.edu
Tue Nov 28 14:53:23 CET 2006
On 11/28/06, Fucikova, Eva <E.Fucikova at nioo.knaw.nl> wrote:
> Dear All,
> I am working with linear mixed-effects models using the lme4 package in
> R. I created a model with the lmer function including some main effects,
> a two-way interaction and a random effect. Now I am searching for a way
> to save the predicted values for this model.
> As far as I can see, there is no command in lme4 to save the predicted
> values (like the predict(model) function in e.g. glm).
If you want the predictions at the observed values of the covariates you can use
fitted(model)
> This gives the following R output: Error in predict(lmer(model)) no
> applicable method for "predict"
> I found the same question in the R forum archives, but no answer.
> Could anybody please give me an advice how to solve this problem?
I haven't written a general method for predict applied to an lmer
object because it is difficult to define what it should do. It is
clear what the predictions based on the fixed effects only should be
and perhaps it is clear what the standard errors of those predictions
are (although that would be a case where my favorite topic of the
degrees of freedom associated with a standard error would rear its
ugly head again).
It is trickier to define the predictions should be when you want to
incorporate the random effects. If you incorporate all the "levels"
of the random effects I think it is clear what the prediction should
be. Defining a standard error for that prediction could be difficult
- I'm not sure. However, I don't know what the answer should be if
you only incorporate some of the random effects. We could define that
unambiguously for lme models because the grouping factors were
required to be nested. Because lmer allows for fully crossed or
partially crossed grouping factors the concept of levels is lost.
That is, there is no strict hierarchy in the grouping factors and we
can't levels to define predictions.
The bottom line is that I won't be able to write a predict method for
lmer objects until I can decide what it should do, what options should
be allowed and what the calling sequence should be.
More information about the R-help
mailing list