[R-sig-ME] lmer (lme4) predictions and confidence interval, help with existing code

Ben Bolker bbolker at gmail.com
Sun Sep 8 23:49:43 CEST 2013


Ron Stone <ronstone1980 at ...> writes:

> Dear all,

 [snip]
 
> I have the following model:
> 
> lmerfit1<-(Speed~BodyMass+(1|ID)+(1|Species))
> 
> In the code below provided by http://glmm.wikidot.com/faq it is stated that
> complex models must be adapted ("tvar1 <- pvar1+VarCorr(fm1)$ID[1]## must
> be adapted for more complex models"). I have two random effects, and I
> wonder if I have modified the code correctly? See below, in orange text.
> 
> library(lme4)
> library(ggplot2) # Plotting
> fm1 <- lmer(
>     formula = Speed ~ BodyMass + (1|ID)
> +(1|Species), data = Flight)
> newdat <- expand.grid(
> BodyMass = seq(from = 0, to = 20, by = 1), distance = 0
> )
> mm <- model.matrix(terms(fm1),newdat)
> newdat$Speed <- mm %*% fixef(fm1)
> pvar1 <- diag(mm %*% tcrossprod(vcov(fm1),mm))
> tvar1 <- pvar1+VarCorr(fm1)$ID[1] +  VarCorr(fm1)$Species[1]  ## must be
> adapted for more complex models
> 

  Since you just have two independent intercept effects, it does
seem that just adding the two RE variances is appropriate. Vector-valued
random effects or random effects on slopes (rather than intercepts)
is where things would get trickier.  (There's probably a closed-form
solution based on VarCorr and Z, but I haven't thought about it.)



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