Skip to content

About

Meta-package for the mediation analysis ecosystem in R

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

mediationverse

Unified ecosystem for mediation analysis in R

Lifecycle: experimental Repo Status R-CMD-check Website Status r-universe

Overview

The mediationverse is a collection of R packages for mediation analysis, providing a unified ecosystem for:

  • 🔧 Model fitting and extraction
  • 📈 Confidence interval estimation

Quick Start

# Install mediationverse (it requires medfit >= 0.5.0, installed from GitHub via
# Remotes: CRAN's 0.3.2 predates result-changing fixes), plus RMediation (opt-in: it
# is not installed automatically with mediationverse)
pak::pak(c("Data-Wise/mediationverse", "RMediation"))

# Load foundation package + packages you need
library(mediationverse)  # Loads medfit (foundation)
library(RMediation)      # For confidence intervals

# Fit mediation models
fit_m <- lm(M ~ X + C, data = mydata)
fit_y <- lm(Y ~ X + M + C, data = mydata)
med_data <- extract_mediation(fit_m, model_y = fit_y,
                               treatment = "X", mediator = "M")

# Get confidence intervals
ci_result <- ci(med_data, type = "dop")

Verify your installation

# Prints a situation report of all ecosystem packages, their versions,
# the recommended install source, and where each copy was actually installed from
mediationverse_sitrep()

# Also check minimum versions, optional dependencies and function conflicts
mediationverse_sitrep(checks = TRUE)

# Check the installed members still work together (fits a small analysis through RMediation and probmed)
mediationverse_sitrep(contracts = TRUE)

# Look up newer versions (contacts CRAN and r-universe), then update only what is behind
mediationverse_sitrep(updates = TRUE)
mediationverse_update(only_outdated = TRUE, dry_run = TRUE)  # preview
mediationverse_update(only_outdated = TRUE)

Session helpers

# Latest released versions' NEWS for every installed member (default: 3 versions)
mediationverse_news(n = 2)

# Attach every installed member at once (library(mediationverse) attaches medfit only)
mediationverse_attach_all()

# In ~/.Rprofile: silence the banner printed by library(mediationverse)
options(mediationverse.quiet = TRUE)

Ecosystem Status Dashboard

📊 View Full Dashboard | 🗺️ Development Roadmap

Package Overview

CRAN and Build columns are live badges (shields.io / GitHub Actions) — they reflect real-time status and update automatically as packages are submitted, accepted, or re-checked. No manual edits needed here when a package's CRAN state changes. (Deliberately using img.shields.io/cran/v/<pkg>, not r-pkg.org/badges/version/<pkg> — the latter 404s with a broken HTML error page, not a valid SVG, for packages not yet on CRAN.)

Package CRAN Build Website Role
medfit CRAN Build Docs Foundation
RMediation CRAN Build Docs Confidence Intervals

Package Ecosystem

The mediationverse follows a modular architecture with selective loading inspired by tidyverse and easystats:

Data Flow

User Data
   │
   ▼
fit_mediation() or lm()/glm()/lavaan::sem()
   │
   ▼
extract_mediation()  ──────►  MediationData object
   │                                  │
   ├──────────────┬───────────────────┘
   │              │
   ▼              ▼
RMediation::   medfit::
medci()        bootstrap_mediation()
   │              │
   └──────────────┘
          │
          ▼
  Results & Inference

Core Packages

medfit: Foundation Infrastructure

Purpose: Unified S7-based infrastructure for mediation analysis Status: Phase 4 in progress Provides:

  • S7 classes (MediationData, SerialMediationData, BootstrapResult)
  • Model extraction from lm/glm/lavaan
  • Bootstrap inference (parametric, nonparametric, plugin)
  • Type-safe data structures

Links: Website | GitHub | Issues

RMediation: Confidence Intervals

Purpose: Asymmetric confidence intervals via Distribution of Product Status: Stable on CRAN Provides:

  • Distribution of Product (DOP) method
  • Monte Carlo (MC) confidence intervals
  • MBCO bootstrap method
  • Integration with standard R models

Links: CRAN | Website | GitHub

Installation

From r-universe (recommended)

The whole ecosystem is available as pre-built binaries at the Data-Wise r-universe — no compiler needed, and GitHub-only packages resolve automatically:

install.packages(
  "mediationverse",
  repos = c("https://data-wise.r-universe.dev", "https://cloud.r-project.org")
)

From GitHub (development)

# Install via pak. medfit is installed from GitHub (listed in Remotes) because
# CRAN's 0.3.2 predates result-changing fixes in 0.5.0.
pak::pak("Data-Wise/mediationverse")

From CRAN (future)

# Planned — once mediationverse itself is submitted to CRAN
install.packages("mediationverse")

Usage

Loading Packages

The mediationverse uses selective loading: only the foundation package (medfit) is loaded by default. Load other packages as needed for your analysis.

library(mediationverse)
#> ── Attaching mediationverse 0.2.0 ──
#> ✔ medfit 0.3.2 (foundation package)
#> ℹ Use library(RMediation) for DOP/MBCO inference
#> ──────────────────────────────────────────────────────

# Load additional packages as needed
library(RMediation)   # For confidence intervals

Why selective loading?

  • Clean namespace (avoids function conflicts)
  • Only load what you need for your analysis
  • medfit is always available (foundation for all packages)

Package Management

# List installed packages and versions
mediationverse_packages()

# Update all packages
mediationverse_update()

# Check for function conflicts
mediationverse_conflicts()

# Collect the citations of the installed packages (text or BibTeX)
mediationverse_citations()

Complete Analysis Workflow

# Load foundation and packages you need
library(mediationverse)  # Loads medfit (foundation)
library(RMediation)      # For confidence intervals

# 1. Fit mediation models (medfit - already loaded)
fit_m <- lm(M ~ X + C, data = mydata)
fit_y <- lm(Y ~ X + M + C, data = mydata)

# 2. Extract mediation structure (medfit)
med_data <- extract_mediation(fit_m, model_y = fit_y,
                               treatment = "X", mediator = "M")

# 3. Bootstrap inference (medfit)
boot_result <- bootstrap_mediation(med_data, n_boot = 2000)

# 4. Get confidence intervals (RMediation)
ci_result <- ci(med_data, type = "dop")

Design Philosophy

Following principles from tidyverse and easystats:

  1. Foundation Package: medfit provides shared S7 infrastructure
  2. Specialized Packages: Each package focuses on one methodological contribution
  3. Consistent API: Unified interfaces across all packages
  4. Type Safety: S7 classes ensure data integrity
  5. Low Dependencies: Minimal external dependencies for stability
  6. Comprehensive Testing: >90% code coverage across packages

Documentation

Getting Started

Status & Planning

Package Documentation

Contributing

The mediationverse is in active development. Contributions are welcome!

Development Workflow:

  1. Fork the repository
  2. Create a feature branch from dev
  3. Make your changes with tests
  4. Submit a pull request to dev

See CONTRIBUTING.md for detailed guidelines.

Citation

If you use packages from the mediationverse in your research, please cite the individual packages:

Tofighi, D. (2026). medfit: Infrastructure for Mediation Model Fitting and
Extraction. R package version 0.3.2. https://CRAN.R-project.org/package=medfit

Tofighi, D., & MacKinnon, D. P. (2011). RMediation: An R package for
mediation analysis confidence intervals. Behavior Research Methods, 43,
692-700. https://CRAN.R-project.org/package=RMediation

Full citations available via citation("packagename").

Related Ecosystems

The mediationverse draws inspiration from:

  • tidyverse - Cohesive data science packages
  • easystats - Statistical modeling ecosystem
  • mlr3 - Machine learning framework

Code of Conduct

Please note that the mediationverse project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

GPL (>= 3)

Contact

Maintainer: Davood Tofighi (dtofighi@gmail.com) ORCID: 0000-0001-8523-7776


Sources:

About

Meta-package for the mediation analysis ecosystem in R

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages