set.seed(123)
sim_data <- data.frame(
x = rnorm(100),
y = rbinom(100, 1, 0.5),
g = sample(letters, 100, replace = TRUE)
)
# Run with defaults
est_vglmer <- vglmer(y ~ x + (x | g), data = sim_data, family = "binomial")
# Simple prediction
predict(est_vglmer, newdata = sim_data)
# Return 10 posterior draws of the linear predictor for each observation.
predict_MAVB(est_vglmer, newdata = sim_data, summary = FALSE, samples = 10)
# Predict with a new level; note this would fail if
# allow_missing_levels = FALSE (the default)
predict(est_vglmer,
newdata = data.frame(g = "AB", x = 0),
allow_missing_levels = TRUE
)
Run the code above in your browser using DataLab