[Repo Assist] fix(doubly_robust): correct propensity score column index for treatment_value=0 - #1792
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…nt_value=0
The old implementation used int(treatment == received_treatment_value) to index
into predict_proba's output, which evaluates to 1 for the treated arm and 0 for
the control arm. This is correct when treatment_value=1 but wrong when
treatment_value=0: the indices are swapped, giving Pr(T=1|X) instead of Pr(T=0|X)
and vice versa, yielding an incorrect ATE.
Fix: since PropensityScoreEstimator enforces binary {0,1} treatment, sklearn's
classifier always produces classes_=[0,1] (sorted), so predict_proba[:,0]=Pr(T=0|X)
and predict_proba[:,1]=Pr(T=1|X). Indexing with int(treatment) directly gives the
correct probability for any binary treatment coding.
Also removes the now-unused 'received_treatment_value' parameter from _do().
Adds a regression test verifying symmetry between (T=1 treated, T=0 control) and
(T=0 treated, T=1 control) codings.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
31 tasks
This branch has not been deployed
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Bug
DoublyRobustEstimator._do()selects the wrong column frompredict_probawhentreatment_value=0.Root cause
The old code computed the propensity-score column index as:
This evaluates to
1for the treated arm (_do(treatment_value, ...)) and0for the control arm (_do(control_value, ...)). That mapping is only correct whentreatment_value=1:_do(1, ...)withtreatment_value=1Pr(T=1|X)✅_do(0, ...)withtreatment_value=1Pr(T=0|X)✅_do(0, ...)withtreatment_value=0Pr(T=1|X)❌_do(1, ...)withtreatment_value=0Pr(T=0|X)❌When
treatment_value=0(i.e. "treated" units have T=0, "control" units have T=1), the propensity scores are swapped between arms, producing a wrong ATE.Fix
PropensityScoreEstimator.fit()already validates that treatment values are in{0, 1}, so sklearn's classifier always hasclasses_ = [0, 1]. Thereforepredict_proba[:, int(treatment)]directly givesPr(T=treatment|X)for any binary coding:The now-unused
received_treatment_valueparameter is also removed from_do().Test
Added
test_doubly_robust_treatment_value_zerowhich generates the same dataset with two codings (T=1treated vsT=0treated) and verifies that the recovered ATE has the right sign and magnitude in both cases. Before this fix, the flipped-coding estimate diverges significantly.Test Status
black --check✅isort --check✅flake8 --select=E9,F63,F7,F82✅