Unified ecosystem for mediation analysis in R
The mediationverse is a collection of R packages for mediation analysis, providing a unified ecosystem for:
- 🔧 Model fitting and extraction
- 📈 Confidence interval estimation
# 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")# 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)# 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)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>, notr-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 | Foundation | |||
| RMediation | Confidence Intervals |
The mediationverse follows a modular architecture with selective loading inspired by tidyverse and easystats:
User Data
│
▼
fit_mediation() or lm()/glm()/lavaan::sem()
│
▼
extract_mediation() ──────► MediationData object
│ │
├──────────────┬───────────────────┘
│ │
▼ ▼
RMediation:: medfit::
medci() bootstrap_mediation()
│ │
└──────────────┘
│
▼
Results & Inference
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
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
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")
)# 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")# Planned — once mediationverse itself is submitted to CRAN
install.packages("mediationverse")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 intervalsWhy selective loading?
- Clean namespace (avoids function conflicts)
- Only load what you need for your analysis
medfitis always available (foundation for all packages)
# 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()# 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")Following principles from tidyverse and easystats:
- Foundation Package: medfit provides shared S7 infrastructure
- Specialized Packages: Each package focuses on one methodological contribution
- Consistent API: Unified interfaces across all packages
- Type Safety: S7 classes ensure data integrity
- Low Dependencies: Minimal external dependencies for stability
- Comprehensive Testing: >90% code coverage across packages
- 📊 Package Status Dashboard
- 🗺️ Development Roadmap
- 🤝 Contributing Guide
- 🧭 Planning Hub — roadmap, specs, coordination
- 📋 Ecosystem Coordination
The mediationverse is in active development. Contributions are welcome!
- 🐛 Report bugs: GitHub Issues
- 💡 Suggest features: GitHub Issues
- 🔧 Contribute code: See our Contributing Guide
- 📖 Improve docs: Submit pull requests
Development Workflow:
- Fork the repository
- Create a feature branch from
dev - Make your changes with tests
- Submit a pull request to
dev
See CONTRIBUTING.md for detailed guidelines.
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").
The mediationverse draws inspiration from:
- tidyverse - Cohesive data science packages
- easystats - Statistical modeling ecosystem
- mlr3 - Machine learning framework
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.
GPL (>= 3)
Maintainer: Davood Tofighi (dtofighi@gmail.com) ORCID: 0000-0001-8523-7776
Sources:
