Description Usage Arguments Examples
When this package is loaded after loading lme4
, it replaces the predict method for linear mixed-effects models (merMod
objects) with this function. The method provided here adds the argument se.fit
(just like in predict.lm
). It uses the bootstrap, as implemented in bootMer
to estimate standard errors and confidence intervals for the predictions. Also useful in conjunction with the visreg
package, which by default does not plot confidence intervals for merMod
models.
1 2 3 |
object |
An object as returned by |
nsim |
The number of bootstrap replicates. The default is a small number to allow quick testing. A warning is printed when nsim < 100, and it can be set via |
se.fit |
If TRUE, returns standard error (se.fit) and confidence interval (ci.fit) for the predictions, as components of the returned list. |
alpha |
Controls the coverage of the confidence interval. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Fit a linear mixed-effects model
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
# Predictions without standard error (fixed effects only)
predict(fm1, newdata=data.frame(Days=5), re.form=NA)
# Predictions with standard error and confidence interval
# Set number of bootstrap replicates first (you should use a larger number)
options(nbootsim=20)
predict(fm1, newdata=data.frame(Days=5), re.form=NA, se.fit=TRUE)
# Add confidence intervals to visreg
library(visreg)
visreg(fm1, "Days")
# Also works with an overlay plot, using visreg
# First add an artificial group to the sleepstudy data
x <- sort(with(sleepstudy, tapply(Reaction, Subject, mean)))
sleepstudy$Group <- as.factor(ifelse(sleepstudy$Subject %in% names(x[1:9]), "A", "B"))
fm2 <- lmer(Reaction ~ Days*Group + (Days | Subject), sleepstudy)
visreg(fm2, "Days", by="Group", overlay=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.