About the Package

The R package CMAverse provides a suite of functions for reproducible causal mediation analysis including cmdag for DAG visualization, cmest for statistical modeling and cmsens for sensitivity analysis.

See the package website for a quickstart guide, an overview of statistical modeling approaches and examples.

DAG Visualization

cmdag visualizes causal relationships via a directed acyclic graph (DAG).

Statistical Modeling

cmest implements six causal mediation analysis approaches including the regression-based approach by Valeri et al. (2013) and VanderWeele et al. (2014), the weighting-based approach by VanderWeele et al. (2014), the inverse odd-ratio weighting approach by Tchetgen Tchetgen (2013), the natural effect model by Vansteelandt et al. (2012), the marginal structural model by VanderWeele et al. (2017), and the g-formula approach by Robins (1986).

cmest currently supports a single exposure, multiple sequential mediators and a single outcome. When multiple mediators are of interest, cmest estimates the joint mediated effect through the set of mediators. cmest also allows for time varying confounders preceding mediators. The two causal scenarios supported are:

  1. There are no confounders affected by the exposure:

  1. There are mediator-outcome confounders affected by the exposure and these confounders precede all of the mediators:

Table: Supported Data Types and Functionalities of cmest
rb wb iorw ne msm gformula1
Continuous Y2
Binary Y
Count Y
Nominal Y ×
Ordinal Y ×
Survival Y × ×
Continuous M ×
Binary M
Nominal M
Ordinal M
Count M ×
M of Any Type × × ×
Continuous A ×3 × ×4
Binary A
Nominal A
Ordinal A
Count A ×5 × ×6
Mediator-outcome Confounder(s) Affected by A × × × ×
2-way Decomposition
4-way Decomposition ×
Estimation: Closed-form Parameter Function 7 × × × × ×
Estimation: Direct Counterfactual Imputation
Inference: Delta Method 8 × × × × ×
Inference: Bootstrapping
Marginal Effects 9
Effects Conditional on C 10 × × × × ×
  1. rb: the regression-based approach; wb: the weighting-based approach; iorw: the inverse odds ratio weighting approach; ne: the natural effect model; msm: the marginal structural model; gformula: the g-formula approach.↩︎

  2. Y denotes the outcome, A denotes the exposure, M denotes the mediator(s) and C denotes the exposure-outcome confounder(s), the exposure-mediator confounder(s) and the mediator-outcome confounder(s) not affected by the exposure.↩︎

  3. continuous A is not supported when C is not empty; otherwise, it is supported.↩︎

  4. continuous A is not supported when C is not empty; otherwise, it is supported.↩︎

  5. count A is not supported when C is not empty; otherwise, it is supported.↩︎

  6. count A is not supported when C is not empty; otherwise, it is supported.↩︎

  7. closed-form parameter function estimation only supports a single mediator.↩︎

  8. delta method inference is available only when closed-form parameter function estimation is used.↩︎

  9. marginal effects are estimated when direct counterfactual imputation estimation is used.↩︎

  10. conditional effects are estimated when closed-form parameter function estimation is used.↩︎

Multiple Imputation

cmest provides the option multimp = TRUE to perform multiple imputations for a dataset with missing values.

Sensitivity Analysis

cmsens conducts sensitivity analysis for unmeasured confounding via the E-value approach by VanderWeele et al. (2017) and Smith et al. (2019), and sensitivity analysis for measurement error via regression calibration by Carroll et al. (1995) and SIMEX by Cook et al. (1994) and Küchenhoff et al. (2006). Sensitivity analysis for measurement error is currently available for the regression-based approach and the g-formula approach.


The latest version can be installed via:


Load CMAverse:



Valeri L, Vanderweele TJ (2013). Mediation analysis allowing for exposure-mediator interactions and causal interpretation: theoretical assumptions and implementation with SAS and SPSS macros. Psychological Methods. 18(2): 137 - 150.

VanderWeele TJ, Vansteelandt S (2014). Mediation analysis with multiple mediators. Epidemiologic Methods. 2(1): 95 - 115.

Tchetgen Tchetgen EJ (2013). Inverse odds ratio-weighted estimation for causal mediation analysis. Statistics in medicine. 32: 4567 - 4580.

Nguyen QC, Osypuk TL, Schmidt NM, Glymour MM, Tchetgen Tchetgen EJ (2015). Practical guidance for conducting mediation analysis with multiple mediators using inverse odds ratio weighting. American Journal of Epidemiology. 181(5): 349 - 356.

VanderWeele TJ, Tchetgen Tchetgen EJ (2017). Mediation analysis with time varying exposures and mediators. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 79(3): 917 - 938.

Robins JM (1986). A new approach to causal inference in mortality studies with a sustained exposure period-Application to control of the healthy worker survivor effect. Mathematical Modelling. 7: 1393 - 1512.

Vansteelandt S, Bekaert M, Lange T (2012). Imputation Strategies for the Estimation of Natural Direct and Indirect Effects. Epidemiologic Methods. 1(1): 131 - 158.

Steen J, Loeys T, Moerkerke B, Vansteelandt S (2017). Medflex: an R package for flexible mediation analysis using natural effect models. Journal of Statistical Software. 76(11).

VanderWeele TJ (2014). A unification of mediation and interaction: a 4-way decomposition. Epidemiology. 25(5): 749 - 61.

Imai K, Keele L, Tingley D (2010). A general approach to causal mediation analysis. Psychological Methods. 15(4): 309 - 334.

Schomaker M, Heumann C (2018). Bootstrap inference when using multiple imputation. Statistics in Medicine. 37(14): 2252 - 2266.

VanderWeele TJ, Ding P (2017). Sensitivity analysis in observational research: introducing the E-Value. Annals of Internal Medicine. 167(4): 268 - 274.

Smith LH, VanderWeele TJ (2019). Mediational E-values: Approximate sensitivity analysis for unmeasured mediator-outcome confounding. Epidemiology. 30(6): 835 - 837.

Carrol RJ, Ruppert D, Stefanski LA, Crainiceanu C (2006). Measurement Error in Nonlinear Models: A Modern Perspective, Second Edition. London: Chapman & Hall.

Cook JR, Stefanski LA (1994). Simulation-extrapolation estimation in parametric measurement error models. Journal of the American Statistical Association, 89(428): 1314 - 1328.

Küchenhoff H, Mwalili SM, Lesaffre E (2006). A general method for dealing with misclassification in regression: the misclassification SIMEX. Biometrics. 62(1): 85 - 96.

Stefanski LA, Cook JR. Simulation-extrapolation: the measurement error jackknife (1995). Journal of the American Statistical Association. 90(432): 1247 - 56.

Valeri L, Lin X, VanderWeele TJ (2014). Mediation analysis when a continuous mediator is measured with error and the outcome follows a generalized linear model. Statistics in medicine, 33(28): 4875–4890.

Efron B (1987). Better Bootstrap Confidence Intervals. Journal of the American Statistical Association. 82(397): 171-185.