add_probs.glmerMod: Response Probabilities for Generalized Linear Mixed Model...

Description Usage Arguments Details Value See Also Examples

View source: R/add_probs_glmer.R

Description

This function is one of the methods for add_probs, and is called automatically when add_probs is used on a fit of class glmerMod. Probabilities are approximate and determined via a simulation. This function is experimental.

Usage

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

Arguments

df

A data frame of new data.

fit

An object of class glmerMod.

q

A double. A quantile of the response distribution.

name

NULL or character vector of length one. If NULL, response probabilities automatically will be named by add_probs,

yhatName

NULL or a string. Name of the predictions vector.

comparison

A string. If comparison = "<", then Pr(Y|x < q) is calculated for each observation in df. Default is "<". Must be "<" or ">" for objects of class lm or lmerMod. If fit is a glm or glmerMod, then comparison also may be "<=" , ">=" , or "=".

type

A string. Must be "boot", If type = "boot", then add_ci calls lme4::simulate to calculate the probabilities.

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

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 and estimated probabilities attached.

See Also

add_pi.glmerMod for prediction intervals of glmerMod objects, add_ci.glmerMod for confidence intervals 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")

add_probs(df, fit, name = "p0.6", q = 0.6, nSims = 500)

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