Skip to content

Commit 7fe55e5

Browse files
refactor(core): extract shared safe_logit_fit/predict primitive (CLAUDE.md §4)
front_door and principal_strat carried byte-identical statsmodels-logit wrappers (fit + predict). Consolidate into core/_glm_fit.py; the module-level _logit_fit/_logit_safe/_logit_predict names stay as thin delegators (mockable). Behavior-preserving (28 tests incl. A1 fallback tests pass). The custom-IRLS / sklearn logits in censoring/gformula/longitudinal/ivmte_lp/tmle are deliberately different solvers and are left for a parity-quiet unification. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 80d6b50 commit 7fe55e5

15 files changed

Lines changed: 448 additions & 38 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ With optional dependencies:
895895
```bash
896896
pip install statspai[plotting] # matplotlib, seaborn
897897
pip install statspai[fixest] # pyfixest for high-dimensional FE
898+
pip install statspai[bayes] # PyMC + ArviZ for Bayesian estimators
899+
pip install statspai[tune] # Optuna for tuned meta-learners / Auto-CATE
900+
pip install statspai[rd-cct] # rdrobust for exact CCT RD parity
898901
pip install statspai[deepiv] # PyTorch for DeepIV
899902
pip install statspai[neural] # PyTorch for TARNet/CFRNet/DragonNet
900903
pip install statspai[text] # sentence-transformers for sbert text embeddings
@@ -909,7 +912,7 @@ installation.
909912

910913
**Requirements:** Python >= 3.9
911914

912-
**Core dependencies:** NumPy, SciPy, Pandas, statsmodels, scikit-learn, linearmodels, patsy, openpyxl, python-docx
915+
**Core dependencies:** NumPy, SciPy, Pandas, statsmodels, scikit-learn, linearmodels, formulaic, numba, patsy, openpyxl, xlsxwriter, python-docx, tabulate
913916

914917
---
915918

SUPPORT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For "**how do I**", "**which estimator should I use**", "**why does my result di
88

99
- **GitHub Discussions**<https://github.com/brycewang-stanford/StatsPAI/discussions>
1010
- Best place for open-ended questions, methodological discussion, and Q&A that may help future users.
11-
- Please search existing threads first — many common questions are already answered.
11+
- Please search existing threads first — many common questions may already be answered.
1212

1313
When asking, please include:
1414

docs/getting-started.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ backends only when you want them:
1616
```bash
1717
pip install "StatsPAI[plotting]" # matplotlib / seaborn / plotly figures
1818
pip install "StatsPAI[bayes]" # PyMC + ArviZ for Bayesian estimators
19+
pip install "StatsPAI[tune]" # Optuna for tuned meta-learners / Auto-CATE
20+
pip install "StatsPAI[rd-cct]" # rdrobust for exact CCT RD parity
1921
pip install "StatsPAI[performance]"# JAX backend for fast feols / bootstrap
2022
```
2123

docs/joss_reviewer_guide.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ checking representative functionality without running the full test suite.
88
StatsPAI is a Python package for causal inference and applied econometrics. The
99
core package is pip-installable, ships small teaching datasets, and can be
1010
tested offline. Optional extras cover plotting, pyfixest integration, neural
11-
causal estimators, JAX-backed workloads, and Bayesian workflows.
11+
causal estimators, JAX-backed workloads, Bayesian workflows, Optuna tuning,
12+
and exact Calonico-Cattaneo-Titiunik RD parity via `rdrobust`.
1213

1314
## Install
1415

@@ -25,6 +26,12 @@ For review from a repository checkout:
2526
python -m pip install -e ".[dev,plotting]"
2627
```
2728

29+
The core install declares the runtime dependencies in `pyproject.toml`:
30+
NumPy, SciPy, Pandas, statsmodels, scikit-learn, linearmodels, formulaic,
31+
numba, patsy, openpyxl, xlsxwriter, python-docx, and tabulate. Optional extras
32+
are named `plotting`, `fixest`, `deepiv`, `neural`, `performance`, `bayes`,
33+
`tune`, `rd-cct`, `text`, and `docs`.
34+
2835
## Smoke Test
2936

