add_ci.lmerMod {ciTools} | R Documentation |
Confidence Intervals for Linear Mixed Model Predictions
Description
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 bootstrapped
via lme4::bootMer
.
Usage
## S3 method for class 'lmerMod'
add_ci(
df,
fit,
alpha = 0.05,
names = NULL,
yhatName = "pred",
type = "boot",
includeRanef = TRUE,
nSims = 500,
...
)
Arguments
df |
A data frame of new data. |
fit |
An object of class |
alpha |
A real number between 0 and 1. Controls the confidence level of the interval estimates. |
names |
|
yhatName |
A string. Name of the predictions vector. |
type |
A string. Must be |
includeRanef |
A logical. Default is |
nSims |
A positive integer. Controls the number of bootstrap
replicates if |
... |
Additional arguments. |
Details
Bootstrapped intervals are slower to compute, but they are the recommended method when working with any linear mixed models more complicated than the random intercept model.
Value
A dataframe, df
, with predicted values, upper and lower
confidence bounds attached.
See Also
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.
Examples
## Not run:
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)
# Try the parametric bootstrap method, and make prediction at the population level
add_ci(dat, fit, alpha = 0.5, type = "boot", includeRanef = FALSE, nSims = 100)
## End(Not run)