
RMediation provides rigorous statistical methods for mediation analysis in observational and experimental designs. It addresses the known limitations of normal-theory confidence intervals (e.g., Sobel test) by implementing advanced methods that account for the non-normal distribution of the indirect effect.
Compute accurate Confidence Intervals (CIs) for indirect effects using methods that outperform the standard normal approximation:
lavaan or
OpenMx model objects.You can install the stable version from CRAN:
install.packages("RMediation")Or the development version from GitHub:
R
# install.packages("remotes")
remotes::install_github("data-wise/RMediation")
If you already have estimates from a published paper or other software, you can calculate CIs using coefficients (\(\hat{a}, \hat{b}\)) and their standard errors.
library(RMediation)
# Example: Single mediator
# a = 0.5, b = 0.6, se.a = 0.08, se.b = 0.04, rho = 0 (independence)
medci(mu.x = 0.5, mu.y = 0.6, se.x = 0.08, se.y = 0.04, rho = 0, type = "prodclin")ci to Calculate CIs for Indirect Effects of Path with Two
Sequential Mediatorslibrary(RMediation)
# Example: Two sequential mediators
ci(mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45),
Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03),
quant = ~ b1 * b2 * b3 * b4, type = "MC", plot = TRUE, plotCI = TRUE)Contributions are welcome! If you encounter issues or have feature requests:
If you use RMediation in your research, please cite the following:
Package Reference: > Tofighi, D., & MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
MBCO Method: > Tofighi, D., & Kelley, K. (2020). Improved inference in mediation analysis: Introducing the model-based constrained optimization procedure. Psychological Methods, 25(4), 496-515. doi:10.1037/met0000259
Bootstrap MBCO: > Tofighi, D. (2020). Bootstrap Model-Based Constrained Optimization Tests of Indirect Effects. Frontiers in Psychology, 10, 2989. doi:10.3389/fpsyg.2019.02989
RMediation is licensed under the GPL-3.0.