Skip to content

Commit 2104cf1

Browse files
feat(rd): comprehensive RDD mega-upgrade — 6 new modules + major enhancements
New modules (6 files, ~6000 lines): - bandwidth.py: Full bandwidth selection suite (8 methods: MSE/CER × common/separate/comb1/comb2) with fuzzy-specific and covariate-adjusted support (Calonico-Cattaneo-Farrell 2020) - locrand.py: Local randomization inference framework (rdrandinf, rdwinselect, rdsensitivity, rdrbounds) with Fisher exact tests and Rosenbaum bounds (Cattaneo-Titiunik-VB 2016) - hte.py: Heterogeneous treatment effects via fully interacted local linear model (rdhte, rdbwhte, rdhte_lincom) with Wald heterogeneity test (Calonico et al. 2025) - rd2d.py: Boundary discontinuity / 2D RD designs with distance-based and location-based approaches, bivariate local polynomial (Cattaneo-Titiunik-Yu 2025) - extrapolate.py: External validity — Angrist-Rokkanen extrapolation (OLS/IPW/AIPW), multi-cutoff extrapolation, external validity diagnostics - rdml.py: ML+RD methods — Causal Forest, Gradient Boosting, LASSO-assisted RD, unified CATE summary with variable importance Major upgrades to existing modules: - rdrobust.py: Covariate-adjusted local polynomial estimation (covariates in design matrix per Calonico et al. 2019), 8 bandwidth selectors (CER-optimal added), weights support, IMSE-optimal binning for rdplot, weighted global polynomial fits, pointwise CI bands - diagnostics.py: Enhanced rdsummary with full=True mode (honest CI, power analysis, placebo tests, bandwidth comparison), multi-panel diagnostic dashboard plot - __init__.py: All 30+ new public functions exported at sp.xxx level 57 tests pass (25 existing + 32 new). Total RD module: 10,298 lines across 14 files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 594461d commit 2104cf1

11 files changed

Lines changed: 7280 additions & 117 deletions

File tree

src/statspai/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@
4343
aggte, cs_report, CSReport, ggdid,
4444
bjs_pretrend_joint,
4545
)
46-
from .rd import rdrobust, rdplot, rdplotdensity, rdbwsensitivity, rdbalance, rdplacebo, rdsummary, rkd, rd_honest, rdit, rdpower, rdsampsi
46+
from .rd import (
47+
rdrobust, rdplot, rdplotdensity, rdbwselect,
48+
rdbwsensitivity, rdbalance, rdplacebo, rdsummary,
49+
rkd, rd_honest, rdit, rdpower, rdsampsi,
50+
rdrandinf, rdwinselect, rdsensitivity, rdrbounds,
51+
rdhte, rdbwhte, rdhte_lincom,
52+
rd_forest, rd_boost, rd_lasso, rd_cate_summary,
53+
rd_extrapolate, rd_multi_extrapolate, rd_external_validity,
54+
)
4755
from .synth import (
4856
synth, SyntheticControl, synthplot, sdid, augsynth,
4957
demeaned_synth, robust_synth, gsynth, staggered_synth, conformal_synth,
@@ -164,6 +172,8 @@
164172
from .mendelian import mendelian_randomization, MRResult, mr_egger, mr_ivw, mr_median
165173
# Multi-cutoff / Geographic RD
166174
from .rd import rdmc, rdms, RDMultiResult
175+
# 2D Boundary RD (Cattaneo, Titiunik, Yu 2025)
176+
from .rd import rd2d, rd2d_bw, rd2d_plot
167177
# Continuous Treatment DID
168178
from .did import continuous_did
169179

@@ -264,13 +274,28 @@
264274
"rdrobust",
265275
"rdplot",
266276
"rdplotdensity",
277+
"rdbwselect",
267278
"rdbwsensitivity",
268279
"rdbalance",
269280
"rdplacebo",
270281
"rdsummary",
271282
"rkd",
272283
"rd_honest",
273284
"rdit",
285+
"rdrandinf",
286+
"rdwinselect",
287+
"rdsensitivity",
288+
"rdrbounds",
289+
"rdhte",
290+
"rdbwhte",
291+
"rdhte_lincom",
292+
"rd_forest",
293+
"rd_boost",
294+
"rd_lasso",
295+
"rd_cate_summary",
296+
"rd_extrapolate",
297+
"rd_multi_extrapolate",
298+
"rd_external_validity",
274299
# Synthetic Control
275300
"synth",
276301
"SyntheticControl",

src/statspai/rd/__init__.py

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
"""
22
Regression Discontinuity (RD) module for StatsPAI.
33
4-
Provides:
5-
- Sharp, Fuzzy, and Kink RD estimation (CCT 2014)
6-
- Donut-hole RD for handling manipulation near the cutoff
7-
- MSE-optimal bandwidth selection
8-
- RD plots with binned scatter and polynomial fits
9-
- Bandwidth sensitivity analysis
10-
- Covariate balance tests at the cutoff
11-
- Placebo cutoff tests
4+
The most comprehensive Python RD toolkit, providing:
5+
6+
**Core estimation:**
7+
- Sharp, Fuzzy, and Kink RD estimation with robust bias-corrected inference (CCT 2014)
8+
- Covariate-adjusted local polynomial estimation (Calonico et al. 2019)
9+
- Donut-hole RD for manipulation near cutoff
10+
- Regression Discontinuity in Time (Hausman-Rapson 2018)
11+
- Multi-cutoff and multi-score RD (Cattaneo et al. 2024)
12+
- Boundary discontinuity / 2D RD designs (Cattaneo-Titiunik-Yu 2025)
13+
14+
**Bandwidth selection:**
15+
- MSE-optimal: mserd, msetwo, msecomb1, msecomb2
16+
- CER-optimal: cerrd, certwo, cercomb1, cercomb2 (Calonico-Cattaneo-Farrell 2020)
17+
- Fuzzy-specific and covariate-adjusted bandwidth selection
18+
19+
**Inference:**
20+
- Honest confidence intervals (Armstrong-Kolesar 2018, 2020)
21+
- Local randomization inference with Fisher exact tests (Cattaneo-Titiunik-VB 2016)
22+
- Window selection and sensitivity analysis
23+
- Rosenbaum sensitivity bounds
24+
25+
**Treatment effect heterogeneity:**
26+
- CATE estimation via fully interacted local linear (Calonico et al. 2025)
27+
- ML + RD: Causal Forest, Gradient Boosting, LASSO-assisted RD
28+
29+
**External validity:**
30+
- Extrapolation away from cutoff (Angrist-Rokkanen 2015)
31+
- Multi-cutoff extrapolation (Cattaneo et al. 2024)
32+
- External validity diagnostics
33+
34+
**Diagnostics & visualization:**
35+
- One-click diagnostic dashboard (rdsummary)
36+
- IMSE-optimal binned scatter with pointwise CI bands
37+
- Density manipulation testing (CJM 2020)
38+
- Bandwidth sensitivity, covariate balance, placebo cutoff tests
39+
- Power analysis and sample size calculations
1240
"""
1341

1442
from .rdrobust import rdrobust, rdplot, rdplotdensity
43+
from .bandwidth import rdbwselect
1544
from .diagnostics import rdbwsensitivity, rdbalance, rdplacebo, rdsummary
1645
from .rkd import rkd
1746
from .honest_ci import rd_honest
1847
from .rdit import rdit
1948
from .rdmulti import rdmc, rdms, RDMultiResult
2049
from .rdpower import rdpower, rdsampsi, RDPowerResult, RDSampSiResult
50+
from .locrand import rdrandinf, rdwinselect, rdsensitivity, rdrbounds
51+
from .hte import rdhte, rdbwhte, rdhte_lincom
52+
from .rd2d import rd2d, rd2d_bw, rd2d_plot
53+
from .rdml import rd_forest, rd_boost, rd_lasso, rd_cate_summary
54+
from .extrapolate import rd_extrapolate, rd_multi_extrapolate, rd_external_validity
2155

2256
__all__ = [
2357
'rdrobust',
2458
'rdplot',
2559
'rdplotdensity',
60+
'rdbwselect',
2661
'rdbwsensitivity',
2762
'rdbalance',
2863
'rdplacebo',
@@ -37,4 +72,21 @@
3772
'rdsampsi',
3873
'RDPowerResult',
3974
'RDSampSiResult',
75+
'rdrandinf',
76+
'rdwinselect',
77+
'rdsensitivity',
78+
'rdrbounds',
79+
'rdhte',
80+
'rdbwhte',
81+
'rdhte_lincom',
82+
'rd2d',
83+
'rd2d_bw',
84+
'rd2d_plot',
85+
'rd_forest',
86+
'rd_boost',
87+
'rd_lasso',
88+
'rd_cate_summary',
89+
'rd_extrapolate',
90+
'rd_multi_extrapolate',
91+
'rd_external_validity',
4092
]

0 commit comments

Comments
 (0)