R code to implement the 4-way decomposition method on mediation and interaction for both binary and continuous mediator or outcome. This R code is easy-to-use by just giving a few inputs.
The user must define the exposure, the mediator, the covariates, the outcome, and whether the mediator and outcome are binary or continuous. Also, the user must input the value of the exposure and mediator at which to compute the controlled direct effect and the remainder of the decomposition. Finally, the bootstrap number of iterations should be defined to obtain 95% confidence intervals.
git clone
this repository (or save all files in separate folder).
- Set variables in MediationAnalysis.R script lines 15-43 according your analysis plan and save changes.
- Run:
- in the command line Rscript MediationAnalysis.R
- In Rstudio just run all code from MediationAnalysis.R
- copy/paste code from MediationAnalysis.R to R shell
We have set the mean value of the covariates at which the effects will be calculated. We considered the exposure/outcome and mediator/outcome to be confounded by the same set of confounders. We suggest the user to make a directed acyclic graph and check the assumptions for mediation analysis.
If you use this R code, please refer to the paper (including supplement) of VanderWeele (2014): "A unification of mediation and interaction: a four-way decomposition."
This project is licensed under GNU GPL v3.
- Unal Mutlu (Departments of Epidemiology and Ophthalmology, Erasmus MC, Rotterdam, Netherlands)
- Gennady V. Roshchupkin (Department of Epidemiology, Radiology and Medical Informatics, Erasmus MC, Rotterdam, Netherlands)
- Gautam Sajeev (Department of Epidemiology, Harvard T.H. Chan School of Public Health, Boston, Massachusetts)
- M. Kamran Ikram (Departments of Epidemiology and Neurology, Erasmus MC, Rotterdam, Netherlands)
- M. Arfan Ikram (Departments of Epidemiology, Neurology and Radiology, Erasmus MC, Rotterdam, Netherlands
If you have any questions/suggestions/comments or problems do not hesitate to contact us: [email protected], [email protected]