Repository navigation
feat(design): planned pre-trend power from placebo event studies (diagnose_design(event_study=True)) - #912
feat(design): planned pre-trend power from placebo event studies (diagnose_design(event_study=True))#912igerber wants to merge 1 commit into
Conversation
diagnose_design(..., event_study=True) records, for CallawaySantAnna and StackedDiD candidates, a placebo event study: the mean and the sample covariance, across the no-effect placebo draws, of each fit's event-study coefficients, as an EventStudyResults with estimand="placebo". It also keeps, per draw, each pre-period coefficient over its own reported standard error. PreTrendsPower accepts the diagnosis (or one of its surfaces) in fit, power_at, power_curve, compute_pretrends_power and compute_mdv and returns planned pre-trend power from Roth's (2022) formula. The new power_by_pre_periods tabulates it by number of pre-periods tested. The formula assumes that each coefficient's own test rejects at its nominal level. For the pre-periods being planned, PreTrendsPower counts how often the pre-trend test rejected in the placebo draws and compares that with the rate the formula assumes. Planned power is reported only where the two agree within Monte Carlo error: fit raises otherwise, and the table shows both rates on every row and leaves a disagreeing row blank. NIS form only. HonestDiD, sensitivity_to_honest_did and the reports' precomputed pretrends_power refuse a placebo surface or a result planned from one. Also: a non-finite violation magnitude M now raises ValueError in fit, power_at, power_curve and PreTrendsPowerResults.power_at (a NaN was reported as power 1.0, or alpha under the Wald form); the PreTrendsPower example in llms-full.txt called a method and an argument that do not exist. benchmarks/python/pretrend_planning_check.py checks the planned numbers against direct trend injection on simulated panels; tutorial 34 gains a section that plans the pre-trend check of its design.
|
✅ Looks good — No unmitigated P0 or P1 findings identified in the supplied changes. Executive summary
Methodology
Code Quality No findings. The new surface uses Performance No actionable findings. Event-study capture is optional and limited to the no-effect cell. Bootstrap aggregation can add replay work, but no demonstrated performance defect was identified. Maintainability No findings. Shared report validation, retained provenance, and backward-compatible pickle defaults support the new input path. Tech Debt
Security No findings. No apparent secrets or newly introduced unsafe execution paths were identified. Documentation/Tests No actionable findings. The PR includes a valid changelog fragment and targeted tests for reduction rules, calibration, consumer refusals, and serialization. Validation completed: all 11 changed Python files and notebook code cells parsed; all 48 committed benchmark classifications matched the documented rules; changelog validation passed. These checks do not independently reproduce the numerical simulations or pytest results. |
Summary
Planned pre-trend power at the design stage: before any outcome exists, how large a diverging trend would the pre-trend check of a planned design catch, and how does that change with the number of pre-periods tested.
diagnose_design(..., event_study=True)keeps, for eachCallawaySantAnnaandStackedDiDcandidate, a placebo event study: the mean and the sample covariance, across the no-effect placebo draws, of the event-study coefficients of each fit. It is stored inDesignDiagnosisResults.event_study_results[label]as anEventStudyResultslabelledestimand="placebo".PreTrendsPoweraccepts the diagnosis (or one of its placebo event studies) infit,power_at,power_curve,compute_pretrends_powerandcompute_mdv, and returns planned pre-trend power from Roth's (2022) formula (covariance_source="placebo_draws").PreTrendsPower.power_by_pre_periods(diagnosis)tabulates it by the number of pre-periods tested (theKnearest to treatment).PreTrendsPowercounts how often the pre-trend test rejected in the draws and compares that with the rate the formula assumes. Planned power is reported only where the two agree within Monte Carlo error:fitraises with both rates otherwise, and the table shows both rates on every row (power_no_violation,placebo_rejection_rate) and leaves the planned numbers of a disagreeing row blank. This mirrors the minimum detectable effect, which is not reported for an estimator that fails the size check.HonestDiD,PreTrendsPower.sensitivity_to_honest_did, andprecomputed["pretrends_power"]inDiagnosticReport/BusinessReport.power_by_pre_periodsrefuses a fitted model (choosing how many pre-periods to test after seeing the event study is a choice made on the outcome).Mthat was NaN was reported as a power of 100% (default pre-test form) or ofalpha(Wald form) byPreTrendsPower.fit,power_at,power_curveandPreTrendsPowerResults.power_at. A non-finiteMnow raisesValueError.PreTrendsPowerexample in the bundledllms-full.txtguide that called a method and an argument that do not exist.New public surface: one keyword (
diagnose_design(event_study=), the spellingTwoWayFixedEffects.fitalready uses), two fields onDesignDiagnosisResults(event_study,event_study_results), one method (PreTrendsPower.power_by_pre_periods), and one new value each for two existing fields (EventStudyResults.estimand="placebo",PreTrendsPowerResults.covariance_source="placebo_draws"). No new class or function.DesignLockis unchanged, and every cell of a diagnosis is identical with the keyword on and off.Limits, each stated in the registry and tracked in
TODO.md:pretest_form="nis") only.CallawaySantAnnaandStackedDiDonly, and not for avcov_type="jackknife"candidate.Ma design could rule out) is not in this PR.Methodology references (required if estimator / math changes)
docs/methodology/REGISTRY.md## DesignDiagnosis("Placebo event study" and its Notes),## PreTrendsPower(Note (design-stage input),Note (power_by_pre_periods)),## HonestDiD(Note (placebo event studies are refused));docs/methodology/REPORTING.md(planned pre-trends power is refused).diagnose_designalready uses (Bertrand, Duflo & Mullainathan 2004; Mizushima & Powell 2025).Validation
Tests added/updated:
tests/test_design_event_study.py(new, 77 tests),tests/test_pretrends.py(non-finiteM),tests/test_t34_design_diagnosis_drift.py(the new tutorial section, including two slow tests that rerun it).CallawaySantAnnawith both base periods, staggered timing,StackedDiD), including the per-draw record and the counted rejection rate; only the no-effect cell is captured, and the diagnosis cells and the lock are identical with the keyword on and off.HonestDiD, both reports on everyBusinessReportpath); pickling, including a state from before the new fields existed.Backtest / simulation / notebook evidence (if applicable):
benchmarks/python/pretrend_planning_check.py(results committed asbenchmarks/data/pretrend_planning_check.json; the registry's numbers are pinned to that file byTestPlanningEvidence). Twelve simulated AR(1) panels of 12 periods (40 and 200 units, a quarter treated, AR 0, 0.5 and 0.8, common and staggered adoption),CallawaySantAnna(base_period="universal")on all andStackedDiDon the common-adoption ones, 500 diagnosis replicates, tests of 2, 4 and all pre-periods (48 cells). For each cell, 1,000 fresh placebo draws with a linear trend of the planned size added to the placebo-treated units, the pre-test applied with each fit's own standard errors:A cell is flagged when the observed power at the planned MDV is more than 5pp plus two Monte Carlo standard errors from 80%, or the observed no-violation rate is more than 3pp plus two standard errors from the planned one. Every flagged cell is one the check withholds. The same script measures the Monte Carlo error of the planned MDV (standard deviation over 20 seeds: 4% to 5% of the mean at 200 replicates, 3% to 4% at 500, 2% at 1,000) and the effect of picking a candidate from a comparison (the picked candidate's planned MDV differed from a rerun alone on a new seed by -1.7% and +1.4%, standard errors 0.7 and 0.6). This is one family of simulated designs.
Tutorial 34 was re-executed; its existing outputs are unchanged.
mypy diff_diffat the pinned versions reports no errors; the Sphinx-Wbuild passes.Security / privacy
Changelog