From e0d003803991d57214e91fe12c18d654fc05f242 Mon Sep 17 00:00:00 2001 From: Amit Sharma Date: Fri, 22 Dec 2023 21:46:00 +0530 Subject: [PATCH] Fix double counting in two sided bootstrap confidence intervals (#1126) * fixed double counting in bootstrap conf interval Signed-off-by: Amit Sharma * fixed double counting in bootstrap conf interval Signed-off-by: Amit Sharma * formatted correctly Signed-off-by: Amit Sharma --------- Signed-off-by: Amit Sharma --- dowhy/causal_estimator.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dowhy/causal_estimator.py b/dowhy/causal_estimator.py index 03f8b70280..061361720d 100755 --- a/dowhy/causal_estimator.py +++ b/dowhy/causal_estimator.py @@ -350,9 +350,11 @@ def _estimate_confidence_intervals_with_bootstrap( bootstrap_variations = [bootstrap_estimate - estimate_value for bootstrap_estimate in bootstrap_estimates] sorted_bootstrap_variations = np.sort(bootstrap_variations) - # Now we take the (1- p)th and the (p)th variations, where p is the chosen confidence level - upper_bound_index = int((1 - confidence_level) * len(sorted_bootstrap_variations)) - lower_bound_index = int(confidence_level * len(sorted_bootstrap_variations)) + # Now we take the (1-p)/2 th and the 1-(1-p)/2 th variations, where p is the chosen confidence level + left_fraction = (1 - confidence_level) / 2 + right_fraction = 1 - left_fraction + upper_bound_index = int(left_fraction * len(sorted_bootstrap_variations)) + lower_bound_index = int(right_fraction * len(sorted_bootstrap_variations)) # Get the lower and upper bounds by subtracting the variations from the estimate lower_bound = estimate_value - sorted_bootstrap_variations[lower_bound_index]