Skip to content

docs(tutorials): repair and conform the Study design tutorials (04, 05, 06, 07, 24), with drift tests - #916

Merged
igerber merged 1 commit into
mainfrom
docs/tutorials-study-design
Nov 26, 2026
Merged

igerber merged 1 commit into
mainfrom
docs/tutorials-study-design

Conversation

@igerber

@igerber igerber commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Third PR of the post-4.0 tutorial repair (after #906 and #911). Fixes the defects found in the Study design tutorials and brings each to the tutorial conventions in CONTRIBUTING.md, keeping each notebook's own narrative. Every notebook is committed with executed outputs (Rust backend) and has a drift test that pins the numbers its prose quotes.

  • 04_parallel_trends: pre-treatment diagnostics are presented as evidence, not as a pass/fail gate. The group placebo now passes treatment=, so treated units are dropped (without it they sat in the placebo control group). The permutation example no longer labels the placebo mean as the estimate.
  • 05_honest_did: the relative-magnitudes restriction is stated on first differences, as implemented (it was written on levels, which cannot reproduce the output). The breakdown value is searched on a grid that reaches it. The conventional interval is shown to miss the simulated truth where both honest intervals cover it. Relative magnitudes and smoothness are no longer compared at "the same M".
  • 06_power_analysis: closed-form and simulated sample sizes are compared for the same design (32 against 35 units; the old comparison set 63 against 42 and blamed simulation noise). sigma and rho are defined once. Panel simulations cluster by unit.
  • 07_pretrends_power: the linear minimum detectable violation is treated as a slope and translated into the bias it implies, and is no longer passed to Honest DiD as a smoothness bound. Power grids sit on the scale of the MDV instead of saturating at 100%. The form of the pre-test is named. A new section shows by simulation that, in the notebook's design, bias is larger and coverage lower among the samples that pass the pre-test.
  • 24_staggered_vs_collapsed_power: the removed overall_att name is gone from the prose; the event study is drawn with plot_event_study; blanket warning filters are removed (the fits are warning-free); the claim that the simulate_* functions draw independently per estimator is corrected.
  • tests/test_tutorial_conventions.py: the five notebooks leave the ratchet allowlist.
  • docs/tutorials/index.rst: card text for the touched notebooks.
  • TODO.md: three small library items found along the way (power evaluated at the MDV under the default M=None; "Residual SD" wording for sigma; seed= in simulate_* seeds the data generator only).

Not touched: 34_design_diagnosis.ipynb.

Methodology references (required if estimator / math changes)

  • Method name(s): N/A - no methodology changes (documentation and tests only). The notebooks' statements about Honest DiD (Rambachan and Roth 2023) and pre-trend power (Roth 2022) were checked against docs/methodology/REGISTRY.md.
  • Paper / source link(s): N/A
  • Any intentional deviations from the source (and why): None

Validation

  • Tests added/updated: tests/test_t04_parallel_trends_drift.py, tests/test_t05_honest_did_drift.py, tests/test_t06_power_analysis_drift.py, tests/test_t07_pretrends_power_drift.py (new); tests/test_t24_staggered_vs_collapsed_power_drift.py, tests/test_tutorial_conventions.py (updated). 334 passed on each backend, slow tests included, together with the docs IA, tracking-file and changelog guards.
  • Backtest / simulation / notebook evidence (if applicable): after rebasing onto current main, notebooks 04, 05, 07 and 24 were re-executed on the Rust backend with no output differences from the committed outputs, and pass pytest --nbmake on the pure-Python backend. 06 is excluded from that CI job for runtime; its drift test, slow tests included, passes on both backends. The Sphinx -W build and the search-excerpt smoke test pass locally.

Security / privacy

  • Confirm no secrets/PII in this PR: Yes

Changelog

  • changelog.d/ fragment added (or N/A - no user-visible change): Yes (changelog.d/20261125-tutorials-study-design.md)

@github-actions

Copy link
Copy Markdown

✅ Looks good

No unmitigated P0 or P1 findings identified in the supplied changes.

Executive summary

  • The revised methodology explanations align with the Registry, docstrings, and checked-in paper reviews.
  • Placebo control filtering, MDV units, and matching-design power comparisons are corrected.
  • All five notebooks pass the convention checks; source/output assertions and the changelog guard pass.
  • Numerical drift tests could not be rerun: this environment lacks NumPy and pytest.

Methodology

  • P3 — Documented inference approximations. Relative-magnitudes CIs use naive FLCI, and analytical power uses normal critical values. Both are explicitly documented deviations (docs/methodology/REGISTRY.md:L6750-L6751, L6934-L6940).
    • Impact: Results can differ from the reference implementations as described.
    • Concrete fix: None required. The tutorials explain these approximations.

The first-difference restriction, smoothness interpretation, pre-test conditioning simulation, and CS estimand descriptions are consistent with the cited methodology.

Code Quality

No findings. Changes are confined to tutorials, documentation, and tests.

Performance

No findings. The new simulation-heavy power tests are marked slow.

Maintainability

No findings. Removing repaired notebooks from the convention allowlist preserves the ratchet.

Tech Debt

  • P3 — Documentation and reproducibility follow-ups are tracked (TODO.md:L115-L116).
    • Impact: Library-wide sigma wording and estimator seed handling remain follow-up work.
    • Concrete fix: None required in this PR; the notebook supplies the necessary explanations and estimator seed.

Security

No findings in the supplied changes.

Documentation/Tests

No actionable findings. Verification completed:

  • Syntax checks for changed tests and notebook code cells.
  • Eleven extracted source/output assertion checks.
  • Convention checks for all five notebooks.
  • Changelog validation and independent closed-form arithmetic.

Full numerical drift tests and notebook re-execution remain unverified locally because the required dependencies are unavailable.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Nov 26, 2026
@igerber
igerber merged commit 1da1496 into main Nov 26, 2026
43 of 44 checks passed
@igerber
igerber deleted the docs/tutorials-study-design branch November 26, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ci Triggers CI test workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant