add_probs.lmerMod: Response Probabilities for Linear Mixed Models

Description Usage Arguments Details Value See Also Examples

View source: R/add_probs_lmer.R

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

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

Arguments

df

A 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 data frame.

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, df. Otherwise, Pr(Y|x > q) is calculated.

type

A string, either "parametric" 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 = "boot", nSims will determine the number of bootstrap simulations to perform.

log_response

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

...

Additional arguments.

Details

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

Value

A dataframe, df, with predictions and probabilities attached.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

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

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