Learn R Programming

ciTools (version 0.1.0)

add_quantile.lmerMod: Quantiles for the Response of a Linear Mixed Model

Description

This function is one of the methods for add_quantile and is called automatically when add_quantile is applied to an object of class lmerMod.

Usage

# S3 method for lmerMod
add_quantile(tb, fit, p, name = NULL, yhatName = "pred",
  includeRanef = TRUE, type = "boot", nSims = 200, log_response = FALSE,
  ...)

Arguments

tb

A tibble or data frame of new data.

fit

An object of class lm. Predictions are made with this object.

p

A real number between 0 and 1. Determines the probability level of the quantiles.

name

NULL or a string. If NULL, quantiles automatically will be named by add_quantile, otherwise, they will be named name.

yhatName

A string. Determines the name of the column of predictions.

includeRanef

The random effects be included or not? If TRUE, quantiles will be calculated at the "group level". Otherwise, quantiles will be calculated at the "population level", where random effects are set to \(0\).

type

A string. Options are "parametric", "boot", or "sim".

nSims

A positive integer. Set the number of simulations to perform. Only applied when type = "boot" or type = "sim"

log_response

A logical. Set to TRUE if the model is a log-linear mixed model: \(\log(Y) = X\beta + Z\gamma + \epsilon\).

...

Additional arguments.

Value

A tibble, tb, with predicted values and level-p quantiles attached.

Details

add_qauntile.lmerMod may use three different methods for determining quantiles: a parametric method, a simulation method (via merTools::predictInterval), or a parametric bootstrap method (via lme4::simulate). The default and recommended method is parametric bootstrap, which corresponds to setting type = "boot". Only use the parametric method (type = "parametric") if fit is a random intercept model, e.g. fit = lmer(y ~ x + (1|group)).

See Also

add_ci.lmerMod for confidence intervals for lmerMod objects, add_pi.lmerMod for prediction intervals of lmerMod objects, and add_probs.lmerMod for response probabilities of lmerMod objects.

Examples

Run this code
# NOT RUN {
dat <- lme4::sleepstudy

# Fit a random intercept model
fit <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)

# Using the parametric bootstrap: given the model fit, what value
# of reaction time do we expect half of new reaction times to fall
# under?
add_quantile(dat, fit, p = 0.5)

# Using the parametric method:
# as above, but we ignore the random effects.
add_quantile(dat, fit, p = 0.5, type = "parametric", includeRanef = FALSE)

# Using the simulation method: give the vector of quantiles a
# custom name.
add_quantile(dat, fit, p = 0.5, type = "sim", name = "my_quantile", nSims = 1000)

# }

Run the code above in your browser using DataLab