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]