1
votes

I need to find the 95% confidence interval as 2.5 and 97.5 quantiles

boot_mean_diff = []
for i in range(3000):
    boot_before = before_proportion
    boot_after = after_proportion
    boot_mean_diff.append(boot_after.mean()-boot_before.mean())

# Calculating a 95% confidence interval from boot_mean_diff 
boot_mean_diff=pd.Series(boot_mean_diff)
#boot_mean_diff1=boot.boot_mean_diff(frac=1,replace=True)
confidence_interval = pd.Series(boot_mean_diff).quantile([0.025,0.975])
confidence_interval

However, I am getting the error below ----

AssertionError: confidence_interval should be calculated as the [0.025, 0.975] quantiles of boot_mean_diff.

1
What are before_proportion and after_proportion? - foxpal
Its the proportion of deaths before a particular period and after a period. The datatype is Series - Esha
I tried your code, with some fake 1-D data I made up for before_proportion and after_proportion, and it works fine. Could you edit your code to provide a minimum working example, including those two Series? - foxpal
I get the output too. in a matrix form 0.025 -0.083957 0.975 -0.083957 dtype: float64 - Esha
If you're getting an output, where is the error raised? - foxpal

1 Answers

0
votes

I was too facing the same error. Try the below code

# A bootstrap analysis of the reduction of deaths due to handwashing
boot_mean_diff = []
for i in range(3000):
    boot_before = before_proportion.sample(frac=1, replace=True)
    boot_after = after_proportion.sample(frac=1, replace=True)
    boot_mean_diff.append(np.mean(boot_after) - np.mean(boot_before))

# Calculating a 95% confidence interval from boot_mean_diff 
confidence_interval = pd.Series(boot_mean_diff).quantile([0.025, 0.975])
print(confidence_interval)

I have used import numpy as np, thus using np.mean() you can directly try with boot_after.mean()