| Title: | Bayesian Understanding for Mediator Selection Framework |
|---|---|
| Description: | A collection of quantitative tools for selecting mediating effects within exploratory Bayesian mediation models. The package accommodates both continuous and dichotomous outcomes, including the dependent variables and the mediators for identifying and analyzing mediation pathways. |
| Authors: | Dingjing Shi [aut, cre], Tansu Celikel [aut], Dexin Shi [aut], Chih-Chia Hsing [ctb] |
| Maintainer: | Dingjing Shi <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.2 |
| Built: | 2026-05-29 08:11:37 UTC |
| Source: | https://github.com/olfactorybulb/buzzmed |
This function implements variable selection for mediators when dealing with binary data. It utilizes a latent probit link formulation to model the probabilities of the binary responses within the JAGS framework. It automates data preparation, JAGS model construction, and MCMC sampling.
buzzEBMcatMcatY( model, dataset, my_prior = NULL, advanced = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )buzzEBMcatMcatY( model, dataset, my_prior = NULL, advanced = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )
model |
A description of the model to be fitted. This is typically a
formula or a character string using |
dataset |
A |
my_prior |
Optional |
advanced |
Character. Use |
a.coef.mean, a.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
b.coef.mean, b.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
a.pip.hyperalpha, a.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
b.pip.hyperalpha, b.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
direct.coef.mean, direct.coef.precision
|
Numeric scalar or vector.
Mean and precision parameters for the Normal prior of the direct effects
( |
direct.coef.init |
Numeric or |
a.pip.hyperprior.init, b.pip.hyperprior.init
|
Numeric or |
n_chains |
Integer. Number of MCMC chains. |
n_adapt |
Integer. Number of adaptation iterations. |
n_burnin |
Integer. Number of burn-in iterations. |
n_iter |
Integer. Number of post-burn-in iterations. |
thin |
Integer. Thinning interval. |
Fits a Bayesian mediation model specifically designed for cases where both
the mediators () and the outcome variable () are binary (0/1).
Since both and are binary, residual precisions are not
estimated (they are fixed to 1 in the latent probit space).
This function identifies via .parse_buzz_syntax
and routes the data through an internal pipeline including
prepare_ebmed_data and build_ebmed_model_mcat_ycat.
An object of class mcmc.list containing posterior samples.
This function is strictly for binary data. For variables with more than two levels, please convert them into dummy variables or ensure they are binary before running.
Shi, D., Shi, D., and Fairchild, A. J. (2023) "Variable Selection for Mediators under a Bayesian Mediation Model" <doi:10.1080/10705511.2022.2164285>
# Binary case: Both M and Y are Binary set.seed(101) n <- 100 toy_data <- data.frame( X = rbinom(n, 1, 0.5), M1 = rbinom(n, 1, 0.3), M2 = rbinom(n, 1, 0.7), Y = rbinom(n, 1, 0.5) ) # Fit the model results <- buzzEBMcatMcatY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)# Binary case: Both M and Y are Binary set.seed(101) n <- 100 toy_data <- data.frame( X = rbinom(n, 1, 0.5), M1 = rbinom(n, 1, 0.3), M2 = rbinom(n, 1, 0.7), Y = rbinom(n, 1, 0.5) ) # Fit the model results <- buzzEBMcatMcatY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)
This function implements variable selection for mediators in a mixed data framework. It utilizes latent variable formulations for the binary mediators and a Gaussian likelihood for the continuous outcome. It automates data preparation, JAGS model construction, and MCMC sampling.
buzzEBMcatMcontY( model, dataset, my_prior = NULL, advanced = NULL, y.prec.shape = NULL, y.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, y.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )buzzEBMcatMcontY( model, dataset, my_prior = NULL, advanced = NULL, y.prec.shape = NULL, y.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, y.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )
model |
A description of the model to be fitted. This is typically a
formula or a character string using |
dataset |
A |
my_prior |
Optional |
advanced |
Character. Use |
y.prec.shape, y.prec.rate
|
Numeric scalar. Shape and rate parameters of the Gamma hyperprior for the outcome residual precision. By default, a Gamma distribution is used. The default values are 1 and 0.001, respectively. |
a.coef.mean, a.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
b.coef.mean, b.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
a.pip.hyperalpha, a.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
b.pip.hyperalpha, b.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
direct.coef.mean, direct.coef.precision
|
Numeric scalar or vector.
Mean and precision parameters for the Normal prior of the direct effects
( |
y.prec.init |
Numeric or |
direct.coef.init |
Numeric or |
a.pip.hyperprior.init, b.pip.hyperprior.init
|
Numeric or |
n_chains |
Integer. Number of MCMC chains. |
n_adapt |
Integer. Number of adaptation iterations. |
n_burnin |
Integer. Number of burn-in iterations. |
n_iter |
Integer. Number of post-burn-in iterations. |
thin |
Integer. Thinning interval. |
Fits a Bayesian mediation model specifically designed for cases where
the mediators () are binary (0/1) and the outcome variable ()
is continuous.
This function is a specific "worker" function. It identifies
via .parse_buzz_syntax. While is modeled with residual
precision parameters, the mediators are binary and thus their
residual precisions are fixed to 1 within the latent variable framework.
An object of class mcmc.list containing posterior samples.
Shi, D., Shi, D., and Fairchild, A. J. (2023) "Variable Selection for Mediators under a Bayesian Mediation Model" <doi:10.1080/10705511.2022.2164285>
# Mixed case: Binary M, Continuous Y set.seed(789) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rbinom(n, 1, 0.4), M2 = rbinom(n, 1, 0.6), Y = rnorm(n) ) # Fit the model results <- buzzEBMcatMcontY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)# Mixed case: Binary M, Continuous Y set.seed(789) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rbinom(n, 1, 0.4), M2 = rbinom(n, 1, 0.6), Y = rnorm(n) ) # Fit the model results <- buzzEBMcatMcontY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)
This function implements variable selection for mediators in a mixed data framework. It assumes a Gaussian likelihood for the mediators and a latent probit link for the binary outcome. It automates data preparation, JAGS model construction, and MCMC sampling.
buzzEBMcontMcatY( model, dataset, my_prior = NULL, advanced = NULL, m.prec.shape = NULL, m.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, m.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )buzzEBMcontMcatY( model, dataset, my_prior = NULL, advanced = NULL, m.prec.shape = NULL, m.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, m.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )
model |
A description of the model to be fitted. This is typically a
formula or a character string using |
dataset |
A |
my_prior |
Optional |
advanced |
Character. Use |
m.prec.shape, m.prec.rate
|
Numeric scalar or vector of length equal to the number of mediators. Shape and rate parameters of the Gamma hyperprior for the mediator residual precisions. By default, a Gamma distribution is used. The default values are 1 and 0.001, respectively. |
a.coef.mean, a.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
b.coef.mean, b.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
a.pip.hyperalpha, a.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
b.pip.hyperalpha, b.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
direct.coef.mean, direct.coef.precision
|
Numeric scalar or vector.
Mean and precision parameters for the Normal prior of the direct effects
( |
m.prec.init |
Numeric or |
direct.coef.init |
Numeric or |
a.pip.hyperprior.init, b.pip.hyperprior.init
|
Numeric or |
n_chains |
Integer. Number of MCMC chains. |
n_adapt |
Integer. Number of adaptation iterations. |
n_burnin |
Integer. Number of burn-in iterations. |
n_iter |
Integer. Number of post-burn-in iterations. |
thin |
Integer. Thinning interval. |
Fits a Bayesian mediation model specifically designed for cases where
the mediators () are continuous and the outcome variable ()
is binary (0/1).
This function is a specific "worker" function. It identifies
via .parse_buzz_syntax. While is modeled with residual
precision parameters, is binary and thus its residual precision
is fixed to 1 within the latent variable framework.
An object of class mcmc.list containing posterior samples.
Shi, D., Shi, D., and Fairchild, A. J. (2023) "Variable Selection for Mediators under a Bayesian Mediation Model" <doi:10.1080/10705511.2022.2164285>
# Mixed case: Continuous M, Binary Y set.seed(456) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rnorm(n), M2 = rnorm(n), Y = rbinom(n, 1, 0.5) ) # Fit the model results <- buzzEBMcontMcatY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)# Mixed case: Continuous M, Binary Y set.seed(456) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rnorm(n), M2 = rnorm(n), Y = rbinom(n, 1, 0.5) ) # Fit the model results <- buzzEBMcontMcatY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 200, n_iter = 1000 ) summary(results)
This function implements variable selection for mediators in a fully continuous framework. It automates data preparation, JAGS model construction using Gaussian likelihoods, and MCMC sampling.
buzzEBMcontMcontY( model, dataset, my_prior = NULL, advanced = NULL, m.prec.shape = NULL, m.prec.rate = NULL, y.prec.shape = NULL, y.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, m.prec.init = NULL, y.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )buzzEBMcontMcontY( model, dataset, my_prior = NULL, advanced = NULL, m.prec.shape = NULL, m.prec.rate = NULL, y.prec.shape = NULL, y.prec.rate = NULL, a.coef.mean = NULL, a.coef.prec = NULL, b.coef.mean = NULL, b.coef.prec = NULL, a.pip.hyperalpha = NULL, a.pip.hyperbeta = NULL, b.pip.hyperalpha = NULL, b.pip.hyperbeta = NULL, direct.coef.mean = NULL, direct.coef.precision = NULL, m.prec.init = NULL, y.prec.init = NULL, direct.coef.init = NULL, a.pip.hyperprior.init = NULL, b.pip.hyperprior.init = NULL, n_chains = NULL, n_adapt = NULL, n_burnin = NULL, n_iter = NULL, thin = NULL )
model |
A description of the model to be fitted. This is typically a
formula or a character string using |
dataset |
A |
my_prior |
Optional |
advanced |
Character. Use |
m.prec.shape, m.prec.rate
|
Numeric scalar or vector of length equal to the number of mediators. Shape and rate parameters of the Gamma hyperprior for the mediator residual precisions. By default, a Gamma distribution is used. The default values are 1 and 0.001, respectively. |
y.prec.shape, y.prec.rate
|
Numeric scalar. Shape and rate parameters of the Gamma hyperprior for the outcome residual precision. By default, a Gamma distribution is used. The default values are 1 and 0.001, respectively. |
a.coef.mean, a.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
b.coef.mean, b.coef.prec
|
Numeric scalar or vector.
Mean and precision parameters of the Normal prior for the |
a.pip.hyperalpha, a.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
b.pip.hyperalpha, b.pip.hyperbeta
|
Numeric scalar or vector. Alpha and
beta parameters for the Beta hyperprior of the |
direct.coef.mean, direct.coef.precision
|
Numeric scalar or vector.
Mean and precision parameters for the Normal prior of the direct effects
( |
m.prec.init, y.prec.init
|
Numeric or |
direct.coef.init |
Numeric or |
a.pip.hyperprior.init, b.pip.hyperprior.init
|
Numeric or |
n_chains |
Integer. Number of MCMC chains. |
n_adapt |
Integer. Number of adaptation iterations. |
n_burnin |
Integer. Number of burn-in iterations. |
n_iter |
Integer. Number of post-burn-in iterations. |
thin |
Integer. Thinning interval. |
Fits a Bayesian mediation model specifically designed for cases where both
the mediators () and the outcome variable () are continuous.
This function is a specific "worker" function. It identifies
via .parse_buzz_syntax and performs Bayesian estimation assuming:
and .
An object of class mcmc.list containing posterior samples.
Shi, D., Shi, D., and Fairchild, A. J. (2023) "Variable Selection for Mediators under a Bayesian Mediation Model" <doi:10.1080/10705511.2022.2164285>
# 1. Create a continuous synthetic dataset set.seed(123) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rnorm(n), M2 = rnorm(n), Y = rnorm(n) ) # 2. Fit the model using lavaan-style syntax # We define Y as the outcome, with M1, M2, and X as predictors results <- buzzEBMcontMcontY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 500, n_iter = 2000 ) # 3. Check results summary(results)# 1. Create a continuous synthetic dataset set.seed(123) n <- 100 toy_data <- data.frame( X = rnorm(n), M1 = rnorm(n), M2 = rnorm(n), Y = rnorm(n) ) # 2. Fit the model using lavaan-style syntax # We define Y as the outcome, with M1, M2, and X as predictors results <- buzzEBMcontMcontY( model = "Y ~ M1 + M2 | X", dataset = toy_data, n_burnin = 500, n_iter = 2000 ) # 3. Check results summary(results)
This function allows users to customize priors without needing to manually construct complex data frames. It displays current defaults, allows selection of specific parameters to change, and provides a menu of available JAGS distributions (e.g., Normal, Gamma, Beta).
run_parms_wizard(verbose = TRUE)run_parms_wizard(verbose = TRUE)
verbose |
Logical. If |
Launches an interactive console-based interface to guide users through viewing and modifying Bayesian prior distributions for mediation models.
The wizard handles two main types of customization:
Distribution Selection: Choose from supported JAGS distributions.
Argument Specification: Set numeric values for hyperparameters (e.g., shape, rate, mean, precision).
For coefficients like and , the wizard will note if they
reference hyperpriors (back-references). It is generally recommended to
modify the shape of the hyperprior rather than the coefficient's distribution
directly to maintain the hierarchical structure.
A data.frame with columns priors, distribution,
and arguments. This dataframe is formatted to be passed directly
to the my_prior argument in related fitting functions.
This function requires an interactive R session. It will return
invisible(NULL) if the user cancels the process.
# Create toy data toy_data <- data.frame( X = rbinom(100, 1, 0.5), M = rbinom(100, 1, 0.3), Y = rbinom(100, 1, 0.5) ) custom_priors <- NULL if (interactive()){ # Launch the wizard custom_priors <- run_parms_wizard() } # Use the resulting object in a model fit <- buzzEBMcatMcatY(model = "Y ~ M | X", dataset = toy_data, my_prior = custom_priors)# Create toy data toy_data <- data.frame( X = rbinom(100, 1, 0.5), M = rbinom(100, 1, 0.3), Y = rbinom(100, 1, 0.5) ) custom_priors <- NULL if (interactive()){ # Launch the wizard custom_priors <- run_parms_wizard() } # Use the resulting object in a model fit <- buzzEBMcatMcatY(model = "Y ~ M | X", dataset = toy_data, my_prior = custom_priors)