Add random_state to CausalEstimator for reproducible bootstrap CIs and significance tests#1556
Open
immu4989 wants to merge 2 commits into
Open
Add random_state to CausalEstimator for reproducible bootstrap CIs and significance tests#1556immu4989 wants to merge 2 commits into
immu4989 wants to merge 2 commits into
Conversation
…d significance tests Signed-off-by: Imran Ahamed <immu4989@gmail.com>
0f97a2f to
5ff18ed
Compare
This was referenced May 31, 2026
Signed-off-by: Amit Sharma <amit_sharma@live.com>
amit-sharma
approved these changes
Jun 6, 2026
Member
amit-sharma
left a comment
There was a problem hiding this comment.
thanks for this fix @immu4989 . Much appreciated
Member
|
@all-contributors please add @immu4989 for code |
Contributor
|
I've put up a pull request to add @immu4989! 🎉 |
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.
Closes #418
Closes #556
What
Bootstrap confidence intervals and significance tests in the shared
CausalEstimatorbase class are non-deterministic, because they draw from the global numpy random state:_generate_bootstrap_estimatescallssklearn.utils.resample(...)with norandom_state, so bootstrap CIs differ between runs._test_significance_with_bootstrapcallsnp.random.permutation(...), so bootstrap p-values differ between runs.This affects every estimator that uses bootstrap CIs or significance testing.
Changes
random_stateparameter (intornp.random.RandomState, defaultNone) toCausalEstimator._get_random_state()and use it to seed bothresample(...)and the permutation in the significance test.random_state=Nonepreserves the existing (non-deterministic) behavior, so this is backward compatible.propensity_score_modelis left untouched.random_stateproduce identical confidence intervals and p-values, while different seeds differ.Usage
Verification