Unified ecosystem for mediation analysis in R
The mediationverse is a collection of R packages for mediation analysis, providing a unified ecosystem for:
# Install mediationverse
pak::pak("Data-Wise/mediationverse")
# 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,
# and installation sources
mediationverse_sitrep()
π View Full Dashboard | πΊοΈ Development Roadmap
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:
MediationData, SerialMediationData, BootstrapResult)Links: Website | GitHub | Issues
Purpose: Asymmetric confidence intervals via Distribution of Product Status: Stable on CRAN Provides:
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 (handles CRAN + GitHub deps automatically)
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.1.1 ββ
#> β 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?
medfit is 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(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:
The mediationverse is in active development. Contributions are welcome!
Development Workflow:
dev
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:
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: