MyNixOS website logo
Description

Mediation Analysis Confidence Intervals.

Computes confidence intervals for nonlinear functions of model parameters (e.g., product of k coefficients) in single-level and multilevel structural equation models. Methods include the distribution of the product, Monte Carlo simulation, and bootstrap methods. It also performs the Model-Based Constrained Optimization (MBCO) procedure for hypothesis testing of indirect effects. References: Tofighi, D., and 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>; Tofighi, D., and 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>; Tofighi, D. (2020). Bootstrap Model-Based Constrained Optimization Tests of Indirect Effects. Frontiers in Psychology, 10, 2989. <doi:10.3389/fpsyg.2019.02989>.

RMediation RMediation website

CRAN status Website Status Lifecycle: stable R-hub

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.

Key Capabilities

1. Rigorous Confidence Intervals

Compute accurate Confidence Intervals (CIs) for indirect effects using methods that outperform the standard normal approximation:

  • Distribution of the Product: Exact method for the product of two normal random variables.
  • Monte Carlo Method: Robust simulation-based intervals.
  • Bootstrapping: Parametric and semi-parametric bootstrap implementations.

2. Advanced Hypothesis Testing

  • LRT-MBCO: Implements the Likelihood Ratio Test via Model-Based Constrained Optimization, a powerful frequentist method for testing indirect effects that controls Type I error rates better than standard approaches.
  • Sobel Test: Asymptotic normal test included for baseline comparison.

3. Seamless Integration

  • Works directly with summary statistics (coefficients/SEs).
  • Extracts parameters automatically from fitted lavaan or OpenMx model objects.

Installation

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")

Usage

Using Summary Statistics to Calculate CIs

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")

Using ci to Calculate CIs for Indirect Effects of Path with Two Sequential Mediators

library(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)

Contributing

Contributions are welcome! If you encounter issues or have feature requests:

Citation

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

License

RMediation is licensed under the GPL-3.0.

Metadata

Version

1.3.0

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows