Commit 1998d75
Address PR #359 CI review round 6 (2 P1)
P1a — preserve full survey design for Binder-TSL variance. Round 5 filtered
the ResolvedSurveyDesign to the positive-weight subset for BOTH design
resolution AND survey variance composition. That's wrong under the
standard subpopulation / domain-estimation convention (keep the sampling
frame, zero the contributions) that ``SurveyDesign.subpopulation()`` +
``compute_survey_if_variance()`` both implement elsewhere in this repo.
Silent consequences: ``n_psu`` / ``n_strata`` / ``df_survey`` / FPC
application / lonely-PSU behavior would all have been computed on the
in-domain subset instead of the full design.
Refactored HAD ``fit()`` to preserve ``weights_unit_full`` /
``resolved_survey_unit_full`` / ``raw_weights_unit_full`` alongside the
filtered copies used ONLY for design resolution (``_detect_design`` /
``d_lower`` / mass-point threshold / cohort counts). The fit itself
(``_fit_continuous`` → ``bias_corrected_local_linear`` → ``lprobust``)
now receives the FULL unfiltered arrays; ``bias_corrected_local_linear``
filters internally (see P1b below) and zero-pads the IF back to full
ordering, so ``compute_survey_if_variance(if_full, resolved_full)``
preserves the sampling-frame structure. ``compute_survey_metadata`` and
``effective_dose_mean`` likewise consume the full arrays so
``n_psu`` / ``n_strata`` / ``sum_weights`` / ``weight_range`` reflect
the sampling frame. Dropped the now-unused
``_filter_resolved_survey`` helper.
P1b — ``bias_corrected_local_linear(weights=...)`` filters internally.
The public wrapper previously ran ``_validate_had_inputs`` / mass-point
threshold / Design 1' support heuristic + auto-bandwidth MSE-DPI
selector on the full ``d`` array, so zero-weight units at the boundary
or at ``d.min()`` could flip the detected regime or trigger spurious
off-support rejections on valid weighted domain fits. Now computes
``positive_mask = weights > 0`` upfront, validates weights (finite,
non-negative, positive sum — consistent with the port's ValueErrors),
filters ``d`` / ``y`` / ``weights`` / ``cluster`` to the positive-
weight subset BEFORE all downstream validation + selection + fit,
and zero-pads the returned IF back to the original ordering when
``return_influence=True``. ``n_total`` on the returned ``BiasCorrectedFit``
is the original length (matches the caller's input shape).
Four new regression tests:
- ``test_zero_weight_survey_metadata_preserves_full_design``: survey=
path with PSU/strata + 25% zero-weight units reports full-frame n_psu
(not in-domain subset); ATT bit-parity with physically-dropped fit.
- ``test_bias_corrected_local_linear_zero_weight_matches_filtered``:
explicit-h/b wrapper with zero-weight unit at d=0 (would have flipped
Design 1') matches dropped-sample fit at 1e-12; IF zero-padded to
original length with IF[0]=0 at the zero-weight position.
- ``test_bias_corrected_local_linear_zero_weight_auto_bandwidth``:
auto-bandwidth path (DPI selector also runs on positive-weight
support) produces same h + same bias-corrected estimate as the
dropped-sample fit.
- The existing Round 5 zero-weight tests (``n_obs`` reflects positive-
weight subset; UserWarning; design-not-flipped) pass unchanged since
the design-resolution filter is preserved.
All 366 tests pass (across test_had, test_nprobust_port,
test_bias_corrected_lprobust, test_np_npreg_weighted_parity, and the
slow MC suite). Ruff clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6bd07e7 commit 1998d75
3 files changed
Lines changed: 284 additions & 115 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1673 | 1673 | | |
1674 | 1674 | | |
1675 | 1675 | | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
1679 | | - | |
1680 | | - | |
1681 | | - | |
1682 | | - | |
1683 | | - | |
1684 | | - | |
1685 | | - | |
1686 | | - | |
1687 | | - | |
1688 | | - | |
1689 | | - | |
1690 | | - | |
1691 | | - | |
1692 | | - | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | 1676 | | |
1734 | 1677 | | |
1735 | 1678 | | |
| |||
2563 | 2506 | | |
2564 | 2507 | | |
2565 | 2508 | | |
2566 | | - | |
| 2509 | + | |
2567 | 2510 | | |
2568 | | - | |
2569 | | - | |
2570 | | - | |
2571 | | - | |
2572 | | - | |
2573 | | - | |
2574 | | - | |
2575 | | - | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
2576 | 2529 | | |
2577 | 2530 | | |
2578 | 2531 | | |
| |||
2581 | 2534 | | |
2582 | 2535 | | |
2583 | 2536 | | |
2584 | | - | |
2585 | | - | |
2586 | | - | |
2587 | | - | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
2588 | 2542 | | |
2589 | 2543 | | |
2590 | 2544 | | |
| 2545 | + | |
2591 | 2546 | | |
2592 | 2547 | | |
2593 | 2548 | | |
2594 | | - | |
2595 | | - | |
2596 | | - | |
2597 | | - | |
2598 | | - | |
2599 | | - | |
2600 | 2549 | | |
2601 | 2550 | | |
2602 | 2551 | | |
| |||
2838 | 2787 | | |
2839 | 2788 | | |
2840 | 2789 | | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
2841 | 2796 | | |
2842 | | - | |
2843 | | - | |
| 2797 | + | |
| 2798 | + | |
2844 | 2799 | | |
2845 | 2800 | | |
2846 | | - | |
2847 | | - | |
| 2801 | + | |
| 2802 | + | |
2848 | 2803 | | |
2849 | 2804 | | |
2850 | 2805 | | |
| |||
2907 | 2862 | | |
2908 | 2863 | | |
2909 | 2864 | | |
2910 | | - | |
2911 | | - | |
2912 | | - | |
2913 | | - | |
2914 | | - | |
2915 | | - | |
2916 | | - | |
2917 | | - | |
2918 | | - | |
2919 | | - | |
2920 | | - | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
2921 | 2878 | | |
2922 | | - | |
| 2879 | + | |
2923 | 2880 | | |
2924 | 2881 | | |
2925 | 2882 | | |
2926 | 2883 | | |
2927 | | - | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
2932 | 2888 | | |
2933 | 2889 | | |
2934 | 2890 | | |
2935 | | - | |
| 2891 | + | |
2936 | 2892 | | |
2937 | 2893 | | |
2938 | 2894 | | |
2939 | 2895 | | |
2940 | 2896 | | |
2941 | | - | |
| 2897 | + | |
2942 | 2898 | | |
2943 | 2899 | | |
2944 | 2900 | | |
2945 | 2901 | | |
2946 | | - | |
2947 | | - | |
| 2902 | + | |
| 2903 | + | |
2948 | 2904 | | |
2949 | | - | |
| 2905 | + | |
2950 | 2906 | | |
2951 | 2907 | | |
2952 | 2908 | | |
| |||
2964 | 2920 | | |
2965 | 2921 | | |
2966 | 2922 | | |
2967 | | - | |
2968 | | - | |
2969 | | - | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
2970 | 2927 | | |
2971 | 2928 | | |
2972 | | - | |
| 2929 | + | |
2973 | 2930 | | |
2974 | 2931 | | |
2975 | 2932 | | |
2976 | | - | |
| 2933 | + | |
2977 | 2934 | | |
2978 | 2935 | | |
2979 | 2936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1060 | 1060 | | |
1061 | 1061 | | |
1062 | 1062 | | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1063 | 1080 | | |
1064 | 1081 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1071 | 1116 | | |
1072 | 1117 | | |
1073 | 1118 | | |
| |||
1248 | 1293 | | |
1249 | 1294 | | |
1250 | 1295 | | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
1251 | 1315 | | |
1252 | 1316 | | |
1253 | 1317 | | |
| |||
1261 | 1325 | | |
1262 | 1326 | | |
1263 | 1327 | | |
1264 | | - | |
| 1328 | + | |
1265 | 1329 | | |
1266 | 1330 | | |
1267 | | - | |
| 1331 | + | |
1268 | 1332 | | |
0 commit comments