Learn R Programming

brms (version 0.8.0)

marginal_effects.brmsfit: Display marginal effects of predictors

Description

Display marginal effects of one or more numeric and/or categorical predictors including interaction effects of order 2.

Usage

## S3 method for class 'brmsfit':
marginal_effects(x, effects = NULL, data = NULL,
  re_formula = NA, probs = c(0.025, 0.975), method = c("fitted",
  "predict"), ...)

marginal_effects(x, ...)

## S3 method for class 'brmsMarginalEffects':
plot(x, ncol = NULL, rug = FALSE,
  theme = ggplot2::theme(), ask = TRUE, do_plot = TRUE, ...)

Arguments

x
An object usually of class brmsfit
effects
An optional character vector naming effects (main effects or interactions) for which to compute marginal plots. If NULL (the default), plots for all effects are generated.
data
An optional data.frame containing variable values to marginalize on. Each effect defined in effects will be plotted separately for each row of data. The row names of data will be treated as titles of
re_formula
A formula containing random effects to be considered in the marginal predictions. If NULL, include all random effects; if NA (default), include no random effects.
probs
The quantiles to be used in the computation of credible intervals (defaults to 2.5 and 97.5 percent quantiles)
method
Either "fitted" or "predict". If "fitted", plot marginal predictions of the regression curve. If "predict", plot marginal predictions of the responses.
...
Currently ignored.
ncol
Number of plots to display per column for each effect. If NULL (default), ncol is computed internally based on the number of rows of data.
rug
Logical; indicating whether a rug representation of predictor values should be added via geom_rug. Default is FALSE.
theme
A theme object modifying the appearance of the plots. For some basic themes see ggtheme. Can be defined globally for the curr
ask
logical; indicates if the user is prompted before a new page is plotted. Only used if do_plot is TRUE.
do_plot
logical; indicates if plots should be plotted directly in the active graphic device. Defaults to TRUE.

Value

  • A list of ggplot objects one for each effect.

Examples

Run this code
fit <- brm(count ~ log_Age_c + log_Base4_c * Trt_c + (1 | patient),
           data = epilepsy, family = poisson()) 
## plot all marginal effects
plot(marginal_effects(fit), ask = FALSE)
## only plot the marginal interaction effect of 'log_Base4_c:Trt_c'
## for different values for 'log_Age_c'
mdata <- data.frame(log_Age_c = c(-0.3, 0, 0.3))
plot(marginal_effects(fit, effects = "log_Base4_c:Trt_c", 
                      data = mdata))
## also incorporate random effects variance over patients
## and add a rug representation of predictor values
plot(marginal_effects(fit, effects = "log_Base4_c:Trt_c", 
                      data = mdata, re_formula = NULL), rug = TRUE)

Run the code above in your browser using DataLab