The following function is designed to work with a logit link.  It can
easily be generalized to work with any link.  The SEs and CIs are
evaluated accounting for all sources of random variation. The plot
may not be much help unless there is just one explanatory variate.

`ciplot` <-
  function(obj=glmm2, data=data.site, xcol=2, nam="litter"){
    cilim <- function(obj, xcol){
      b <- fixef(obj)
      vcov <- summary(obj)@vcov
      X <- unique(model.matrix(obj))
      hat <- X%*%b
      pval <- exp(hat)/(1+exp(hat))   # NB, designed for logit link
      U <- chol(as.matrix(summary(obj)@vcov))
      se <- sqrt(apply(X%*%t(U), 1, function(x)sum(x^2)))
      list(hat=hat, se=se, x=X[,xcol])
           }
    limfo <- cilim(obj, xcol)
    hat <- limfo$hat
    se <- limfo$se
    x <- limfo$x
    upper <- hat+2*se
    lower <- hat-2*se
    ord <- order(x)
    plot(x, hat, yaxt="n", type="l", xlab=nam, ylab="")
    rug(x)
    lines(x[ord], lower[ord])
    lines(x[ord], upper[ord])
    ploc <- c(0.01, 0.05, 0.1, 0.2, 0.5, 0.8, 0.9)
    axis(2, at=log(ploc/(1-ploc)), labels=paste(ploc), las=2)
    }

## Usage
glmm2 <- lmer(rcr ~ litter + (1 | Farm), family=binomial,  
data=data.site)
ciplot(obj=glmm2)

John Maindonald             email: john.maindonald@anu.edu.au
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.


On 8 May 2008, at 8:00 PM, r-help-request@r-project.org wrote:
> From: "May, Roel" <Roel.May@nina.no>
> Date: 8 May 2008 12:23:15 AM
> To: r-help@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]]

