[R-sig-ME] lme4 crossed random effects predictions

Philip Harrison pharriso at uwaterloo.ca
Tue Apr 16 16:59:33 CEST 2013


Hi,

I am attempting to reproduce the code from glmm wikidot in order to  
get predictions for a crossed random effects model made in lme4  
http://glmm.wikidot.com/faq

library(lme4)
library(ggplot2) # Plotting
data("Orthodont",package="MEMSS")
fm1 <- lmer(
     formula = distance ~ age*Sex + (age|Subject)
     , data = Orthodont
)
newdat <- expand.grid(
     age=c(8,10,12,14)
     , Sex=c("Male","Female")
     , distance = 0
)
mm <- model.matrix(terms(fm1),newdat)
newdat$distance <- mm %*% fixef(fm1)
pvar1 <- diag(mm %*% tcrossprod(vcov(fm1),mm))
tvar1 <- pvar1+VarCorr(fm1)$Subject[1]  ## must be adapted for more  
complex models

anyone have any ideas on how I might adapt the tvar1 code for a  
partially crossed random effects model effects model. ie a  
(1|subjecti)+(1|subjectj) random effect structure?

I am actually going to use the multcomp package to look at significant  
differences between my categorical fixed effects levels- but i would  
like to get a visualisation of the data with the prediction method.

Thanks for your time

Phil H



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