python - 将置信区间计算为分位数

标签 python confidence-interval

我需要找到 95% 置信区间为 2.5 和 97.5 分位数

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

但是,我收到以下错误----

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

最佳答案

我也面临同样的错误。尝试下面的代码

# 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)

我使用了 import numpy as np,因此使用了 np.mean() 你可以直接尝试使用 boot_after.mean()

关于python - 将置信区间计算为分位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56473741/

相关文章:

r - 提取置信区间 data.table

python - 在 Python 中绘制具有平滑外观的时间序列的导数

python - Matplotlib自定义发散梯度忽略颜色

python - 拟合多峰分布

r - 您将如何绘制具有交互作用及其 CI 的 3D 回归?

r - 使用 bootstrap 进行分位数回归的置信区间

python - 测量Python中某些频率值内发生了多少事件

python - 复制numpy数组的速度

r - R中主成分载荷的置信区间

r - lme4计算协方差的置信区间