Learn R Programming

ciTools (version 0.1.0)

add_probs.lmerMod: Response Probabilities for Linear Mixed Models

Description

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

Usage

# S3 method for lmerMod
add_probs(tb, fit, q, name = NULL, yhatName = "pred",
  comparison = "

Arguments

tb

A tibble or data frame of new data.

fit

An object of class lmerMod.

q

A real number. A quantile of the conditional response distribution.

name

NULL or a string. If NULL, probabilities automatically will be named by add_probs, otherwise, the probabilities will be named name in the returned tibble.

yhatName

A string. Name of the vector of predictions.

comparison

A character vector of length one. Must be either "<" or ">". If comparison = "<", then \(Pr(Y|x < q)\) is calculated for each x in the new data, tb. Otherwise, \(Pr(Y|x > q)\) is calculated.

type

A string, either "parametric" , "sim", or "boot". Determines the method used to determine the probabilities.

includeRanef

A logical. If TRUE, probabilities and predictions will be calculated at the group level. If FALSE, random effects will not be included, and probabilities will be calculated at the population level.

nSims

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

log_response

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

...

Additional arguments.

Value

A tibble, tb, with predictions and probabilities attached.

Details

It is recommended that one perform a parametric bootstrap to determine these probabilities. To do so, use the option type = "boot".

See Also

add_ci.lmerMod for confidence intervals for lmerMod objects, add_pi.lmerMod for prediction intervals 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 model
fit <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)

# What is the probability that a new reaction time will be less
# than 300? (given the random effects).
add_probs(dat, fit, q = 300)

# As above, but using a different method.
add_probs(dat, fit, q = 300, type = "sim")

# What is the probability that a new reaction time will be greater
# than 300? (ignoring the random effects). 
add_probs(dat, fit, q = 300, type = "parametric", includeRanef = FALSE, comparison = ">")

# }

Run the code above in your browser using DataLab