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). 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? Thank you in advance, Eva Fucikova ******************************************** Msc. Eva Fucikova Netherlands Institute of Ecology (NIOO-KNAW) PO Box 40 6666 ZG Heteren The Netherlands tel.: +31 (0)26 4791248 Email:E.Fucikova@nioo.knaw.nl ******************************************* [[alternative HTML version deleted]]
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.
m3 is a logistic regression model without random effect fitted by glm m5 is a logistic regression model with random effect fitted by lmer why the range for the fitted value for m5 is not between 0 and 1. thanks, Aimin > range(fitted(m3)) [1] 0.1630141 0.9903415 > range(fitted(m5)) [1] -1.515915 4.576576 At 07:53 AM 11/28/2006, Douglas Bates wrote:> fitted(model)
The fitted values for m5 must be logits. On 28/11/06, Aimin Yan <aiminy at iastate.edu> wrote:> m3 is a logistic regression model without random effect fitted by glm > m5 is a logistic regression model with random effect fitted by lmer > why the range for the fitted value for m5 is not between 0 and 1. > thanks, > Aimin > > range(fitted(m3)) > [1] 0.1630141 0.9903415 > > range(fitted(m5)) > [1] -1.515915 4.576576 > > At 07:53 AM 11/28/2006, Douglas Bates wrote: > > fitted(model) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- ================================David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP