Skip to content

Conversation

@igerber
Copy link
Owner

@igerber igerber commented Jan 14, 2026

No description provided.

igerber and others added 3 commits January 14, 2026 15:20
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>
@igerber igerber merged commit f87946c into main Jan 14, 2026
4 checks passed
@igerber igerber deleted the improve-se-accuracy-wif branch January 14, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants