Repository navigation
Fix standard errors in marginal_effects - #5297
Closed
raashish1601 wants to merge 1 commit into
Closed
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
|
@saitcakmak has imported this pull request. If you are a Meta employee, you can view this in D123916702. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5297 +/- ##
==========================================
- Coverage 96.60% 96.59% -0.01%
==========================================
Files 621 621
Lines 70952 70966 +14
==========================================
+ Hits 68541 68550 +9
- Misses 2411 2416 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@saitcakmak merged this pull request in f4e58e0. |
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.
marginal_effects(used byMarginalEffectsPlot) got two things wrong when computing the SE of each level's relative effect:inverse_variance_weightreturns(mean, variance), but the second value was stored asoverall_semand passed torelativizeas the control SEM. So the variance of the overall mean was used where its standard error is expected.relativizewas called withcov_means=0.0, but the level's mean is computed from a subset of the same observations as the overall mean, so the two are correlated. With inverse variance weights, the covariance between a group's weighted mean and the overall weighted mean is the variance of the overall mean.This PR passes
np.sqrt(overall_var)as the control SEM andoverall_varascov_means.To check the result, I simulated the arm means many times and compared the spread of the relative effect with the reported SE. With means
[1, 2, 3, 4]and SEMs[0.05, 0.2, 0.1, 0.3]in two levels:The expected values in
test_marginal_effectschanged accordingly. The Betas move slightly too, because the bias correction inrelativizenow sees the real control SEM. I also addedtest_marginal_effects_se_matches_simulation, which compares the SEs with a simulation like the one above. Both tests fail on main.Ran
ax/utils/stats/tests/test_statstools.pyandax/analysis/plotly/tests/test_marginal_effects.py(Linux, Python 3.12), and black and flake8 on the changed files.