Learn R Programming

ciTools (version 0.6.1)

add_pi.glmerMod: Prediction Intervals for Generalized Linear Mixed Model Predictions

Description

This function is one of the methods for add_pi, and is called automatically when add_pi is used on a fit of class glmerMod. This function is experimental.

Usage

# S3 method for glmerMod
add_pi(
  df,
  fit,
  alpha = 0.05,
  names = NULL,
  yhatName = "pred",
  type = "boot",
  includeRanef = TRUE,
  nSims = 10000,
  ...
)

Arguments

df

A data frame of new data.

fit

An object of class glmerMod.

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

NULL or a string. The name of the predictions vector.

type

A string. Must be "boot", If type = "boot", then add_ci calls lme4::bootMer to calculate the confidence intervals.

includeRanef

A logical. Default is TRUE. Set whether the predictions and intervals should be made conditional on the random effects. If FALSE, random effects will not be included.

nSims

A positive integer. Controls the number of bootstrap replicates.

...

Additional arguments.

Value

A dataframe, df, with predicted values, upper and lower prediction bounds attached.

Details

Prediction intervals are approximate and determined by simulation through the simulate function distributed with lme4.

If IncludeRanef is False, random slopes and intercepts are set to 0. Unlike in `lmer` fits, settings random effects to 0 does not mean they are marginalized out. Consider generalized estimating equations if this is desired.

See Also

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

Examples

Run this code
# NOT RUN {
n <- 300
x <- runif(n)
f <- factor(sample(1:5, size = n, replace = TRUE))
y <- rpois(n, lambda = exp(1 - 0.05 * x * as.numeric(f) + 2 * as.numeric(f)))
df <- data.frame(x = x, f = f, y = y)
fit <- lme4::glmer(y ~ (1+x|f), data=df, family = "poisson")

add_pi(df, fit, names = c("LPB", "UPB"), nSims = 500)

# }

Run the code above in your browser using DataLab