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