sbw
Computes stable balancing weights to remove covariate imbalance between treatment and control arms, producing validated ATT/ATE/ATC estimates and diagnostic evidence for causal decisions.
Instructions
Stable Balancing Weights (Zubizarreta 2015) with optional ATT/ATE Validation: certified parity evidence. Assumptions: Unconfoundedness: treatment is as-good-as-random given the measured covariates; Overlap / common support: every unit has a non-degenerate probability of each treatment; The covariate set blocks all back-door paths. Pre-conditions: Pre-treatment covariates measured for treated and control units; A binary (or low-cardinality) treatment indicator; Sufficient covariate overlap between treatment arms. Failure modes: Poor overlap -- extreme propensity scores or few acceptable matches -> Trim or restrict to the common-support region and report the discarded units; Covariate imbalance remains after matching/weighting -> Re-specify the balancing model (CBPS, entropy balancing) and re-check standardized mean differences. Alternatives: sp.propensity_score, sp.cbps, sp.ebalance, sp.dml. Typical minimum N: 200.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| y | No | Outcome column. If provided, a weighted ATT/ATE estimate with HC-robust SE is attached to the returned :class:`SBWResult`. | |
| alpha | No | Significance level for inference on the outcome. | |
| delta | No | Balance tolerance. With ``tolerance_scale='sd'`` the constraint is ``|mean_T(X_j) - weighted mean_C(X_j)| <= delta_j * sd(X_j)``. | |
| treat | Yes | Binary 0/1 treatment indicator column. | |
| 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 |
| estimand | No | ``'att'`` reweights controls to match treated means (standard); ``'atc'`` reweights treated to match control means; ``'ate'`` reweights each group to match the pooled means. | att |
| 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://. | |
| objective | No | Dispersion objective. ``'variance'`` minimises Sigma w_i2; ``'entropy'`` minimises Sigma w_i log(n * w_i) (KL from uniform). | variance |
| 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 | Yes | Columns whose means must be balanced. | |
| 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. | |
| solver_options | No | Passed to ``scipy.optimize.minimize``. | |
| include_squares | No | Also balance second-moments (w_j2 columns). | |
| tolerance_scale | No | Standard deviation ``delta`` is quoted in. ``'sd'`` is the full-sample sd; ``'target'`` the sd of the group being matched to and ``'group'`` the sd of the group being reweighted, matching ``sbw::sbw``'s ``bal_std="target"`` / ``"group"``; ``'raw'`` is unstandardised. | sd |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||