| Title: | Causal Mediation Analysis with Diagnostics and Sensitivity Analysis |
|---|---|
| Description: | Provides tools for causal mediation analysis with continuous treatments using inverse probability weighting (IPW). Estimates natural direct and indirect effects over a user-defined treatment grid and supports flexible dose-response mediation analysis. Includes diagnostic procedures for assessing covariate balance in both treatment and mediator models using standardized mean differences. Implements pathway-specific extensions of the impact threshold for a confounding variable (ITCV; Frank, 2000 <doi:10.1177/0049124100029002001>) adapted to mediation settings. Provides joint sensitivity analysis combining E-values (VanderWeele and Ding, 2017 <doi:10.7326/M16-2607>) and violations of sequential ignorability (Imai, Keele, and Yamamoto, 2010 <doi:10.1214/10-STS321>). Additional utilities include visualization of dose-response mediation functions, robustness profiles, fragility summaries, and formatted outputs for applied research. Supports clustered data structures and multiple outcome families. |
| Authors: | Subir Hait [aut, cre] (ORCID: <https://orcid.org/0009-0004-9871-9677>) |
| Maintainer: | Subir Hait <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-17 07:44:59 UTC |
| Source: | https://github.com/causalfragility-lab/robustmediate |
RobustMediate provides a workflow for causal mediation analysis with continuous treatments using inverse probability weighting (IPW), diagnostic tools, and sensitivity analysis.
Main functions include:
robustmediate() - Fits treatment, mediator, and outcome models and
stores precomputed results for downstream plotting and reporting.
plot_balance() - Displays covariate balance before and after weighting
for both the treatment and mediator pathways using standardized mean
differences.
plot_mediation() - Plots estimated natural direct effects (NDE) and
natural indirect effects (NIE) over the treatment range, with pointwise
uncertainty bands.
plot_sensitivity() - Displays a bivariate sensitivity surface based on
E-values and sequential ignorability violations parameterized by rho.
sensitivity_meditcv() - Computes pathway-specific mediation ITCV
(medITCV) diagnostics based on Frank's impact threshold for a
confounding variable framework.
plot_meditcv() - Displays pathway-specific medITCV robustness
corridors for the a-path and b-path.
diagnose() - Produces a formatted diagnostic summary of balance,
mediation effects, and sensitivity results.
library(RobustMediate) data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2 + Z3, M ~ X + Z1 + Z2 + Z3, Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 500 ) plot(fit) plot(fit, type = "balance") plot(fit, type = "sensitivity") plot(fit, type = "meditcv") diagnose(fit)
The E-value x rho surface is a bivariate robustness display rather than a
single unified causal model. It is intended to help users examine how large
different classes of unmeasured confounding would need to be to attenuate or
nullify the estimated indirect effect.
The mediation ITCV (medITCV) is reported separately for the a-path and
b-path. The indirect-effect summary is interpreted as a minimum-path
robustness bound governed by the weaker pathway.
Maintainer: Subir Hait [email protected] (ORCID)
Frank, K. A. (2000). Impact of a confounding variable on a regression coefficient. Sociological Methods & Research, 29(2), 147–194.
Imai, K., Keele, L., & Yamamoto, T. (2010). Identification, inference, and sensitivity analysis for causal mediation effects. Psychological Methods, 15(4), 309–334.
VanderWeele, T. J., & Ding, P. (2017). Sensitivity analysis in observational research: Introducing the E-value. Annals of Internal Medicine, 167(4), 268–274.
Useful links:
Report bugs at https://github.com/causalfragility-lab/RobustMediate/issues
Convenience accessor returning the NDE/NIE/TE curve data frame.
## S3 method for class 'robmedfit' as.data.frame(x, ...)## S3 method for class 'robmedfit' as.data.frame(x, ...)
x |
A |
... |
Ignored. |
A data frame with columns dose, estimand, estimate,
lower, upper.
Returns the original data augmented with IPW weights, fitted mediator values, and fitted outcome values from the pathway models.
## S3 method for class 'robmedfit' augment(x, data = NULL, ...)## S3 method for class 'robmedfit' augment(x, data = NULL, ...)
x |
A |
data |
Optional data frame to augment. Defaults to the data stored
in the outcome model's |
... |
Ignored. |
The original data frame with additional columns:
.ipw_weightStabilised inverse probability weights.
.fitted_mediatorPredicted mediator values.
.fitted_outcomePredicted outcome values.
.resid_mediatorResiduals from the mediator model.
.resid_outcomeResiduals from the outcome model.
fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) aug <- augment(fit) hist(aug$.ipw_weight)fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) aug <- augment(fit) hist(aug$.ipw_weight)
Overlays the NDE/NIE/TE curves from two robmedfit objects on the same
panel. Useful for sensitivity comparisons (e.g. different spline degrees,
trimming thresholds, or model specifications).
compare_fits( fit1, fit2, label1 = "Model 1", label2 = "Model 2", estimands = c("NDE", "NIE") )compare_fits( fit1, fit2, label1 = "Model 1", label2 = "Model 2", estimands = c("NDE", "NIE") )
fit1 |
First |
fit2 |
Second |
label1 |
Label for |
label2 |
Label for |
estimands |
Estimands to display. Default |
A ggplot2 object.
## Not run: fit_a <- robustmediate(X~Z, M~X+Z, Y~X+M+Z, data=dat, spline_df=3, R=200) fit_b <- robustmediate(X~Z, M~X+Z, Y~X+M+Z, data=dat, spline_df=6, R=200) compare_fits(fit_a, fit_b, label1="df=3", label2="df=6") ## End(Not run)## Not run: fit_a <- robustmediate(X~Z, M~X+Z, Y~X+M+Z, data=dat, spline_df=3, R=200) fit_b <- robustmediate(X~Z, M~X+Z, Y~X+M+Z, data=dat, spline_df=6, R=200) compare_fits(fit_a, fit_b, label1="df=3", label2="df=6") ## End(Not run)
Prints a formatted diagnostics report covering balance, mediation effects, and sensitivity robustness. The output is structured so that it can be used directly (or with minimal editing) in the Results section of an applied paper. Returns the underlying results invisibly.
diagnose(x, ...)diagnose(x, ...)
x |
A |
... |
Ignored. |
Invisibly returns a list with elements balance, effects,
sensitivity, meditcv, and meditcv_profile.
Returns a publication-ready table decomposing indirect-effect robustness into pathway-specific components. Columns follow the medITCV reporting convention: pathway, coefficient, SE, t, df, observed partial r, critical r, medITCV, medITCV%, fragility classification, and tipping-point confounder r.
fragility_table(x, alpha = 0.05)fragility_table(x, alpha = 0.05)
x |
A |
alpha |
Significance level. Default |
A data frame with three rows (a-path, b-path, indirect effect) and
columns pathway, coefficient, SE, t_stat, df, r_obs,
r_crit, medITCV, medITCV_pct, fragility,
tipping_r_confounder, and bottleneck.
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) fragility_table(fit)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) fragility_table(fit)
Returns a one-row summary of the fit: sample size, bootstrap reps, reference dose, percentage mediated, and the two tipping-point sensitivity values.
## S3 method for class 'robmedfit' glance(x, ...)## S3 method for class 'robmedfit' glance(x, ...)
x |
A |
... |
Ignored. |
A one-row data frame.
fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) glance(fit)fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) glance(fit)
Produces a publication-ready love plot showing standardised mean differences (SMDs) before and after IPW weighting for both the treatment and mediator pathways — stacked vertically in a single panel. This dual-pathway display is unique to RobustMediate; no other mediation package provides it.
plot_balance(x, threshold = 0.1, pathways = c("treatment", "mediator"), ...)plot_balance(x, threshold = 0.1, pathways = c("treatment", "mediator"), ...)
x |
A |
threshold |
Absolute SMD threshold displayed as dashed reference lines.
Reviewers conventionally accept |SMD| < 0.10. Default |
pathways |
Character vector indicating which pathways to show.
Options: |
... |
Ignored (for S3 consistency). |
A ggplot2 object. Add layers or themes as usual.
## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_balance(fit) plot_balance(fit, threshold = 0.05, pathways = "treatment") ## End(Not run)## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_balance(fit) plot_balance(fit, threshold = 0.05, pathways = "treatment") ## End(Not run)
Three-panel visualisation of dose-varying fragility: (1) effect curve with CI bands and fragility zones, (2) local fragility index, (3) normalised curvature.
plot_curvature(x, estimand = "NIE", ref_dose = NULL, ...)plot_curvature(x, estimand = "NIE", ref_dose = NULL, ...)
x |
Data frame from |
estimand |
Label for the estimand. Default |
ref_dose |
Optional reference dose vertical line. |
... |
Ignored. |
A ggplot2 object.
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) curv <- sensitivity_curvature(fit) plot_curvature(curv, ref_dose = fit$meta$ref_dose)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) curv <- sensitivity_curvature(fit) plot_curvature(curv, ref_dose = fit$meta$ref_dose)
Plots NDE, NIE, and (optionally) total effect as smooth spline curves over the full range of treatment values, with pointwise bootstrap confidence bands. This is the signature visualisation of RobustMediate and is publication-ready out of the box.
plot_mediation( x, estimands = c("NDE", "NIE"), show_total = FALSE, facet = FALSE, ... )plot_mediation( x, estimands = c("NDE", "NIE"), show_total = FALSE, facet = FALSE, ... )
x |
A |
estimands |
Character vector of estimands to display.
Any subset of |
show_total |
Shorthand for adding |
facet |
Logical. Split estimands into separate facets? Default |
... |
Ignored. |
A ggplot2 object.
## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_mediation(fit) plot_mediation(fit, estimands = c("NDE","NIE","TE"), facet = TRUE) ## End(Not run)## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_mediation(fit) plot_mediation(fit, estimands = c("NDE","NIE","TE"), facet = TRUE) ## End(Not run)
Produces a two-panel pathway-specific robustness corridor plot showing the observed partial correlation, critical partial correlation threshold, medITCV corridor, and benchmark confounder impacts for each pathway.
plot_meditcv(x, ...)plot_meditcv(x, ...)
x |
A |
... |
Ignored. |
A ggplot2 object.
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) med <- sensitivity_meditcv(fit) plot_meditcv(med)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) med <- sensitivity_meditcv(fit) plot_meditcv(med)
Visualises how each pathway's partial correlation is attenuated as confounding impact delta increases, with tipping points and a fragility zone marked.
plot_meditcv_profile(x, ...)plot_meditcv_profile(x, ...)
x |
A |
... |
Ignored. |
A ggplot2 object.
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) mp <- sensitivity_meditcv_profile(fit) plot_meditcv_profile(mp)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) mp <- sensitivity_meditcv_profile(fit) plot_meditcv_profile(mp)
Renders the novel bivariate robustness map unique to RobustMediate: a 2-D heatmap where the x-axis is the E-value (VanderWeele-style unmeasured treatment–outcome confounding) and the y-axis is Imai's sequential-ignorability violation parameter rho. Contour lines show where the mediation effect crosses zero, so readers can judge robustness to two different sensitivity dimensions simultaneously.
This visualisation does not exist elsewhere in the R ecosystem. The correct interpretation is as a bivariate robustness display, not a joint causal model — see the package paper for theoretical justification.
plot_sensitivity( x, annotate_zero = TRUE, n_breaks = 12, palette = "RdYlGn", ... )plot_sensitivity( x, annotate_zero = TRUE, n_breaks = 12, palette = "RdYlGn", ... )
x |
A |
annotate_zero |
Logical. Draw a bold dashed zero-crossing contour?
Default |
n_breaks |
Number of fill colour breaks in the heatmap. Default |
palette |
RColorBrewer palette name. Default |
... |
Ignored. |
A ggplot2 object.
## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_sensitivity(fit) plot_sensitivity(fit, annotate_zero = FALSE, palette = "PuOr") ## End(Not run)## Not run: fit <- robustmediate(X ~ Z, M ~ X + Z, Y ~ X + M + Z, data = mydata) plot_sensitivity(fit) plot_sensitivity(fit, annotate_zero = FALSE, palette = "PuOr") ## End(Not run)
Dispatches to the appropriate plot function based on type.
## S3 method for class 'robmedfit' plot( x, type = c("mediation", "balance", "sensitivity", "meditcv", "meditcv_profile", "curvature"), ... )## S3 method for class 'robmedfit' plot( x, type = c("mediation", "balance", "sensitivity", "meditcv", "meditcv_profile", "curvature"), ... )
x |
A |
type |
Which plot to produce. One of:
|
... |
Passed to the underlying plot function. |
A ggplot2 object.
Print a meditcv object
## S3 method for class 'meditcv' print(x, ...)## S3 method for class 'meditcv' print(x, ...)
x |
A |
... |
Ignored. |
The input object, invisibly. Called for its side effect of printing a formatted medITCV report to the console.
Print a meditcv_profile object
## S3 method for class 'meditcv_profile' print(x, ...)## S3 method for class 'meditcv_profile' print(x, ...)
x |
A |
... |
Ignored. |
The input object, invisibly. Called for its side effect of printing a formatted medITCV robustness profile to the console.
Print a robmedfit object
## S3 method for class 'robmedfit' print(x, ...)## S3 method for class 'robmedfit' print(x, ...)
x |
A |
... |
Ignored. |
The input object, invisibly.
Fits treatment, mediator, and outcome models for causal mediation analysis
with continuous treatments using inverse probability weighting (IPW), and
returns a precomputed robmedfit object for plotting and diagnostics.
robustmediate( treatment_formula, mediator_formula, outcome_formula, data, ref_dose = NULL, dose_grid = NULL, R = 500, alpha = 0.05, covariates = NULL, cluster_var = NULL, family_treatment = stats::gaussian(), family_mediator = stats::gaussian(), family_outcome = stats::gaussian(), spline_df = 4, evalue_seq = seq(1, 10, by = 0.25), rho_seq = seq(-1, 1, by = 0.05), verbose = TRUE )robustmediate( treatment_formula, mediator_formula, outcome_formula, data, ref_dose = NULL, dose_grid = NULL, R = 500, alpha = 0.05, covariates = NULL, cluster_var = NULL, family_treatment = stats::gaussian(), family_mediator = stats::gaussian(), family_outcome = stats::gaussian(), spline_df = 4, evalue_seq = seq(1, 10, by = 0.25), rho_seq = seq(-1, 1, by = 0.05), verbose = TRUE )
treatment_formula |
Formula for the treatment model
(for example, |
mediator_formula |
Formula for the mediator model
(for example, |
outcome_formula |
Formula for the outcome model
(for example, |
data |
A data frame containing all analysis variables. |
ref_dose |
Reference dose value. Defaults to the sample mean of the treatment variable. |
dose_grid |
Numeric vector of dose values over which NDE, NIE, and TE are evaluated. Defaults to 100 evenly spaced points across the observed treatment range. |
R |
Number of bootstrap replicates. Default is |
alpha |
Significance level. Default is |
covariates |
Covariate names for balance diagnostics. If |
cluster_var |
Optional clustering variable name. |
family_treatment |
GLM family for the treatment model.
Default is |
family_mediator |
GLM family for the mediator model.
Default is |
family_outcome |
GLM family for the outcome model.
Default is |
spline_df |
Degrees of freedom for spline-based effect summaries.
Default is |
evalue_seq |
Sequence of E-values used to build the sensitivity surface.
Default is |
rho_seq |
Sequence of |
verbose |
Logical; if |
An object of class "robmedfit" containing:
modelsFitted treatment, mediator, and outcome models.
balanceBalance statistics before and after weighting.
effectsDose-response summaries for NDE, NIE, and TE, including bootstrap intervals.
sensitivityBivariate E-value and rho sensitivity surface.
meditcvPathway-specific medITCV object from
sensitivity_meditcv().
meditcv_profilemedITCV robustness profile from
sensitivity_meditcv_profile().
clusterCluster information, or NULL if clustering was not
used.
metaCall, variable names, dose settings, bootstrap settings, and sample information.
n <- 400 Z1 <- rnorm(n) Z2 <- rbinom(n, 1, 0.5) X <- 0.5 * Z1 + 0.3 * Z2 + rnorm(n) M <- 0.4 * X + 0.2 * Z1 + rnorm(n) Y <- 0.3 * X + 0.5 * M + 0.1 * Z1 + rnorm(n) dat <- data.frame(Y, X, M, Z1, Z2) fit <- robustmediate( treatment_formula = X ~ Z1 + Z2, mediator_formula = M ~ X + Z1 + Z2, outcome_formula = Y ~ X + M + Z1 + Z2, data = dat, R = 100 ) print(fit)n <- 400 Z1 <- rnorm(n) Z2 <- rbinom(n, 1, 0.5) X <- 0.5 * Z1 + 0.3 * Z2 + rnorm(n) M <- 0.4 * X + 0.2 * Z1 + rnorm(n) Y <- 0.3 * X + 0.5 * M + 0.1 * Z1 + rnorm(n) dat <- data.frame(Y, X, M, Z1, Z2) fit <- robustmediate( treatment_formula = X ~ Z1 + Z2, mediator_formula = M ~ X + Z1 + Z2, outcome_formula = Y ~ X + M + Z1 + Z2, data = dat, R = 100 ) print(fit)
Computes the fragility curvature of the mediation effect across the full treatment dose grid. Returns local fragility index, numerical curvature of the effect curve, and a fragility zone flag at each dose value.
sensitivity_curvature(x, estimand = c("NIE", "NDE", "TE"))sensitivity_curvature(x, estimand = c("NIE", "NDE", "TE"))
x |
A |
estimand |
Which estimand to analyse: |
A data frame with columns dose, estimate, lower, upper,
se_approx, frag_local, curvature, and in_fragility_zone.
plot_curvature(), sensitivity_meditcv_profile()
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) curv <- sensitivity_curvature(fit, estimand = "NIE") plot_curvature(curv)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) curv <- sensitivity_curvature(fit, estimand = "NIE") plot_curvature(curv)
Computes a mediation-specific extension of Kenneth Frank's (2000) Impact Threshold for a Confounding Variable (ITCV) for both pathways of a mediation model:
a-path: treatment -> mediator
b-path: mediator -> outcome (controlling for treatment)
The mediation ITCV (medITCV) quantifies how strong an unmeasured confounder
would need to be, in terms of the product , to
invalidate inference for each pathway.
sensitivity_meditcv(x, alpha = 0.05)sensitivity_meditcv(x, alpha = 0.05)
x |
A |
alpha |
Significance level. Default is |
An object of class "meditcv": a named list with elements
a_path, b_path, indirect, and alpha. Each pathway element
contains the observed partial correlation, critical partial correlation,
medITCV value, and benchmark confounder impacts.
Frank, K. A. (2000). Impact of a confounding variable on a regression coefficient. Sociological Methods & Research, 29(2), 147–194.
plot_meditcv(), print.meditcv()
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) med <- sensitivity_meditcv(fit) print(med) plot_meditcv(med)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) med <- sensitivity_meditcv(fit) print(med) plot_meditcv(med)
Implements the medITCV robustness profile, a formal extension of Frank's ITCV to causal mediation. Computes pathway-specific fragility thresholds, applies the minimum robustness principle, and identifies the bottleneck pathway that governs indirect-effect fragility.
sensitivity_meditcv_profile( x, alpha = 0.05, delta_grid = seq(0, 0.5, by = 0.01) )sensitivity_meditcv_profile( x, alpha = 0.05, delta_grid = seq(0, 0.5, by = 0.01) )
x |
A |
alpha |
Significance level. Default |
delta_grid |
Numeric vector of confounding impact values over which the
robustness profile is evaluated. Default |
An object of class "meditcv_profile": a named list with elements
a_path, b_path, meditcv_indirect, bottleneck,
robustness_profile, fragility_ratio, meditcv_detail, and alpha.
Frank, K. A. (2000). Impact of a confounding variable on a regression coefficient. Sociological Methods & Research, 29(2), 147–194.
sensitivity_meditcv(), plot_meditcv_profile(),
sensitivity_curvature()
data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) mp <- sensitivity_meditcv_profile(fit) print(mp) plot_meditcv_profile(mp)data(sim_mediation) fit <- robustmediate( X ~ Z1 + Z2, M ~ X + Z1 + Z2, Y ~ X + M + Z1 + Z2, data = sim_mediation, R = 20, verbose = FALSE ) mp <- sensitivity_meditcv_profile(fit) print(mp) plot_meditcv_profile(mp)
A synthetic dataset mimicking a clustered education study with a continuous treatment (tutoring hours), a continuous mediator (mid-year test score), and a continuous outcome (end-of-year test score). Designed to illustrate RobustMediate with realistic effect sizes and non-trivial confounding.
sim_mediationsim_mediation
A data frame with 600 rows (30 schools x 20 students) and 7 columns:
Factor. School identifier (30 levels). Use as cluster_var.
Numeric. End-of-year test score (outcome).
Numeric. Tutoring hours received (continuous treatment, >= 0).
Numeric. Mid-year test score (mediator).
Numeric. Prior achievement (continuous covariate).
Integer (0/1). Free-lunch status (binary covariate).
Numeric. Parental education index (continuous covariate).
The data-generating process sets:
NDE (X → Y direct path) ~= 0.25
NIE (X → M → Y path) ~= 0.35
TE ~= 0.60
% mediated ~= 58%
Use these as a ground truth to assess estimation accuracy.
Generated via data-raw/generate_sim_data.R. See that script for
the full data-generating process.
data(sim_mediation) str(sim_mediation) summary(sim_mediation[, c("Y","X","M")]) ## Not run: fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, cluster_var = "school", R = 500 ) diagnose(fit) ## End(Not run)data(sim_mediation) str(sim_mediation) summary(sim_mediation[, c("Y","X","M")]) ## Not run: fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, cluster_var = "school", R = 500 ) diagnose(fit) ## End(Not run)
Summary method for robmedfit objects
## S3 method for class 'robmedfit' summary(object, ...)## S3 method for class 'robmedfit' summary(object, ...)
object |
A |
... |
Ignored. |
A list with effect, balance, and sensitivity summaries, invisibly.
Returns a tidy data frame of the mediation effect estimates (NDE, NIE, TE)
at the reference dose, with confidence intervals. Compatible with
broom::tidy() and the broader tidymodels ecosystem.
## S3 method for class 'robmedfit' tidy(x, conf.int = TRUE, ...)## S3 method for class 'robmedfit' tidy(x, conf.int = TRUE, ...)
x |
A |
conf.int |
Logical. Include confidence interval columns? Default |
... |
Ignored. |
A data frame with columns term, estimate, conf.low,
conf.high, and ref_dose.
fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) tidy(fit)fit <- robustmediate( treatment_formula = X ~ Z1 + Z2 + Z3, mediator_formula = M ~ X + Z1 + Z2 + Z3, outcome_formula = Y ~ X + M + Z1 + Z2 + Z3, data = sim_mediation, R = 50 ) tidy(fit)
Returns a formatted data frame of sensitivity tipping points: the minimum E-value and minimum |rho| required to nullify the NIE. Designed for direct insertion into a table in a manuscript.
tipping_table(x)tipping_table(x)
x |
A |
A data frame with columns parameter, tipping_value,
interpretation.