Commit 2042b7c
Phase 4.5 C: HAD linearity-family pretests under survey
Closes the Phase 4.5 C0 promise (PR #367 commit 29f8b12). Linearity-
family pretests now accept survey=/weights= keyword-only kwargs:
- stute_test, yatchew_hr_test, stute_joint_pretest, joint_pretrends_test,
joint_homogeneity_test, did_had_pretest_workflow.
Stute family: PSU-level Mammen multiplier bootstrap via
generate_survey_multiplier_weights_batch. Each replicate draws
(B, n_psu) Mammen multipliers, broadcast to per-obs perturbation
eta_obs[g] = eta_psu[psu(g)], weighted OLS refit, weighted CvM via new
_cvm_statistic_weighted helper. Joint Stute SHARES the multiplier matrix
across horizons within each replicate, preserving both vector-valued
empirical-process unit-level dependence (Delgado 1993; Escanciano 2006)
AND PSU clustering (Krieger-Pfeffermann 1997). NOT Rao-Wu rescaling --
multiplier bootstrap is a different mechanism.
Yatchew: closed-form weighted OLS + pweight-sandwich variance components
(no bootstrap):
sigma2_lin = sum(w * eps^2) / sum(w)
sigma2_diff = sum(w_avg * diff^2) / (2 * sum(w)) [Reviewer CRITICAL #2]
sigma4_W = sum(w_avg * eps_g^2 * eps_{g-1}^2) / sum(w_avg)
T_hr = sqrt(sum(w)) * (sigma2_lin - sigma2_diff) / sigma2_W
where w_avg_g = (w_g + w_{g-1}) / 2 (Krieger-Pfeffermann 1997 Section 3).
All three components reduce bit-exactly to existing unweighted formulas
at w=ones(G); locked at atol=1e-14 by direct helper test.
Workflow under survey/weights: skips the QUG step with UserWarning (per
C0 deferral), sets qug=None on the report, dispatches the linearity
family with survey-aware mechanism, appends "linearity-conditional
verdict; QUG-under-survey deferred per Phase 4.5 C0" suffix to the
verdict. all_pass drops the QUG-conclusiveness gate (one less
precondition). HADPretestReport.qug retyped from QUGTestResults to
Optional[QUGTestResults]; summary/to_dict/to_dataframe updated to
None-tolerant rendering.
Pweight shortcut routing: weights= passes through a synthetic trivial
ResolvedSurveyDesign (new survey._make_trivial_resolved helper) so the
same kernel handles both entry paths -- mirrors PR #363's R7 fix pattern
on HAD sup-t.
Replicate-weight survey designs (BRR/Fay/JK1/JKn/SDR) raise
NotImplementedError at every entry point (defense in depth, reciprocal-
guard discipline). The per-replicate weight-ratio rescaling for the
OLS-on-residuals refit step is not covered by the multiplier-bootstrap
composition; deferred to a parallel follow-up.
Per-row weights= / survey=col aggregated to per-unit via existing HAD
helpers (_aggregate_unit_weights, _aggregate_unit_resolved_survey;
constant-within-unit invariant enforced) through new
_resolve_pretest_unit_weights helper. Strictly-positive weights required
on Yatchew (the adjacent-difference variance is undefined under
contiguous-zero blocks).
Stability invariants preserved:
- Unweighted code paths bit-exact pre-PR (the new survey/weights branch
is a separate if arm; existing 138 pretest tests pass unchanged).
- Yatchew weighted variance components reduce to unweighted at w=1 at
atol=1e-14 (locked by TestYatchewHRTestSurvey).
- HADPretestReport schema bit-exact on the unweighted path; qug=None
triggers the new None-tolerant rendering only on the survey path.
20 new tests across TestHADPretestWorkflowSurveyGuards (revised from
C0 rejection-only to C functional + 2 mutex/replicate-weight retained),
TestStuteTestSurvey (7), TestYatchewHRTestSurvey (7), TestJointStuteSurvey
(5). Full pretest suite: 158 tests pass.
Patch-level addition (additive on stable surfaces). See
docs/methodology/REGISTRY.md "QUG Null Test" -- Note (Phase 4.5 C) for
the full methodology.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2899e6c commit 2042b7c
6 files changed
Lines changed: 1269 additions & 224 deletions
File tree
- diff_diff
- docs/methodology
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
0 commit comments