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

Description Usage Arguments Details Value See Also Examples

View source: R/add_quantile_lmer.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S3 method for class 'lmerMod'
add_quantile(
  df,
  fit,
  p,
  name = NULL,
  yhatName = "pred",
  includeRanef = TRUE,
  type = "boot",
  nSims = 10000,
  log_response = FALSE,
  ...
)

Arguments

df

A 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" or "boot".

nSims

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

log_response

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

...

Additional arguments.

Details

add_qauntile.lmerMod may use one of two different methods for determining quantiles: a parametric method or a parametric bootstrap method (via lme4::simulate). The parametric method is the default. Only use the parametric method (type = "parametric") if fit is a random intercept model, e.g. fit = lmer(y ~ x + (1|group)). If your model of interest is random slope and random intercept, use the parametric bootstrap method (type = "boot").

Value

A dataframe, df, with predicted values and level-p quantiles attached.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
dat <- lme4::sleepstudy

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

# Using the parametric method: 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, includeRanef = FALSE)

ciTools documentation built on Jan. 13, 2021, 7 a.m.