The R packageBayesGmed implements parametricmediation analysis using the Bayesian g-formula approach. In addition tothe estimation of causal mediation effects, the package also allowsresearchers to conduct sensitivity analysis. The methodology behind theR-package and a demonstration of its application can be found on [arxiv](https://arxiv.org/abs/2210.08499) The package’s source code is hostedonGitHub. Moreinformation can be found on theBayesGmed’s Vignette.
Please ensure you have the latest version of R installed. Windowsusers may need to install RTools (more information on theRStanwebsite), OS X users may need to install XCode
BayesGmed is developed on GitHub, and users mayobtain the latest (development) version from GitHub directly.
The latest development version ofBayesGmed requiresdevtools forinstallation. If you don’t have the devtools package installed in R,first run this line:
install.packages("devtools")Then proceed to installBayesGmed from GitHub:
devtools::install_github("belayb/BayesGmed")TheBayesGmed R-package currently handles continuousoutcome – continuous mediator, binary outcome – binary mediator,continuous outcome – binary mediator, and binary outcome – continuousmediator.
Suppose we are interested in the causal direct and indirect effect ofa single exposure\(A\) on a binaryoutcome\(Y\) where we have a singlebinary mediator\(M\). In addition,assume we have two confounding variables
To estimate the direct and indirect of the exposure on the outcomeadjusted for confounder, the anlaysis would follow as below.
data(example_data)fit1<-bayesgmed(outcome ="Y",mediator ="M",treat ="A",covariates =c("Z1","Z2"),dist.y ="binary",dist.m ="binary",link.y ="logit",link.m ="logit",data = example_data)bayesgmed_summary(fit1)The above model assumes the following structure for the outcome andmediator model
Note: BayesGmed currently does not handle interaction. ### Priors
Currently, a multi-normal,
priors<-list(scale_m =2.5*diag(P+1),scale_y =2.5*diag(P+2),location_m =rep(0, P+1),location_y =rep(0, P+2),scale_sd_y =2.5,scale_sd_m =2.5)where\(P\) is the number ofcovariates (including the intercept) in the mediator/outcome model butexcluding the exposure and mediator. For the residual standarddeviation, a half normal prior distribution with mean zero and scaleparameter scale_sd_* is assumed. Currently, the user can only change thescale and location parameters.
Maintained by Belay Birlie Yimer of theCentre for Epidemiology VersusArthritis, University of Manchester, UK. Co-authors: Mark Lunt, JohnMcBeth, Marcus Beasley, and Gary J Macfarlane. Stan model definitionwithin the package are based on Comment, Leah (2018) Causal inferencewith the g-formula in Stan.
The package is under development. Hence, pull requests and GitHubissues are welcome. Any use of the package has to be done wth care.