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
- 📊 Effect size computation
- 📈 Confidence interval estimation
- 🛡️ Sensitivity analysis
- 🔬 Simulation studies
# Install mediationverse
pak::pak("data-wise/mediationverse")
# Load foundation package + packages you need
library(mediationverse) # Loads medfit (foundation)
library(probmed) # For P_med effect size
library(RMediation) # For confidence intervals
library(medrobust) # For sensitivity analysis
# 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 P_med effect size, confidence intervals, and sensitivity analysis
pmed_result <- compute_pmed(med_data)
ci_result <- ci(med_data, type = "dop")
sensitivity <- sensitivity_analysis(med_data)| Package | Status | Build | Website | Role |
|---|---|---|---|---|
| medfit | Foundation | |||
| probmed | Effect Size | |||
| RMediation | Confidence Intervals | |||
| medrobust | — | Sensitivity Analysis | ||
| medsim | Simulation Infrastructure |
Current Quarter (Q4 2025): Ecosystem Development Phase
| Milestone | Status | Progress |
|---|---|---|
| medfit Phase 3 (Extraction) | ✅ Complete | 100% |
| medfit Phase 4 (Model Fitting) | 🚧 In Progress | 60% |
| probmed Integration | ⏳ Pending | 0% |
| RMediation Integration | ⏳ Pending | 0% |
| medsim Core Implementation | ✅ Complete | 100% |
| Comprehensive Documentation | ✅ Complete | 100% |
Next Quarter (Q1 2026): Integration & Release
- Complete medfit Phase 4-5 (Bootstrap, Testing)
- Integrate probmed and RMediation with medfit
- CRAN submissions for medfit, probmed
- Finalize mediationverse meta-package
The mediationverse follows a modular architecture with selective loading inspired by tidyverse and easystats:
┌──────────────────────────────────────────────────────────────────────┐
│ mediationverse │
│ (Meta-Package Loader) │
│ │
│ library(mediationverse) → Loads only medfit (foundation) │
│ library(probmed) → Explicit loading for effect sizes │
│ library(RMediation) → Explicit loading for CIs │
│ library(medrobust) → Explicit loading for sensitivity │
│ library(medsim) → Explicit loading for simulation │
└──────────────────────────────────────────────────────────────────────┘
│
│ Always loads
▼
┌──────────────────────────────────────────────────────────────────────┐
│ FOUNDATION LAYER │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ medfit │ │
│ │ • S7 classes (MediationData, SerialMediationData) │ │
│ │ • extract_mediation() - Extract from lm/glm/lavaan │ │
│ │ • fit_mediation() - Formula interface │ │
│ │ • bootstrap_mediation() - Bootstrap inference │ │
│ └────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────────────────────────┐
│ SPECIALIZED PACKAGES LAYER │
├────────────────┬─────────────────┬────────────────┬─────────────────┤
│ probmed │ RMediation │ medrobust │ medsim │
│ ┌────────────┐ │ ┌─────────────┐ │ ┌────────────┐ │ ┌─────────────┐ │
│ │ Effect │ │ │ Confidence │ │ │Sensitivity │ │ │ Simulation │ │
│ │ Sizes │ │ │ Intervals │ │ │ Analysis │ │ │Infrastructure│ │
│ ├────────────┤ │ ├─────────────┤ │ ├────────────┤ │ ├─────────────┤ │
│ │• P_med │ │ │• DOP │ │ │• Bounds │ │ │• Data gen │ │
│ │• Scale-free│ │ │• Monte Carlo│ │ │• Falsify │ │ │• Parallel │ │
│ │• Continuous│ │ │• MBCO │ │ │• Partial ID│ │ │• Caching │ │
│ │• Binary │ │ │• Asymmetric │ │ │• Plots │ │ │• Tables │ │
│ └────────────┘ │ └─────────────┘ │ └────────────┘ │ └─────────────┘ │
└────────────────┴─────────────────┴────────────────┴─────────────────┘
│
│ All packages use
▼
┌─────────────────────┐
│ MediationData (S7) │
│ Unified Interface │
└─────────────────────┘
User Data
│
▼
fit_mediation() or lm()/glm()/lavaan::sem()
│
▼
extract_mediation() ──────► MediationData object
│ │
│ │
├──────────────┬──────────────┬────┴────────────┐
│ │ │ │
▼ ▼ ▼ ▼
probmed:: RMediation:: medrobust:: medfit::
compute_pmed() medci() sensitivity() 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: Compute P_med, a scale-free probabilistic effect size Status: Stable, ready for integration Provides:
- P_med computation for continuous and binary outcomes
- GLM support (logistic, Poisson)
- Integration with lavaan and mediation packages
- Bootstrap confidence intervals
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
Purpose: Partial identification under differential misclassification Status: In development Provides:
- Partial identification bounds for NDE/NIE
- Data-driven falsification tests
- Synthetic data generation
- Publication-ready visualizations
Links: Website | GitHub | Issues
Purpose: Standardized infrastructure for Monte Carlo studies Status: Core implementation complete Provides:
- Environment-aware execution (local/HPC)
- Parallel processing with progress bars
- Ground truth caching
- Publication-ready figures and LaTeX tables
Links: Website | GitHub | Issues
# Install all packages
pak::pak("Data-Wise/mediationverse")
# Or install individually
pak::pak("Data-Wise/medfit")
pak::pak("Data-Wise/probmed")
pak::pak("Data-Wise/medrobust")
pak::pak("Data-Wise/medsim")
# RMediation from CRAN
install.packages("RMediation")# Planned for Q2-Q3 2026
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.0.0.9000 ──
#> ✔ medfit 0.1.0 (foundation package)
#> ℹ Use library(probmed) for P_med effect size
#> ℹ Use library(RMediation) for DOP/MBCO inference
#> ℹ Use library(medrobust) for sensitivity analysis
#> ℹ Use library(medsim) for simulation utilities
#> ──────────────────────────────────────────────────────
# Load additional packages as needed
library(probmed) # For probabilistic effect sizes
library(RMediation) # For confidence intervals
library(medrobust) # For sensitivity analysis
library(medsim) # For simulation studiesWhy 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()# Load foundation and packages you need
library(mediationverse) # Loads medfit (foundation)
library(probmed) # For P_med effect size
library(RMediation) # For confidence intervals
library(medrobust) # For sensitivity analysis
# 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. Compute probabilistic effect size (probmed)
pmed_result <- compute_pmed(med_data)
# 5. Get confidence intervals (RMediation)
ci_result <- ci(med_data, type = "dop")
# 6. Sensitivity analysis (medrobust)
robust_result <- sensitivity_analysis(med_data)
# 7. Run simulation study (medsim - load if needed)
library(medsim)
sim_results <- medsim_run(
method = my_method,
scenarios = medsim_scenarios_mediation(),
config = medsim_config("local")
)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
- medfit Documentation
- probmed Documentation
- RMediation Documentation
- medrobust Documentation
- medsim Documentation
The mediationverse is in active development. Contributions are welcome!
- 🐛 Report bugs: GitHub Issues
- 💡 Suggest features: Discussions
- 🔧 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. (2025). medfit: Infrastructure for mediation analysis in R.
R package version 0.1.0. https://github.com/data-wise/medfit
Tofighi, D. (2025). probmed: Probabilistic effect sizes for mediation analysis.
R package version 0.1.0. https://github.com/data-wise/probmed
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:
