Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Related tracking surfaces:

| Issue | Location | Origin | Effort | Priority |
|-------|----------|--------|--------|----------|
| Sensitivity planning at the design stage: what HonestDiD `M` a planned design could rule out, from the placebo event studies `diagnose_design(event_study=True)` records (needs an effect-injected surface and HonestDiD run inside each placebo draw; the Rambachan-Roth review has no planning formula). Lifts the `HonestDiD` and `sensitivity_to_honest_did` refusals of `estimand="placebo"` surfaces. | `design.py::_placebo_event_study`, `honest_did.py::_extract_event_study_params` | pre-trend planning PR | Heavy | Medium |
| Placebo event studies for more `diagnose_design` candidates: `SunAbraham` (its container is not an admitted `PreTrendsPower` input; only the fitted results object is) and the `TwoWayFixedEffects` event-study mode (a different fit from the static one the diagnosis runs). Recorded today for `CallawaySantAnna` and `StackedDiD` only. | `design.py::_EVENT_STUDY_ESTIMATORS`, `pretrends.py::_extract_container_pre_period_params` | pre-trend planning PR | Mid | Low |
| Planned pre-trend power for the joint Wald form: `PreTrendsPower(pretest_form="wald")` refuses a design-stage input because the placebo record keeps each coefficient over its own standard error (the NIS test) and not each draw's event-study covariance. Supporting it needs the per-draw covariance blocks, a counted Wald rejection rate for the tested set, and a direct-injection check like the one in `benchmarks/python/pretrend_planning_check.py`. | `pretrends.py::_planned_pretest_check`, `design.py::_event_study_record` | pre-trend planning PR | Mid | Low |
| `PreTrendsPower` Wald form on a numerically singular pre-period covariance from a fitted model: `_compute_mdv_wald` and `_compute_power_wald` call `np.linalg.inv`, which does not raise on a numerically singular matrix (`pinv` is only the fallback after an exception), so the MDV can be meaningless. The design-stage path gates such a covariance out; the fitted path is unchanged. Decide between a rank guard and `pinv`. | `pretrends.py::_compute_mdv_wald` | pre-trend planning PR | Quick | Medium |
| `diagnose_design` staggered placebo for `DifferenceInDifferences` / `TwoWayFixedEffects`: both are refused under a staggered declaration (two or more `cohort_periods`) because they are fitted with one `post` dummy. Supporting them needs a staggered TWFE placebo fit (a time-varying treatment column) and a stated estimand, since static TWFE under staggered timing does not target the injected effect cleanly. | `design.py::_validate_estimators` | design diagnosis PR-B | Mid | Low |
| `diagnose_design` with `anticipation > 0`: refused today because the candidate's aggregate averages periods before adoption where no effect is injected. Inject the effect from `g - anticipation` so that bias and coverage are scored against the right target. | `design.py::_validate_estimators`, `design.py::_make_placebo_generator` | design diagnosis PR-B | Mid | Low |
| `diagnose_design` size verdict near the threshold: the size check passes a no-effect rejection rate up to `alpha + 1.96 * sqrt(alpha * (1 - alpha) / R)`, so a candidate whose true size is just above `alpha` passes one run and fails the next. In `benchmarks/data/design_lock_rerun.json` (500 replicates, 40 units) candidates with reference size 6.4-6.7% passed the comparison and were then flagged by the lock rerun in 30-36% of locks. The lock already reports the rerun's verdict and warns when the two differ; decide whether the rule itself should change (a stricter bound, a reported interval for the size, or a three-way verdict). | `design.py::_size_controlled` | design lock PR | Mid | Medium |
Expand Down
19 changes: 19 additions & 0 deletions benchmarks/data/pretrend_planning_check.json

Large diffs are not rendered by default.

576 changes: 576 additions & 0 deletions benchmarks/python/pretrend_planning_check.py

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions changelog.d/20261126-pretrend-planning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
### Added
- **Planned pre-trend power at the design stage.**
`diagnose_design(..., event_study=True)` keeps, for each `CallawaySantAnna`
and `StackedDiD` estimator, a placebo event study: the mean and the
covariance, across the no-effect placebo draws, of the event-study
coefficients of each fit (`DesignDiagnosisResults.event_study_results`, an
`EventStudyResults` labelled `estimand="placebo"`). `PreTrendsPower.fit`,
`power_at`, `power_curve`, `compute_pretrends_power` and `compute_mdv` accept
the diagnosis (or one of its surfaces) and return planned pre-trend power from
Roth's (2022) formula before any outcome exists
(`covariance_source="placebo_draws"`). The new
`PreTrendsPower.power_by_pre_periods(diagnosis)` tabulates the minimum
detectable violation and the test's no-violation rejection rate by the 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 (none of which contains a
violation) and compares that with the rate the formula assumes. Planned
power is reported only where the two agree within Monte Carlo error: `fit`
raises with both rates otherwise, and the by-pre-period table shows both
rates on every row (`power_no_violation`, `placebo_rejection_rate`) and
leaves the planned numbers blank on rows that disagree. In the library's
simulation the formula matched direct trend injection on all 28 cells that
passed this check (power at the planned minimum detectable violation 73%
to 84% against a target of 80%), and every cell on which it did not match
was one the check withholds (mostly 40-unit panels with 10 treated units).
- Planned power is available for the default pre-test form
(`pretest_form="nis"`) only.
- No placebo event study is recorded for a `vcov_type="jackknife"` candidate
or for the other estimator classes.
- `HonestDiD`, `PreTrendsPower.sensitivity_to_honest_did`, and
`precomputed["pretrends_power"]` in `DiagnosticReport` / `BusinessReport`
refuse a placebo event study or a result planned from one.

### Fixed
- `PreTrendsPower.fit`, `power_at`, `power_curve` and
`PreTrendsPowerResults.power_at` reported a power of 100% (default pre-test
form) or of `alpha` (Wald form) for a violation magnitude `M` that was NaN.
A non-finite `M` now raises `ValueError`.
- The `PreTrendsPower` example in the bundled `llms-full.txt` guide called a
method and an argument that do not exist (`ptp.compute`, `M_grid=` on
`compute_pretrends_power`).
21 changes: 21 additions & 0 deletions diff_diff/_reporting_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ def results_design(results: Any) -> Optional[str]:
return getattr(results, "design", None)


def check_precomputed_pretrends_power(precomputed: Dict[str, Any], owner: str) -> None:
"""
Refuse a planned pre-trends power result in ``precomputed=``.

A ``PreTrendsPowerResults`` computed from a placebo event study
(``covariance_source == "placebo_draws"``) describes a design that had
not been run. A report describes one fitted model, so the two cannot be
combined.
"""
supplied = precomputed.get("pretrends_power")
if supplied is None:
return
if getattr(supplied, "covariance_source", None) == "placebo_draws":
raise ValueError(
f"{owner}: precomputed['pretrends_power'] was computed from a "
f"placebo event study of diagnose_design (a planned design, not "
f"the fit being reported). Pass pre-trends power computed from the "
f"fitted results, or omit the key."
)


def check_design_reconciliation(reconciliation: Any, results: Any, owner: str) -> None:
"""
Refuse a ``design_reconciliation=`` input the report cannot stand behind.
Expand Down
2 changes: 2 additions & 0 deletions diff_diff/business_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

from diff_diff._reporting_helpers import (
check_design_reconciliation,
check_precomputed_pretrends_power,
describe_design_reconciliation,
describe_target_parameter,
design_reconciliation_lines,
Expand Down Expand Up @@ -429,6 +430,7 @@ def __init__(
"aggregate('event_study') surface) and do not accept "
"precomputed overrides."
)
check_precomputed_pretrends_power(self._dr_precomputed, "BusinessReport")

resolved_alpha = alpha if alpha is not None else getattr(results, "alpha", 0.05)
self._context = BusinessContext(
Expand Down
Loading
Loading