计算一个样本中某个比例的置信区间 [英] Calculating Confidence Interval for a Proportion in One Sample
问题描述
当样本量很小甚至样本量为 1 时,计算某个比例的置信区间 (CI) 的更好方法是什么?
What would be a better way to calculate Confidence Interval (CI) for a proportion when the sample size is small and even the sample size is 1?
我目前正在计算一个样本中某个比例的 CI:
I am currently calculating CI for a Proportion in One Sample w/:
但是,我的样本量很小,有时甚至是1.我也尝试过小总体的比例 p 的近似 (1−α)100% 置信区间使用:
However, my sample size is very small, sometimes it is even 1. I also tried An approximate (1−α)100% confidence interval for a proportion p of a small population using:
具体来说,我正在尝试实施这两个公式来计算比例的 CI.如下图所示,在 2018 年第一季度,蓝色组周围没有 CI,因为在 2018 年第一季度有十分之一的人选择了该项目.如果使用有限种群校正 (FPC),如果 N 为 1,则不会校正 CI.所以,我的问题是,以 100% 的比例解决这个小样本量问题的最佳统计方法是什么.
Specifically, I'm trying to implement those two formulas to calculate the CI for proportion. As you see on the graph below, at 2018-Q1, the blue group has no CI around it because there is 1 out of 1 ppl choosing that item at 2018-Q1. If using the Finite Population Correction (FPC), it doesn't correct the CI if N is 1. So, my question is that what would be the best statistical way to solve this small sample size issue with 100% proportion.
- 如果你能在python中提供一个包来计算它会很棒吗?谢谢!
推荐答案
尝试statsmodels.stats.proportion.proportion_confint
Try statsmodels.stats.proportion.proportion_confint
http://www.statsmodels.org/devel/generated/statsmodels.stats.proportion.proportion_confint.html
根据他们的文档,您可以这样使用它:
According to their documentation, you use it like this:
ci_low, ci_upp = proportion_confint(count, nobs, alpha=0.05, method='normal')
参数在哪里:
- count (int or array_array_like) – 成功的次数,可以是pandas Series或DataFrame
- nobs (int) – 试验总数
- alpha (float in (0, 1)) – 显着性水平,默认 0.05
method (string in ['normal']) – 用于置信区间的方法,目前可用的方法:
- count (int or array_array_like) – number of successes, can be pandas Series or DataFrame
- nobs (int) – total number of trials
- alpha (float in (0, 1)) – significance level, default 0.05
method (string in ['normal']) – method to use for confidence interval, currently available methods:
- normal : 渐近正态近似
- agresti_coull:Agresti-Coull 区间
- beta:基于 Beta 分布的 Clopper-Pearson 区间
- wilson : Wilson 分数区间
- jeffreys:杰弗里斯贝叶斯区间
- binom_test : 实验性的,binom_test 的反演
这篇关于计算一个样本中某个比例的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!