Re: [R] predict lmer

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Wed, 07 May 2008 10:13:30 -0700

Sorry, my reply below may be too terse. You'll need to also construct the appropriate design matrix to which to apply the fixef() results to.

If newDat is a data.frame containing **exactly the same named regressor and response columns** as your original vdata dataframe, and if me.fit.of is your fitted lmer object as you have defined it below, then

 model.matrix(terms(me.fit.of),newDat) %*% fixef(me.fit.of)

gives your predictions. Note that while the response column in newDat is obviously unnecessary for prediction (you can fill it with 0's,say), it is nevertheless needed for model.matrix to work. This seems clumsy to me, so there may well be better ways to do this, and **I would appreciate suggestions for improvement.***

Cheers,
Bert

-----Original Message-----

From: bgunter
Sent: Wednesday, May 07, 2008 9:53 AM
To: May, Roel; r-help_at_r-project.org
Subject: RE: [R] predict lmer

?fixef

gets you the coefficient vector, from which you can make your predictions.

-----Original Message-----

From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of May, Roel
Sent: Wednesday, May 07, 2008 7:23 AM
To: r-help_at_r-project.org
Subject: [R] predict lmer

Hi,  

I am using lmer to analyze habitat selection in wolverines using the following model:  

(me.fit.of <-
lmer(USED~1+STEP+ALT+ALT2+relM+relM:ALT+(1|ID)+(1|ID:TRKPT2),data=vdata, control=list(usePQL=TRUE),family=poisson,method="Laplace"))  

Here, the habitat selection is calaculated using a so-called discrete choice model where each used location has a certain number of alternatives which the animal could have chosen. These sets of locations are captured using the TRKPT2 random grouping. However, these sets are also clustered over the different individuals (ID). USED is my binary dependent variable which is 1 for used locations and zero for unused locations. The other are my predictors.  

I would like to predict the model fit at different values of the predictors, but does anyone know whether it is possible to do this? I have looked around at the R-sites and in help but it seems that there doesn't exist a predict function for lmer???  

I hope someone can help me with this; point me to the right functions or tell me to just forget it....  

Thanks in advance!  

Cheers Roel  

Roel May
Norwegian Institute for Nature Research
Tungasletta 2, NO-7089 Trondheim, Norway

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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.

R-help_at_r-project.org 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. Received on Wed 07 May 2008 - 18:26:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 11 May 2008 - 03:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive