This vignette documents the identification assumptions behind the MSM/IPW workflow and shows how to run the causal recovery harness added for regression testing and simulation-based checks.
In this workflow, interpretation of weighted outcome contrasts depends on:
Use diagnostics to stress-test these assumptions:
ild_msm_balance() for weighted SMD checks;ild_ipw_ess() for effective sample size;ild_msm_overlap_plot() for propensity overlap;ild_diagnose(..., balance = TRUE, ...) for integrated
causal diagnostics + guardrails.library(tidyILD)
d <- ild_msm_simulate_scenario(n_id = 100, n_obs_per = 12, true_ate = 0.5, seed = 101)
d <- ild_center(d, y)
hist_spec <- ild_msm_history_spec(vars = c("stress", "trt"), lags = 1:2)
d <- ild_build_msm_history(d, hist_spec)
estimand <- ild_msm_estimand(type = "ate", regime = "static", treatment = "trt")
fit_obj <- ild_msm_fit(
estimand = estimand,
data = d,
outcome_formula = y ~ y_bp + y_wp + stress + trt + (1 | id),
history = ~ stress_lag1 + trt_lag1,
predictors_censor = "stress",
inference = "bootstrap",
n_boot = 200,
strict_inference = FALSE
)
fit_obj
fit_obj$inference$status
fit_obj$inference$reasonrec <- ild_msm_recovery(
n_sim = 100,
n_id = 120,
n_obs_per = 12,
true_ate = 0.5,
n_boot = 200,
inference = "bootstrap",
seed = 1001,
censoring = TRUE
)
rec$summary
rec$summary_by_scenarioScenario-grid validation (positivity stress and treatment-model misspecification):
grid <- tibble::tibble(
scenario_id = c("baseline", "positivity_stress", "misspecified_treatment"),
positivity_stress = c(1, 1.8, 1),
misspec_treatment_model = c(FALSE, FALSE, TRUE)
)
rec_grid <- ild_msm_recovery(
n_sim = 50,
n_id = 120,
n_obs_per = 12,
true_ate = 0.5,
n_boot = 200,
inference = "bootstrap",
scenario_grid = grid,
seed = 1101
)
rec_grid$summary_by_scenarioInterpretation:
bias and rmse target point-estimate
recovery;coverage targets interval calibration under the chosen
inference mode;ess_mean / ess_min and
weight_ratio_median summarize positivity stress.inference = "robust" can degrade on weighted
lmer paths where robust variance is not supported.ild_msm_fit() records this explicitly in:
fit_obj$inference$status ("ok",
"degraded", "unsupported"),fit_obj$inference$reason (machine-readable reason
code),fit_obj$inference$message (user-facing
explanation).strict_inference = TRUE to error instead of
degrading.ild_msm_bootstrap(..., weight_policy = "reestimate_weights")
when you want first-stage weight uncertainty represented in
intervals.ild_msm_fit and
will report degraded status unless strict mode is enabled.?ild_msm_inference).