# NOT RUN {
fit <- brm(count ~ zAge + zBase * Trt + (1 | patient),
data = epilepsy, family = poisson())
## plot all marginal effects
plot(marginal_effects(fit), ask = FALSE)
## change colours to grey scale
library(ggplot2)
me <- marginal_effects(fit, "zBase:Trt")
plot(me, plot = FALSE)[[1]] +
scale_color_grey() +
scale_fill_grey()
## only plot the marginal interaction effect of 'zBase:Trt'
## for different values for 'zAge'
conditions <- data.frame(zAge = c(-1, 0, 1))
plot(marginal_effects(fit, effects = "zBase:Trt",
conditions = conditions))
## also incorporate random effects variance over patients
## also add data points and a rug representation of predictor values
plot(marginal_effects(fit, effects = "zBase:Trt",
conditions = conditions, re_formula = NULL),
points = TRUE, rug = TRUE)
## change handling of two-way interactions
int_conditions <- list(
zBase = setNames(c(-2, 1, 0), c("b", "c", "a"))
)
marginal_effects(fit, effects = "Trt:zBase",
int_conditions = int_conditions)
marginal_effects(fit, effects = "Trt:zBase",
int_conditions = list(zBase = quantile))
## fit a model to illustrate how to plot 3-way interactions
fit3way <- brm(count ~ zAge * zBase * Trt, data = epilepsy)
conditions <- make_conditions(fit3way, "zAge")
marginal_effects(
fit3way, "zBase:Trt", conditions = conditions
)
## only include points close to the specified values of zAge
me <- marginal_effects(
fit3way, "zBase:Trt", conditions = conditions,
select_points = 0.1
)
plot(me, points = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab