| Title: | Causal Mediation Analysis with Diagnostics and Sensitivity Analysis |
| Version: | 0.1.1 |
| 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. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/causalfragility-lab/RobustMediate |
| BugReports: | https://github.com/causalfragility-lab/RobustMediate/issues |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1.0) |
| Imports: | cli, ggplot2 (≥ 3.4.0), rlang, scales, stats, broom |
| Suggests: | covr, dplyr, knitr, lme4, pkgdown, rmarkdown, splines, testthat (≥ 3.0.0), tidyr |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| NeedsCompilation: | no |
| Packaged: | 2026-04-09 16:50:37 UTC; Subir |
| Author: | Subir Hait |
| Maintainer: | Subir Hait <haitsubi@msu.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-16 09:12:11 UTC |
RobustMediate: Causal Mediation Analysis with Diagnostics and Sensitivity Analysis
Description
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 byrho. -
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.
Getting started
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)
Sensitivity interpretation
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.
Author(s)
Maintainer: Subir Hait haitsubi@msu.edu (ORCID)
References
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.
See Also
Useful links:
Report bugs at https://github.com/causalfragility-lab/RobustMediate/issues
Compute stabilised IPW weights from a GPS model (continuous treatment)
Description
Implements the stabilised weight formula from Robins, Hernán & Brumback (2000) for continuous exposures:
w_i = \frac{f(X_i \mid \bar{X}, \hat{\sigma}^2_m)}{f(X_i \mid Z_i, \hat{\sigma}^2_c)}
where the numerator is the marginal density of X and the denominator is the conditional density given covariates. Both are evaluated as Gaussian PDFs using the model residual standard deviation.
Weights are trimmed at the 1st and 99th percentile to reduce the influence of extreme propensity scores (positivity violations).
Usage
.compute_gps_weights(gps_model, data, treat_var, trim = c(0.01, 0.99))
Arguments
gps_model |
Fitted GPS model from |
data |
Original data frame. |
treat_var |
Name of the treatment variable (character). |
trim |
Quantile trimming bounds. Default |
Value
Numeric vector of stabilised, trimmed IPW weights (length = nrow(data)).
References
Robins, J. M., Hernán, M. A., & Brumback, B. (2000). Marginal structural models and causal inference in epidemiology. Epidemiology, 11(5), 550–560.
Hirano, K. & Imbens, G. W. (2004). The propensity score with continuous treatments. In A. Gelman & X.-L. Meng (Eds.), Applied Bayesian modeling and causal inference from incomplete-data perspectives (pp. 73–84). Wiley.
Build a prediction data frame for a specific dose value
Description
Returns a copy of data with the treatment variable set to dose, used
to predict counterfactual mediator and outcome means under intervention.
Usage
.dose_df(data, treat_var, dose)
Arguments
data |
Original data frame. |
treat_var |
Treatment variable name. |
dose |
Scalar dose value. |
Value
Data frame with treat_var replaced by dose.
Effective Sample Size for IPW weights
Description
Returns the effective sample size (ESS) of the weighted sample:
ESS = (\sum w_i)^2 / \sum w_i^2
Values well below n indicate severe weighting and likely positivity problems.
Usage
.ess(weights)
Arguments
weights |
Numeric vector of IPW weights. |
Value
Scalar ESS value.
Fit a natural-spline treatment model and return the GPS model object
Description
Fit a natural-spline treatment model and return the GPS model object
Usage
.fit_gps_model(treatment_formula, data, df = 4, family = stats::gaussian())
Arguments
treatment_formula |
Original treatment formula (e.g., |
data |
Data frame. |
df |
Degrees of freedom for |
family |
GLM family. Default |
Value
A fitted glm object with a spline basis for the intercept term
replaced by ns(X, df) on the response side — i.e. the model
X_spline ~ Z where X_spline is the ns-expanded treatment.
In practice we use the approach: model X | Z with a Gaussian GLM using
the raw X, then use the residual SD from that model to form GPS
densities. The spline enters on the covariate side of mediator/outcome
models for the dose-response curve.
Predict mean potential outcome under a dose pair (x, x_ref)
Description
Implements the g-computation identification formula for the NDE and NIE:
NDE(x, x^*) = E[Y(x, M(x^*))] - E[Y(x^*, M(x^*))]
NIE(x, x^*) = E[Y(x, M(x))] - E[Y(x, M(x^*))]
The mediator is predicted at the individual level (not as a scalar mean), correctly marginalising over each person's covariate values.
Usage
.predict_effects(models, data, x, x_ref, treat_var, med_var, out_var)
Arguments
models |
List with elements |
data |
Original data frame. |
x |
Dose value (the "treated" level). |
x_ref |
Reference dose (counterfactual baseline). |
treat_var |
Character. Name of treatment variable. |
med_var |
Character. Name of mediator variable. |
out_var |
Character. Name of outcome variable. |
Value
Named numeric vector: NDE, NIE, TE.
Summarise GPS weight distribution
Description
Prints a compact diagnostic table for IPW weights: range, mean, ESS, and a flag if ESS < 0.4 * n (severe imbalance warning).
Usage
.summarise_weights(weights, n, pathway = "treatment")
Arguments
weights |
Numeric weight vector. |
n |
Original sample size. |
pathway |
Label for the pathway (e.g. |
Value
Invisibly returns a named list with min, max, mean, ess, ess_ratio.
Coerce effects curve to a data frame
Description
Convenience accessor returning the NDE/NIE/TE curve data frame.
Usage
## S3 method for class 'robmedfit'
as.data.frame(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
A data frame with columns dose, estimand, estimate,
lower, upper.
Augment data with fitted values from a robmedfit object (broom-compatible)
Description
Returns the original data augmented with IPW weights, fitted mediator values, and fitted outcome values from the pathway models.
Usage
## S3 method for class 'robmedfit'
augment(x, data = NULL, ...)
Arguments
x |
A |
data |
Optional data frame to augment. Defaults to the data stored
in the outcome model's |
... |
Ignored. |
Value
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.
Examples
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)
Compare Two robmedfit Objects Side by Side
Description
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).
Usage
compare_fits(
fit1,
fit2,
label1 = "Model 1",
label2 = "Model 2",
estimands = c("NDE", "NIE")
)
Arguments
fit1 |
First |
fit2 |
Second |
label1 |
Label for |
label2 |
Label for |
estimands |
Estimands to display. Default |
Value
A ggplot2 object.
Examples
fit_a <- 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, spline_df = 3, R = 50
)
fit_b <- 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, spline_df = 6, R = 50
)
compare_fits(fit_a, fit_b, label1 = "df=3", label2 = "df=6")
Diagnose a robmedfit Object
Description
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.
Usage
diagnose(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
Invisibly returns a list with elements balance, effects,
sensitivity, meditcv, and meditcv_profile.
Pathway Fragility Decomposition Table
Description
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.
Usage
fragility_table(x, alpha = 0.05)
Arguments
x |
A |
alpha |
Significance level. Default |
Value
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.
Examples
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)
Glance at a robmedfit object (broom-compatible)
Description
Returns a one-row summary of the fit: sample size, bootstrap reps, reference dose, percentage mediated, and the two tipping-point sensitivity values.
Usage
## S3 method for class 'robmedfit'
glance(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
A one-row data frame.
Examples
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)
Plot a robmedfit object
Description
Dispatches to the appropriate plot function based on type.
Usage
## S3 method for class 'robmedfit'
plot(
x,
type = c("mediation", "balance", "sensitivity", "meditcv", "meditcv_profile",
"curvature"),
...
)
Arguments
x |
A |
type |
Which plot to produce. One of:
|
... |
Passed to the underlying plot function. |
Value
A ggplot2 object.
Love Plot: Balance Diagnostics for Both Pathways
Description
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.
Usage
plot_balance(x, threshold = 0.1, pathways = c("treatment", "mediator"), ...)
Arguments
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). |
Value
A ggplot2 object. Add layers or themes as usual.
Examples
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
)
plot_balance(fit)
plot_balance(fit, threshold = 0.05, pathways = "treatment")
Plot Dose-Varying Fragility (Curvature-Based Sensitivity)
Description
Three-panel visualisation of dose-varying fragility: (1) effect curve with CI bands and fragility zones, (2) local fragility index, (3) normalised curvature.
Usage
plot_curvature(x, estimand = "NIE", ref_dose = NULL, ...)
Arguments
x |
Data frame from |
estimand |
Label for the estimand. Default |
ref_dose |
Optional reference dose vertical line. |
... |
Ignored. |
Value
A ggplot2 object.
Examples
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)
Dose-Response Curve: Natural Direct and Indirect Effects
Description
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.
Usage
plot_mediation(
x,
estimands = c("NDE", "NIE"),
show_total = FALSE,
facet = FALSE,
...
)
Arguments
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. |
Value
A ggplot2 object.
Examples
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
)
plot_mediation(fit)
plot_mediation(fit, estimands = c("NDE", "NIE", "TE"), facet = TRUE)
Plot medITCV robustness corridors for both mediation pathways
Description
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.
Usage
plot_meditcv(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
A ggplot2 object.
Examples
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)
Plot the medITCV Robustness Profile
Description
Visualises how each pathway's partial correlation is attenuated as confounding impact delta increases, with tipping points and a fragility zone marked.
Usage
plot_meditcv_profile(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
A ggplot2 object.
Examples
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)
Sensitivity Contour Plot: Joint E-value x Rho Display
Description
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.
Usage
plot_sensitivity(
x,
annotate_zero = TRUE,
n_breaks = 12,
palette = "RdYlGn",
...
)
Arguments
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. |
Value
A ggplot2 object.
Examples
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
)
plot_sensitivity(fit)
plot_sensitivity(fit, annotate_zero = FALSE, palette = "PuOr")
Print a meditcv object
Description
Print a meditcv object
Usage
## S3 method for class 'meditcv'
print(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
The input object, invisibly. Called for its side effect of printing a formatted medITCV report to the console.
Print a meditcv_profile object
Description
Print a meditcv_profile object
Usage
## S3 method for class 'meditcv_profile'
print(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
The input object, invisibly. Called for its side effect of printing a formatted medITCV robustness profile to the console.
Print a robmedfit object
Description
Print a robmedfit object
Usage
## S3 method for class 'robmedfit'
print(x, ...)
Arguments
x |
A |
... |
Ignored. |
Value
The input object, invisibly.
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
Robust Causal Mediation Analysis
Description
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.
Usage
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
)
Arguments
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 |
Value
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
rhosensitivity surface.meditcvPathway-specific medITCV object from
sensitivity_meditcv().meditcv_profilemedITCV robustness profile from
sensitivity_meditcv_profile().clusterCluster information, or
NULLif clustering was not used.metaCall, variable names, dose settings, bootstrap settings, and sample information.
Examples
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)
Dose-Varying Fragility: Curvature-Based Sensitivity
Description
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.
Usage
sensitivity_curvature(x, estimand = c("NIE", "NDE", "TE"))
Arguments
x |
A |
estimand |
Which estimand to analyse: |
Value
A data frame with columns dose, estimate, lower, upper,
se_approx, frag_local, curvature, and in_fragility_zone.
See Also
plot_curvature(), sensitivity_meditcv_profile()
Examples
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)
Mediation ITCV (medITCV) for pathway-specific robustness
Description
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 r_{XC} \cdot r_{YC}, to
invalidate inference for each pathway.
Usage
sensitivity_meditcv(x, alpha = 0.05)
Arguments
x |
A |
alpha |
Significance level. Default is |
Value
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.
References
Frank, K. A. (2000). Impact of a confounding variable on a regression coefficient. Sociological Methods & Research, 29(2), 147–194.
See Also
plot_meditcv(), print.meditcv()
Examples
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)
medITCV Robustness Profile: Pathway-Specific Fragility Framework
Description
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.
Usage
sensitivity_meditcv_profile(
x,
alpha = 0.05,
delta_grid = seq(0, 0.5, by = 0.01)
)
Arguments
x |
A |
alpha |
Significance level. Default |
delta_grid |
Numeric vector of confounding impact values over which the
robustness profile is evaluated. Default |
Value
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.
References
Frank, K. A. (2000). Impact of a confounding variable on a regression coefficient. Sociological Methods & Research, 29(2), 147–194.
See Also
sensitivity_meditcv(), plot_meditcv_profile(),
sensitivity_curvature()
Examples
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)
Simulated Mediation Study Data
Description
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.
Usage
sim_mediation
Format
A data frame with 600 rows (30 schools x 20 students) and 7 columns:
- school
Factor. School identifier (30 levels). Use as
cluster_var.- Y
Numeric. End-of-year test score (outcome).
- X
Numeric. Tutoring hours received (continuous treatment, >= 0).
- M
Numeric. Mid-year test score (mediator).
- Z1
Numeric. Prior achievement (continuous covariate).
- Z2
Integer (0/1). Free-lunch status (binary covariate).
- Z3
Numeric. Parental education index (continuous covariate).
True parameter targets
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.
Source
Generated via data-raw/generate_sim_data.R. See that script for
the full data-generating process.
Examples
data(sim_mediation)
str(sim_mediation)
summary(sim_mediation[, c("Y","X","M")])
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)
Spline-Based Generalised Propensity Score for Continuous Treatments
Description
Internal machinery that fits a natural spline treatment model to estimate the generalised propensity score (GPS) for a continuous exposure. This produces more flexible, positivity-respecting stabilised IPW weights than a simple linear model.
Users do not call these functions directly — they are invoked automatically
by robustmediate() when spline_df > 1.
Summary method for robmedfit objects
Description
Summary method for robmedfit objects
Usage
## S3 method for class 'robmedfit'
summary(object, ...)
Arguments
object |
A |
... |
Ignored. |
Value
A list with effect, balance, and sensitivity summaries, invisibly.
Tidy a robmedfit object (broom-compatible)
Description
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.
Usage
## S3 method for class 'robmedfit'
tidy(x, conf.int = TRUE, ...)
Arguments
x |
A |
conf.int |
Logical. Include confidence interval columns? Default |
... |
Ignored. |
Value
A data frame with columns term, estimate, conf.low,
conf.high, and ref_dose.
Examples
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)
Extract Tipping-Point Table
Description
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.
Usage
tipping_table(x)
Arguments
x |
A |
Value
A data frame with columns parameter, tipping_value,
interpretation.