
Last chance! 50% off unlimited learning
Sale ends in
This function is one of the methods for add_ci
, and is
called automatically when add_ci
is used on a fit
of
class lmerMod
. It is recommended that one use parametric
confidence intervals when modeling with a random intercept linear
mixed model (i.e. a fit with a formula such as lmer(y ~ x +
(1|group))
). Otherwise, confidence intervals may be simulated (type
= "sim"
) via merTools::predictInterval
or
bootstrapped via lme4::bootMer
.
# S3 method for lmerMod
add_ci(tb, fit, alpha = 0.05, names = NULL,
yhatName = "pred", type = "boot", includeRanef = TRUE, nSims = 200,
...)
A tibble or data frame of new data.
An object of class lmerMod
.
A real number between 0 and 1. Controls the confidence level of the interval estimates.
NULL
or character vector of length two. If
NULL
, confidence bounds automatically will be named by
add_ci
, otherwise, the lower confidence bound will be
named names[1]
and the upper confidence bound will be
named names[2]
.
A string. Name of the predictions vector.
A string. Must be "parametric"
, "boot"
, or
"sim"
. If type = "sim"
, then add_ci
calls
merTools::predictInterval
. If type = "boot"
, then
add_ci
calls lme4::bootMer
.
A logical. Default is TRUE
. Set whether
the predictions and intervals should be made conditional on the
random effects. If FALSE
, random effects will not be
included.
A positive integer. Controls the number of bootstrap
replicates if type = "boot"
, or the number of simulated
draws if type = "sim"
.
Additional arguments.
A tibble, tb
, with predicted values, upper and lower
confidence bounds attached.
Bootstrapped intervals are the slowest to compute, but they are the recommended method when working with any linear mixed models more complicated than the random intercept model.
add_pi.lmerMod
for prediction intervals
of lmerMod
objects, add_probs.lmerMod
for
conditional probabilities of lmerMod
objects, and
add_quantile.lmerMod
for response quantiles of
lmerMod
objects.
# NOT RUN {
# Define the data set
dat <- lme4::sleepstudy
# Fit a linear mixed model (random intercept model)
fit <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)
# Get the fitted values for each observation in dat, and
# append CIs for those fitted values to dat
add_ci(dat, fit, alpha = 0.5, nSims = 100)
# Try another method, and make prediction at the population level
add_ci(dat, fit, alpha = 0.5, type = "parametric", includeRanef = FALSE, nSims = 100)
# Try another method, and add custom names to the confidence bounds
add_ci(dat, fit, alpha = 0.5, type = "sim", names = c("lwr", "upr"), nSims = 1000)
# }
Run the code above in your browser using DataLab