mediate
Decompose total treatment effect into natural direct and indirect effects using mediation analysis. Requires binary treatment, mediator, and outcome; supports bootstrap confidence intervals.
Instructions
Mediation analysis (Imai-Keele-Tingley 2010). Decomposes the total effect into natural direct effect (NDE) and natural indirect effect (NIE) via an interventional or sequential-ignorability identification strategy. Validation: certified parity evidence. Assumptions: Sequential ignorability: (Y(t,m), M(t)) perp T | X; Y(t,m) perp M | T, X; No post-treatment confounder of the mediator-outcome relationship (classical Imai-Keele-Tingley); SUTVA on both mediator and outcome. Pre-conditions: binary treatment 0/1; mediator is a post-treatment variable causally between treat and y; pre-treatment covariates capture confounding for T-Y, M-Y, T-M. Failure modes: NDE + NIE do not sum to total effect (difference vs product decomposition) -> Nonlinear / interactive mediator model -- use sp.mediate_interventional or four-way decomposition; Sensitivity to unobserved T-M / M-Y confounder unknown -> Always report sp.mediate_sensitivity (Imai-Keele-Yamamoto rho bound); Post-treatment confounder L suspected -> Use sp.four_way_decomposition (VanderWeele 2014) which handles L. Alternatives: sp.mediate_sensitivity, sp.mediate_interventional, sp.four_way_decomposition, sp.proximal. Typical minimum N: 500.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| y | Yes | Outcome | |
| alpha | No | Significance level for confidence intervals and tests. | |
| treat | Yes | Binary treatment | |
| detail | No | Payload depth: 'minimal' (~150 tokens) for sub-step calls where only the point estimate is needed; 'standard' (~1K tokens) for diagnostics + coefficient table; 'agent' (~2K tokens, default) adds violations / next_steps / suggested_functions so the LLM can plan its next call without another round-trip. | agent |
| n_boot | No | Bootstrap reps for NDE/NIE CIs | |
| mediator | Yes | Mediator variable | |
| as_handle | No | If true, cache the fitted result on the server and return result_id + result_uri alongside the JSON payload so a subsequent tools/call can chain without re-running. | |
| data_path | Yes | Absolute path or URL to a data file. Supported: .csv / .tsv / .txt (delimited), .parquet / .pq, .feather / .arrow, .xlsx / .xls, .dta (Stata), .json / .jsonl. Schemes: file://, s3://, gs://, https://. | |
| result_id | No | Optional handle to a previously-fitted result (returned by an earlier call when as_handle=true). Tools that operate on a fitted object accept this in place of re-supplying data_path + columns. | |
| covariates | No | Pre-treatment confounders | |
| data_columns | No | Optional column projection. Parquet/Feather/Stata loaders honour this for fast partial reads. | |
| data_sample_n | No | Optional uniform random subsample size (seed=0, deterministic) — useful on huge panels. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||