This is the R package for MrMediation, a Bayesian framework for Mendelian Randomization in the mediation setting.
To run the package, you might need to first install RCpp from CRAN
install.packages("RCpp")
Then the package can be installed in R from this Github repository:
library(devtools)
install_github("ZixuanWu1/MrMediation")
Recall in the Mediation setting, we have
In order to run MrMediation, we will need at least two inputs, Gamma_hat and Sd_hat. The Gamma_hat matrix is an observation of
To estimate the matrix
result = BayesMediation(Gamma_hat, Sd_hat, inv = TRUE)
Here inv = TRUE
implies we are estimating B, as opposed to estimating inv = FALSE
.
One can also support the correlation among the measurement errors by setting cor
to be the correlation matrix
result_cor = BayesMediation(Gamma_hat, Sd_hat, cor = cor_mat, inv = TRUE)
In addition, in order to compute the indirect effect of exposures on the outcome, one can simply use the following command
result = BayesMediation(Gamma_hat, Sd_hat, cor = cor_mat, indirect = T)
Sometimes we might see a warning that the algorithm might not have convergenced. This problem could be solved by using more iterations or changing the initialization method. One can also look at the traceplot of parameters for MCMC diagnosis. For instance, the following function gives the traceplot of the parameter of insterest of all the chains.
traceplot(result$raw, par = "B", ind = c(1,2))
(Here we are using