Learn R Programming

ciTools (version 0.1.0)

add_pi.lmerMod: Prediction Intervals for Linear Mixed Model Fitted Values

Description

This function is one of the methods in add_pi, and is called automatically when add_pi is used on a fit of class lmerMod.

Usage

# S3 method for lmerMod
add_pi(tb, fit, alpha = 0.05, names = NULL,
  yhatName = "pred", type = "boot", includeRanef = TRUE,
  log_response = FALSE, nSims = 200, ...)

Arguments

tb

A tibble or data frame of new data

fit

An object of class lmerMod.

alpha

A real number between 0 and 1. Controls the confidence level of the interval estimates.

names

NULL or character vector of length two. If NULL, prediction bounds automatically will be named by add_pi, otherwise, the lower prediction bound will be named names[1] and the upper prediction bound will be named names[2].

yhatName

A string. Name of the predictions vector.

type

A string, either "parametric", "sim", or "boot". Determines the method used to calculate the prediction intervals.

includeRanef

A logical. Set whether the predictions and intervals should be conditioned on the random effects. If FALSE, random effects will not be included.

log_response

A logical, indicating if the response is on log scale in the model fit. If TRUE, prediction intervals will be returned on the response scale.

nSims

A positive integer. If type = "sim" or type = "boot", nSims will determine the number of simulated draws to make.

...

Additional arguments.

Value

A tibble, tb, with predicted values, upper and lower prediction bounds attached.

Details

It is recommended that one use parametric prediction intervals when modeling with a random intercept linear mixed model. Otherwise, prediction intervals may be simulated using one of two methods: "sim" indicates that merTools::predictInterval should be used to simulate responses to form prediction intervals, and "boot" indicates that lme4::simulate should be used to simulate predictions for the model fit. The recommended method for determining prediction intervals is parametric bootstrap, which corresponds to type = "boot".

See Also

add_ci.lmerMod for confidence intervals for lmerMod objects, add_probs.lmerMod for conditional probabilities of lmerMod objects, and add_quantile.lmerMod for response quantiles of lmerMod objects.

Examples

Run this code
# NOT RUN {
dat <- lme4::sleepstudy
# Fit a (random intercept) linear mixed model
fit <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)
# Add prediction intervals to the original data using the default
# method, parametric bootstrap. (You may want to use more than 100
# bootstrap replicates in practice).
add_pi(dat, fit, alpha = 0.5, nSims = 100)

# Add prediction intervals to the original data using the
# parametric method. Form prediction intervals at the population
# level (unconditional on the random effects)
add_pi(dat, fit, alpha = 0.5, type = "parametric", includeRanef = FALSE)

# Use a simulation method to form the parametric intervals. Add
# custom names to the prediction bounds. This method is faster
# than the parametric bootstrap, so we can set nSims higher.
add_pi(dat, fit, alpha = 0.5, type = "sim", names = c("lwr", "upr"), nSims = 1000)

# }

Run the code above in your browser using DataLab