Add research-grade DGP parameters for survey tutorials#274
Conversation
Add 6 new optional parameters (icc, weight_cv, informative_sampling, heterogeneous_te_by_strata, strata_sizes, return_true_population_att) that enable coverage studies and tutorials demonstrating when survey- design methods outperform naive estimators. All default to current behavior for backward compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Overall Assessment
Executive Summary
Methodology
Code Quality
Performance No material findings in the changed code. Maintainability No material findings beyond the documentation/test gaps below. Tech Debt No existing Security No material findings. Documentation/Tests
Path to Approval
|
…alidation - Reverse _rank_pair_weights() so higher Y(0) → heavier weight (w=1/pi) - Replace icc_realized with ANOVA ICC on period-1 data (matches icc solver) - Add np.isfinite() guard on weight_cv to reject NaN/Inf - Fix test assertions: positive correlation, ICC regression check, NaN/Inf test 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 No material findings. Maintainability No material findings beyond the test/documentation gaps below. Tech Debt
Security No material findings. Documentation/Tests
Path to Approval
|
…lidation - Scale rank weights by stratum mean to preserve weight_variation structure - Update informative_sampling and icc_realized docstrings to match code - Add integer type validation for strata_sizes - Add tests: default weight_variation path, positive correlation, float rejection 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
Path to Approval
|
- Include covariate variance (0.2725) in ICC calibration when add_covariates=True - Document informative_sampling structural Y(0) ranking in docstring and REGISTRY.md - Add cross-section default-weights test and ICC + covariates regression test 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
|
- Pre-draw covariates before ranking step for both panel and cross-section paths when add_covariates=True, include in Y(0) for rank-pairing - Update docstrings: icc formula includes covariate variance, informative sampling includes covariates in ranking - Update REGISTRY.md: remove structural-only deviation, document full covariate inclusion - Add panel + cross-section tests for informative_sampling + add_covariates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Needs changes. One unmitigated P1 remains in the new survey DGP methodology path. Executive Summary
Methodology Cross-checking the changed survey DGP code against the registry and docstring shows the documented
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
Static review only: I could not execute Path to Approval
|
Raise ValueError when icc is set but unit_fe_sd=0, noise_sd=0, and add_covariates=False, since the target ICC is unattainable with zero non-PSU variance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment Needs changes (highest unmitigated severity: P1). Executive Summary
Methodology Affected methods: survey DGP ICC calibration, informative sampling via rank-pairing, stratum-specific treatment-effect DGP, and the new Cross-check result: I did not find an undocumented mismatch in the
Code Quality No findings in the changed lines. Performance No findings in the changed lines. Maintainability No findings in the changed lines. Tech Debt No separate tech-debt finding. Security No findings in the changed lines. Documentation/Tests
Path to Approval
|
- population_att returns NaN when no treated units (was 0.0) - icc_realized returns NaN when period-1 has < 2 groups or no within-PSU replication (was finite sentinel) - Matches library NaN-for-undefined convention 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 — no unmitigated P0/P1 findings. Executive Summary
Methodology No findings. Affected methods were survey-DGP ICC calibration, informative sampling via within-stratum rank-pairing, stratum-specific treatment effects, and the new Code Quality No findings. Performance No findings. Maintainability No findings. Tech Debt No findings. I did not find a relevant pre-existing Security No findings. Documentation/Tests
|
- covariate_effects=(beta1, beta2) replaces hardcoded (0.5, 0.3) coefficients for x1/x2 in outcome, ICC calibration, and informative sampling ranking - te_covariate_interaction adds TE_i = base_TE + gamma * x1_i for unit-level treatment effect heterogeneity (requires add_covariates) - Both default to current behavior for backward compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ⛔ Blocker — one unmitigated P0 and one unmitigated P1 remain in the changed code. Executive Summary
Path to Approval
Methodology
No other unmitigated methodology mismatch stood out in the changed math itself; the new ICC calibration and the documented inclusion of covariates in the informative-sampling ranking look aligned between diff_diff/prep_dgp.py:L1258-L1278 and docs/methodology/REGISTRY.md:L2520-L2527. Code Quality
Performance No findings. Maintainability No findings. Tech Debt No findings. I did not find a matching mitigation entry in TODO.md:L51-L76 for the P0/P1 issues above, so they remain unmitigated. Security No findings. Documentation/Tests
|
- Add type/length/finiteness validation for covariate_effects and te_covariate_interaction - Rename stratum_effects to base_stratum_effects in dgp_truth to clarify these are base TEs before dynamic/covariate modifiers - Add validation rejection tests for malformed inputs 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: no unmitigated P0 or P1 findings remain in the changed files. The previous P0 around non-finite input propagation and the previous P1 around misleading stratum-level truth metadata both appear resolved in substance in diff_diff/prep_dgp.py:L1417-L1436 and diff_diff/prep_dgp.py:L1679-L1715, with regression coverage in tests/test_prep.py:L1757-L1775 and tests/test_prep.py:L1892-L1915. Executive Summary
Methodology No unmitigated P0 or P1 methodology defects remain. The two methodology sensitive changes in scope, ICC calibration and informative sampling with covariates, match the code path described in the new registry entries.
Code Quality No findings. Performance No findings. Maintainability No findings. Tech Debt No findings. I did not find a matching mitigation entry in Security No findings. Documentation/Tests
|
…ing test - REGISTRY.md: generalize ICC covariate variance to beta1²/beta2² formula - Docstring: fix stratum_effects → base_stratum_effects key name - Add direct covariate-ranking test: covariates dominate Y(0), verify weight assignment changes with nonzero vs zero covariate effects 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 — no unmitigated P0 or P1 findings remain in the changed files. Executive Summary
Methodology Affected methods reviewed: No findings. Code Quality No findings. Performance No findings. Maintainability No findings. Tech Debt No findings. Security No findings. Documentation/Tests
Execution note: test execution was not possible in this environment because |
Summary
generate_survey_did_data():icc,weight_cv,informative_sampling,heterogeneous_te_by_strata,strata_sizes,return_true_population_att_rank_pair_weights()helper for informative sampling with panel and cross-section supportMethodology references (required if estimator / math changes)
Validation
tests/test_prep.py— 13 new tests inTestSurveyDGPResearchGrade(ICC targeting, weight CV, informative sampling panel+cross-section, heterogeneous TE, strata sizes, backward compatibility)Security / privacy
Generated with Claude Code