Improve se accuracy wif#63
Merged
Merged
Conversation
Implement weight influence function (wif) adjustment for the "simple" aggregation in CallawaySantAnna, matching R's `did` package approach. Changes: - Add _compute_aggregated_se_with_wif() method that accounts for uncertainty in estimating group-size weights - Update _aggregate_simple() to use the new wif-adjusted SE calculation - Add tests/test_se_accuracy.py for SE accuracy testing and regression Results: - SE difference reduced from ~2.5% to ~1.2% across all scales - Point estimates unchanged (ATT diff < 1e-10) - No performance regression - All existing tests pass Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The weight influence function (wif) formula had two issues causing ~1.1% SE difference vs R: 1. pg computation: Used n_g / total_treated instead of n_g / n_all 2. wif iteration: Iterated over groups with averaged ATT instead of keepers (post-treatment pairs) with individual ATT(g,t) values Now implements R's exact formula: - if1[i,k] = (indicator(G_i == group_k) - pg[k]) / sum(pg[keepers]) - if2[i,k] = indicator_sum[i] * pg[k] / sum(pg[keepers])^2 - wif[i,k] = if1[i,k] - if2[i,k] - wif_contrib[i] = sum_k(wif[i,k] * att[k]) Result: SE now matches R within <0.01% (essentially exact match). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The test_se_vs_r_benchmark test requires specific benchmark data with known R values. This data is generated locally and not committed to the repo. The test now skips gracefully in CI with a helpful message. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.