add_ci.glmerMod: Confidence Intervals for Generalized Linear Mixed Model...

Description Usage Arguments Details Value References See Also Examples

View source: R/add_ci_glmer.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S3 method for class 'glmerMod'
add_ci(
  df,
  fit,
  alpha = 0.05,
  names = NULL,
  yhatName = "pred",
  response = TRUE,
  type = "boot",
  includeRanef = TRUE,
  nSims = 500,
  ...
)

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, confidence bounds automatically will be named by add_ci, otherwise, the lower confidence bound will be named names[1] and the upper confidence bound will be named names[2].

yhatName

NULL or a string. Name of the predictions vector. If NULL, the predictions will be named pred.

response

A logical. The default is TRUE. If TRUE, the confidence intervals will be determined for the expected response; if FALSE, confidence intervals will be made on the scale of the linear predictor.

type

A string. If type == "boot" then bootstrap intervals are formed. If type == "parametric" then parametric intervals are formed. Currently only bootstrap intervals are supported.

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 if type = "boot".

...

Additional arguments.

Details

The default and recommended method is bootstrap. The bootstrap method can handle many types of models and we find it to be generally reliable and robust as it is built on the bootMer function from lme4. This function is experimental.

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.

Value

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

References

For general information about GLMMs http://bbolker.github.io/mixedmodels-misc/glmmFAQ.html

See Also

add_pi.glmerMod for prediction intervals of glmerMod objects, add_probs.glmerMod for conditional probabilities of glmerMod objects, and add_quantile.glmerMod for response quantiles of glmerMod objects.

Examples

1
2
3
4
5
6
7
8
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")

## Not run: add_ci(df, fit, names = c("lcb", "ucb"), nSims = 300)

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