Add replicate weight support to 7 estimators#253
Conversation
|
Overall Assessment Executive Summary
Path to Approval
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ⛔ Blocker Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Path to Approval
|
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ⛔ Blocker Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Path to Approval
|
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Needs changes Reviewed as a re-review against the provided unified diff and the methodology registry. The prior Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Path to Approval
|
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Re-reviewing the provided diff against the methodology registry and surrounding code, the prior ImputationDiD Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Path to Approval
|
Expand replicate weight variance (BRR, Fay, JK1, JKn) from 4 estimators to 11. New compute_replicate_refit_variance() in survey.py generalizes the existing compute_replicate_vcov() for estimators whose estimation procedure depends on weights (within-transformation, two-stage imputation). Estimator-level changes: - DiD: LinearRegression dispatch (no-absorb) + refit loop (absorb) - MultiPeriodDiD: compute_replicate_vcov (no-absorb) + refit loop (absorb) - TWFE: refit loop re-doing within-transformation per replicate - SunAbraham: refit loop wrapping _fit_saturated_regression, replaces vcov_cohort - StackedDiD: refit loop with Q-weight × replicate weight composition - ImputationDiD: two-stage refit (_fit_untreated_model + _impute) - TwoStageDiD: two-stage refit (_fit_untreated_model + _stage2_static) All estimators reject bootstrap + replicate (mutual exclusion). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- SunAbraham: pass resolved_survey=None to initial fit (prevents bogus replicate dispatch on demeaned data); recompute cohort_ses from the replicate vcov diagonal so results.cohort_effects carries correct SEs - TwoStageDiD: subset replicate_weights when always-treated units are excluded (fixes misaligned arrays); extend refit to return event-study and group effects so aggregate='event_study'/'group'/'all' use replicate-based SEs instead of GMM SEs - ImputationDiD: extend refit to return per-relative-time and per-group ATTs alongside overall ATT; override event-study/group SEs from replicate vcov after running existing aggregation for point estimates - Tests: event-study/group aggregation with replicate weights (Imputation + TwoStage), always-treated unit subsetting, SunAbraham cohort SEs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…StageDiD/ImputationDiD edge cases P0: All 7 estimators now set df=0 (→ NaN inference) when replicate design has undefined df_survey (rank-deficient replicate matrix). Previously fell through to normal distribution with finite p-values. P1: TwoStageDiD replicate event-study/group vector now derived from actual full-sample outputs after horizon_max/balance_e/Prop5 filtering, with real effect values instead of zero placeholders. P1: ImputationDiD replicate SE override now skips non-finite effects (Prop 5 unidentified horizons), preserving their all-NaN status. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…vector mismatch P0: MultiPeriodDiD df<=0 fallback now skipped for replicate designs (df=0 is intentional for NaN inference on rank-deficient replicates). P1: ImputationDiD replicate refit restructured: overall ATT uses separate scalar refit (robust); event-study/group use per-effect scalar refits from actual outputs after Prop5/filtering. Prevents NaN horizons from poisoning the overall ATT variance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ect df - Event-study replicate refits now apply the same balanced-cohort mask as _aggregate_event_study() when balance_e is set, so replicate SEs match the reported estimand - Per-effect replicate refits now capture n_valid and compute effect-specific df (n_valid-1 when replicates dropped) instead of reusing the overall ATT df Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d6ab824 to
cfa36af
Compare
…uisance, balance_e horizon set - SunAbraham: replicate refit now returns fully re-aggregated event-study and overall ATT effects (recomputes IW cohort-share weights from w_r via _compute_iw_effects/_compute_overall_att), not just vcov_cohort - DiD/MultiPeriodDiD/TWFE absorb paths: detect NaN nuisance coefficients from rank-deficient full-sample fit, refit only identified columns, compute reduced replicate vcov, expand back with _expand_vcov_with_nan - ImputationDiD: balance_e mask now uses full treated horizon set (before Prop 5 filtering), matching _aggregate_event_study() exactly Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Re-reviewing the changed replicate-weight paths against Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Path to Approval
|
Add second replicate refit loop for raw (g,e) cohort coefficients so cohort_ses in results.cohort_effects uses replicate-based variance instead of stale analytical SEs from the initial saturated regression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ✅ Looks good Executive Summary
Methodology No unmitigated findings. The changed replicate-weight variance paths are consistent with the Methodology Registry’s updated support matrix, and the Sun-Abraham cohort-level replicate SE gap from the prior review appears resolved (docs/methodology/REGISTRY.md:L2282-L2296, diff_diff/sun_abraham.py:L723-L776). Code Quality
Performance No findings. Maintainability No findings. Tech Debt No findings. The P2 items above are not already tracked in TODO.md:L47-L88. Security No findings. Documentation/Tests
Review note: this was a static diff review. I could not run |
…orb test - ImputationDiD: exclude synthetic reference period (n_obs==0) from replicate event-study override loop to avoid spurious NaN warnings - Add DiD absorb-path replicate test (BRR + absorbed group FE) - TODO.md: track BRR test gap (Fay-like perturbations, not true half-sample) as low-priority deferred item Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ✅ Looks good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
When dropped replicates reduce the effective df, write it back to survey_metadata.df_survey so summary()/exported metadata is consistent with the p-values/CIs actually reported. Matches existing pattern in ContinuousDiD and TripleDifference. Applied to all 7 new estimator replicate paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Static review only: Path to Approval
|
…df=0 P1: Replicate refit closures for TWFE, SunAbraham, DiD/MultiPeriodDiD absorb paths now drop zero-weight observations before weighted demeaning, preventing division-by-zero in within-transformation group means. Matches R's survey::withReplicates() convention. Documented in REGISTRY.md. P2: survey_metadata.df_survey writeback now covers df=0 case (set to None) so summary/metadata is consistent when all replicates fail. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ✅ Looks good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
…REGISTRY notes - SunAbraham: replace fragile .loc label-based assignment with positional df["_rep_wt"] = w_r for replicate weight column - ImputationDiD: consolidate per-effect scalar refits into single vectorized refit returning [overall, es_e0..., grp_g0...], reducing from R×(1+H+G) to R full refits for aggregate="all" - REGISTRY.md: add replicate-refit cross-references to SunAbraham and StackedDiD per-estimator survey notes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ✅ Looks good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Version bump covering silent warning audit (#256), replicate weight expansion (#253), and imputation pre-period coefficients (#252). Adds Phase 8 survey maturity roadmap (SDR, FPC expansion, lonely PSU, CV, weight trimming, compatibility matrix). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
compute_replicate_refit_variance()tosurvey.py— generic callback-based replicate variance for estimators with weight-dependent transformationscompute_replicate_vcov(no-absorb) + refit loop (absorb)_fit_saturated_regression(), replacesvcov_cohort_fit_untreated_model+_impute_treatment_effects)_fit_untreated_model+_stage2_static)Methodology references (required if estimator / math changes)
compute_replicate_vcovandcompute_replicate_if_variancein survey.pyValidation
tests/test_replicate_weight_expansion.py— 15 new smoke tests (7 estimators × {BRR, JK1} + mutual exclusion guards)tests/test_survey_phase6.py— Updated 7 "rejected" tests to "accepted" tests verifying estimators now work with replicate weightsSecurity / privacy
Generated with Claude Code