3037
```bash

docs/joss_validation_dossier.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ and reviewer-verifiable examples rather than published downstream citations.
8181
## Public Distribution And Community Signals
8282

8383
StatsPAI is publicly distributed on PyPI and archived on Zenodo. The GitHub
84-
repository has public stars, forks, issue templates, discussions links,
85-
contribution instructions, support instructions, release notes, and CI status
86-
checks. These are treated as community-readiness and public-interest signals,
87-
not as evidence of independent scholarly adoption.
84+
repository has public stars, forks, issue templates, a dedicated support
85+
discussion channel, contribution instructions, support instructions, release
86+
notes, and CI status checks. These are treated as community-readiness and
87+
public-interest signals, not as evidence of independent scholarly adoption.
8888

8989
The public fork list is available through GitHub at
9090
<https://github.com/brycewang-stanford/StatsPAI/forks>. As of 2026-05-29, the

docs/reference/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace. Reference pages are grouped by methodological area:
66
| Area | Page | Flagship functions |
77
| --- | --- | --- |
88
| Difference-in-differences | [did](did.md) | `callaway_santanna`, `aggte`, `sun_abraham`, `bjs`, `dcdh`, `etwfe`, `cs_report`, `honest_did`, `breakdown_m` |
9+
| Instrumental variables | [iv](iv.md) | `iv`, `ivreg`, `iv_diag`, `iv_compare`, `kernel_iv`, `continuous_iv_late`, `ivdml`, `npiv`, `mte` |
10+
| Matching / balancing | [matching](matching.md) | `match`, `ebalance`, `cbps`, `genmatch`, `sbw`, `overlap_weights`, `balance_diagnostics`, `love_plot` |
911
| Regression discontinuity | [rd](rd.md) | `rdrobust`, `rd2d`, `rkd`, `rdit`, `rdhonest`, `rdrandinf`, `rdpower`, `rd_forest`, `rdsummary` |
1012
| Synthetic control | [synth](synth.md) | `synth`, `sdid`, `ascm`, `bayesian_synth`, `bsts_synth`, `penscm`, `synth_compare`, `synth_recommend`, `synth_report` |
1113
| Decomposition | [decomposition](decomposition.md) | `decompose`, `oaxaca`, `gelbach`, `ffl_decompose`, `dfl_decompose`, `machado_mata`, `shapley_inequality`, `gap_closing` |
@@ -18,6 +20,7 @@ namespace. Reference pages are grouped by methodological area:
1820
| Spatial econometrics | [spatial](spatial.md) | `spatial_weights`, `moran_i`, `geary_c`, `sar`, `sem`, `sdm`, `gwr`, `mgwr`, `spatial_panel`, `spatial_did` |
1921
| Time series | [timeseries](timeseries.md) | `arima`, `var`, `bvar`, `garch`, `cointegration`, `local_projections`, `structural_break` |
2022
| Survival | [survival](survival.md) | `cox`, `aft`, `frailty`, `kaplan_meier`, `log_rank_test`, `competing_risks` |
23+
| Agent-native workflows | [smart](smart.md) | `detect_design`, `preflight`, `audit`, `examples`, `session`, `brief`, `bib_for` |
2124

2225
Every result object follows the same contract:
2326

docs/reference/iv.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,33 @@ The core requirements are **relevance** (a non-zero first stage),
106106
**exclusion** (the instrument affects the outcome only through the treatment),
107107
**exogeneity / independence** of the instrument, and — for a LATE
108108
interpretation — **monotonicity** (no defiers).
109+
110+
## Method-level API
111+
112+
The public top-level entry points used in examples and agent workflows are
113+
documented here explicitly; the exhaustive namespace listing remains available
114+
under [Full API reference -> iv](api/iv.md).
115+
116+
### `sp.iv(...)`
117+
118+
::: statspai.regression.iv.iv
119+
120+
### `sp.ivreg(...)`
121+
122+
::: statspai.regression.iv.ivreg
123+
124+
### `sp.kernel_iv(...)`
125+
126+
::: statspai.iv.kernel_iv
127+
128+
### `sp.continuous_iv_late(...)`
129+
130+
::: statspai.iv.continuous_iv_late
131+
132+
### `sp.iv_diag(...)`
133+
134+
::: statspai.iv.iv_diag
135+
136+
### `sp.iv_compare(...)`
137+
138+
::: statspai.iv.iv_compare

docs/reference/matching.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Matching and balancing
2+
3+
`statspai.matching` covers classical matching, balancing weights, diagnostics,
4+
and Love plots behind a unified `sp.match(...)` dispatcher plus standalone
5+
estimator functions for power users.
6+
7+
See also the decision guide:
8+
[Choosing a matching estimator](../guides/choosing_matching_estimator.md), and
9+
the exhaustive auto-generated listing under
10+
[Full API reference -> matching](api/matching.md).
11+
12+
## Choosing an entry point
13+
14+
```python
15+
import statspai as sp
16+
17+
# Default nearest-neighbour propensity-score matching.
18+
r = sp.match(
19+
df,
20+
y="earnings",
21+
treat="training",
22+
covariates=["age", "education", "earnings_pre"],
23+
)
24+
25+
# Balancing-weight estimators are available through method=...
26+
r_ebal = sp.match(df, y="earnings", treat="training",
27+
covariates=["age", "education"], method="ebalance")
28+
29+
# ...or as standalone functions with estimator-specific options.
30+
w = sp.overlap_weights(df, treat="training",
31+
covariates=["age", "education", "earnings_pre"])
32+
diag = sp.balance_diagnostics(df, treat="training",
33+
covariates=["age", "education"],
34+
weights=w.weights)
35+
```
36+
37+
## Estimator families
38+
39+
| Family | Functions | Typical use |
40+
| --- | --- | --- |
41+
| Classical matching | `sp.match(method="nearest" | "psm" | "mahalanobis" | "cem" | "stratify")` | Matched samples or subclassification with transparent design choices. |
42+
| Entropy / CBPS / SBW | `sp.ebalance`, `sp.cbps`, `sp.sbw` | Direct covariate balance by reweighting. |
43+
| Genetic matching | `sp.genmatch` | Automated balance search over covariate weights. |
44+
| Overlap weights | `sp.overlap_weights` | ATE-style overlap-population estimands with stable weights. |
45+
| Diagnostics | `sp.balance_diagnostics`, `sp.love_plot` | Standardised mean differences, variance ratios, and Love plots. |
46+
47+
## Method-level API
48+
49+
### `sp.match(...)`
50+
51+
::: statspai.match
52+
53+
### `sp.ebalance(...)`
54+
55+
::: statspai.ebalance
56+
57+
### `sp.cbps(...)`
58+
59+
::: statspai.cbps
60+
61+
### `sp.genmatch(...)`
62+
63+
::: statspai.genmatch
64+
65+
### `sp.sbw(...)`
66+
67+
::: statspai.sbw
68+
69+
### `sp.overlap_weights(...)`
70+
71+
::: statspai.overlap_weights
72+
73+
### `sp.balance_diagnostics(...)`
74+
75+
::: statspai.balance_diagnostics
76+
77+
### `sp.love_plot(...)`
78+
79+
::: statspai.love_plot

docs/reference/smart.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,37 @@ Calibration card: top-method `verify_score` is typically 85–95 on
7272
clean DGPs (RD lower at ≈ 74 due to local-polynomial bootstrap
7373
variance). `sp.verify_benchmark(...)` runs verify against synthetic
7474
DGPs to calibrate what threshold constitutes "trust it".
75+
76+
## Agent-native method-level API
77+
78+
These functions are guide-friendly, but they are also public API calls used by
79+
agents and notebook workflows. Their docstrings are exposed here so the
80+
Reference navigation includes method-level details.
81+
82+
### `sp.detect_design(...)`
83+
84+
::: statspai.detect_design
85+
86+
### `sp.preflight(...)`
87+
88+
::: statspai.preflight
89+
90+
### `sp.audit(...)`
91+
92+
::: statspai.audit
93+
94+
### `sp.examples(...)`
95+
96+
::: statspai.examples
97+
98+
### `sp.session(...)`
99+
100+
::: statspai.session
101+
102+
### `sp.brief(...)`
103+
104+
::: statspai.brief
105+
106+
### `sp.bib_for(...)`
107+
108+
::: statspai.bib_for

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ nav:
120120
- "Overview": reference/index.md
121121
- "Difference-in-differences": reference/did.md
122122
- "Instrumental variables": reference/iv.md
123+
- "Matching / balancing": reference/matching.md
123124
- "Panel data": reference/panel.md
124125
- "Regression discontinuity": reference/rd.md
125126
- "Synthetic control": reference/synth.md

0 commit comments

Comments
 (0)