Bayesian Mediation Analysis with Variable Selection
buzzMed is an R package for Bayesian mediation analysis. It provides tools for exploratory Bayesian mediation models with Bayesian variable selection, supporting continuous and binary mediators and outcomes. The package also includes a longitudinal Bayesian mediation model for repeated-measures data.
This package requires JAGS (Just Another Gibbs Sampler) to be installed on your system.
Download JAGS from:
https://mcmc-jags.sourceforge.io/
Install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("olfactorybulb/buzzMed")
library(buzzMed)The package provides four functions for exploratory Bayesian mediation analysis based on the mediator and outcome variable types.
| Function | Mediator | Outcome |
|---|---|---|
buzzEBMcontMcontY() |
Continuous | Continuous |
buzzEBMcontMcatY() |
Continuous | Binary |
buzzEBMcatMcontY() |
Binary | Continuous |
buzzEBMcatMcatY() |
Binary | Binary |
longBMed() fits a Bayesian mediation model for
repeated-measures data with one or more predictors, multiple candidate
mediators, and a continuous outcome.library(buzzMed)
# Create toy data
my_data <- data.frame(
MyPredictor = rnorm(30),
MyMediator1 = rnorm(30),
MyMediator2 = rnorm(30),
MyOutcome = rnorm(30)
)
# Fit the model
fit <- buzzEBMcontMcontY(
model = "MyOutcome ~ MyPredictor | MyMediator1 + MyMediator2",
dataset = my_data
)library(buzzMed)
# Load the example longitudinal dataset
data(sublongspikes)
# Fit the longitudinal Bayesian mediation model
# For model specification, slice 1 is the predictor, slices 2--20 are candidate mediators, and slice 21 is the outcome.
# n.burnin and n.iter are optional arguments
results <- longBMed(
model = "21 ~ 1 | 2:20",
data = sublongspikes,
n.burnin = 100,
n.iter = 500
)
summary(results)singlespikes: Cross-sectional mediation dataset
containing one predictor, nineteen candidate mediators, and one
outcome.sublongspikes: Longitudinal mediation dataset stored as
a three-dimensional array for repeated-measures analysis with
longBMed().framing2: A modified version of the
framing dataset from the mediation package
containing dichotomized candidate mediators for demonstrating the
GT-exploratory Bayesian mediation functions.If you use buzzMed in your research, please cite:
Shi, D., Shi, D., & Fairchild, A. J. (2023). Variable Selection for Mediators under a Bayesian Mediation Model. Structural Equation Modeling: A Multidisciplinary Journal, 30(6), 887–900. https://doi.org/10.1080/10705511.2022.2164285
This project is licensed under the GNU General Public License v3.0.
See the LICENSE file for details.