Repository navigation
feat(design): diagnose_design - size and power of candidate estimators on your own untreated panel - #898
Conversation
…s on your own untreated panel Add diff_diff/design.py with diagnose_design and DesignDiagnosisResults. On an untreated panel it repeatedly assigns placebo treatments that follow a declared design, optionally injects a known effect, fits every listed estimator on the same placebo draws through simulate_power, and reports each estimator's rejection rate under no effect, its power, bias, RMSE and coverage at each injected effect, and an optional minimum detectable effect. Outcome-blind; estimators are returned in input order and never ranked. Methodology and the choices without a paper source are documented in REGISTRY ## DesignDiagnosis.
|
Overall assessment: ⛔ Blocker Executive summary
MethodologyP0 — Conley inference loses the calendar period Impact: The common-timing adapter supplies Consequently, observations from different years within the same pre/post window enter the spatial sandwich as contemporaneous observations. With This contradicts the within-calendar-period spatial sum and period-distance serial kernel in Concrete fix: Refuse P3 — Documented methodological choices are accepted Impact: The size gate, failed-fit exclusion, MDE search, RMSE convention, and declared adoption dates intentionally differ from—or extend—the sources. Concrete fix: None required. These choices are explicitly documented. The source cross-check used the registry, estimator references, and repository paper reviews, including BDM’s whole-unit resampling and additive injection, Mizushima–Powell’s staggered assignments, Coglianese–Fang’s shared events, and Blair et al.’s diagnosands. Primary PDFs were unavailable locally. Code QualityP1 — Nullable first-treatment values are not converted safely Impact: A numeric pandas nullable column such as Concrete fix: Use PerformanceNo additional findings. MaintainabilityNo additional findings. Tech DebtP3 — Scope limitations and tutorial work are tracked Impact: Unbalanced panels, additional calendar types, anticipation support, and the full tutorial remain unavailable or deferred. Concrete fix: None required for this PR; these limitations are tracked and unsupported paths are refused. SecurityNo findings in the reviewed changes. Documentation/TestsThe changelog fragment is present. Existing tests cover shared draws, recovery, truncation, and failure handling, but the Conley test checks successful fitting rather than covariance correctness ( Static syntax checks passed for all seven changed Python files. Runtime validation stopped at Path to Approval
|
…lable first_treat and calendar columns explicitly DifferenceInDifferences and static TwoWayFixedEffects take the Conley time dimension from the 0/1 post indicator, so on a multi-period placebo panel the spatial and serial terms would treat each pre/post window as one period. Refuse vcov_type='conley' candidates up front. A nullable first_treat column that marks never-treated units with pd.NA is now converted with an explicit missing value, and a nullable integer calendar column is read as a plain array.
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: ✅ Looks good Both prior blocking findings are addressed. No unmitigated P0 or P1 findings remain within this re-review’s scope. Executive summary
MethodologyPrior P0 — Resolved: Conley inference loses the calendar period Impact: The early refusal prevents size, power, coverage and MDE calculations from using an incorrect Conley calendar. Tests cover both affected estimators, lag cutoffs 0/1 and both resampling modes ( Concrete fix: None remaining. P3 — Informational: documented methodology choices accepted Impact: The size gate, failed-fit exclusion, MDE procedure, RMSE convention and declared adoption dates are explicitly documented choices. Cross-checking the registry, docstrings and repository reviews of BDM, Mizushima–Powell, Coglianese–Fang and Blair et al. identified no additional undocumented mismatch. Primary PDFs were unavailable locally. Concrete fix: None required. Code QualityPrior P1 — Resolved: nullable first-treatment conversion Impact: Concrete fix: None remaining. PerformanceNo additional findings within the re-review scope. MaintainabilityNo additional findings within the re-review scope. Tech DebtP3 — Informational: limitations and tutorial work are tracked Impact: Unsupported configurations are refused, while survey support, broader panel/calendar support and tutorial work have tracking entries. Concrete fix: None required for this PR. SecurityNo findings in the reviewed changes. Documentation/TestsThe required changelog fragment is present at Syntax compilation passed for all seven changed Python files. Attempting the two design test suites stopped because pytest is unavailable; NumPy is also missing. The PR’s reported runtime results were therefore not independently verified. |
Summary
Add
diagnose_design, the first design-stage tool: before analysing a study, check how each candidate estimator behaves on the panel that will actually be used.DesignDiagnosisResultswith, per estimator, the rejection rate under no effect (size) and the power, bias, RMSE and coverage at each injected effect, plus an optional minimum detectable effect.first_treat=, every period from the earliest real adoption onward is dropped before anything else.size_controlledflags those whose no-effect rejection rate is consistent withalphaand that lost at most 10% of their replicates; no minimum detectable effect is reported for the others.DifferenceInDifferences,TwoWayFixedEffects,CallawaySantAnna,SunAbraham,ImputationDiD,TwoStageDiD,StackedDiD,EfficientDiD; absorbing binary treatment; common or staggered timing.diff_diff/design.py. It drivessimulate_powerandsimulate_mdeunchanged, through their existingdata_generatorhook, and returns existingSimulationPowerResults/SimulationMDEResultsobjects.diff_diff/power.pyis not modified.diagnose_design, the results classDesignDiagnosisResults(fieldsresults,mde_results,estimators,size_controlled,n_nan_inference,mde,data_sha256,data_columns,n_dropped, plus echoed arguments), and the argumentsestimatorsandresample_units. Every other argument and field reuses an existing spelling with its existing meaning (cohort_periods,treatment_fraction,n_treated,effect_sizes,n_simulations,alpha,power,first_treat,estimator_kwargs,seed,progress,target_power).anticipation; an estimatoralphadifferent from the function's;DifferenceInDifferences/TwoWayFixedEffectsunder a staggered declaration;vcov_type="conley"(those two estimators take the Conley time dimension from the 0/1 post indicator, which is wrong on a multi-period placebo panel); withresample_units=True, aclustercolumn other than the unit column (copies of a resampled unit would share a cluster); unbalanced panels, missing outcomes and a non-numeric calendar column.Methodology references (required if estimator / math changes)
diagnose_design).docs/methodology/papers/.## DesignDiagnosis. The ones with no paper source: the size check and its 10% lost-replicate condition; the minimum detectable effect on real data (bisection viasimulate_mde, bracket seeded from the estimator's own no-effect spread); the two-pre-period minimum; the data fingerprint. Differences from a source: RMSE is the existingddof = 1form, not Blair et al.'s root mean squared error; adoption periods are declared, where Bertrand et al.'s main design draws the year at random; a fit with non-finite inference is excluded from the rates, wheresimulate_poweralone counts it as a non-rejection.Validation
tests/test_design.py(104 tests: effect recovery for all eight estimators, shared placebo draws, exact enumeration of all assignments on a six-unit panel, the outcome-blind truncation, every refusal, the failure policy via call-counted stubs, size-check boundaries, the fingerprint, warning handling, the results contract, the minimum detectable effect) andtests/test_methodology_design.py(14 tests).tests/test_diagnostic_marker.pyandtests/helpers/results_foundation.pyenrol the new results class;tests/test_naming_guard.pyregisters the two new calendar-column surfaces.TwoWayFixedEffects(vcov_type="classical")rejects a true null above 25% and fails the size check; the default unit-clustered fit is below 12% and passes.CallawaySantAnna,ImputationDiDandSunAbrahameach reject above 15%; with 20 treated units each is below 12%.(z_0.975 + z_0.80)times the spread of the no-effect estimates.pytest tests/test_design.py tests/test_methodology_design.pyon the Rust backend and withDIFF_DIFF_BACKEND=python- 118 passed on each.pytest tests/test_power.py- passed (unchanged module).pytest tests/test_naming_guard.py tests/test_diagnostic_marker.py tests/test_v4_diagnostic_family_docs.py tests/test_doc_deps_integrity.py tests/test_docs_ia.py tests/test_changelog_fragments.py tests/test_tracking_files.py- passed.black --checkandruff checkclean.mypy diff_diff/design.pyclean. The Sphinx HTML build with warnings as errors (-W, same dependency set as the docs workflow) completes with no warnings.DeclareDesigndiagnoses simulated designs, not placebo assignment on a user's panel).Security / privacy
Changelog