问题
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?
I am currently calculating CI for a Proportion in One Sample w/:
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:
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.
- It would be great if you can provide a package in python to calculate it? Thanks!
回答1:
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')
Where the parameters are:
- 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 : asymptotic normal approximation
- agresti_coull : Agresti-Coull interval
- beta : Clopper-Pearson interval based on Beta distribution
- wilson : Wilson Score interval
- jeffreys : Jeffreys Bayesian Interval
- binom_test : experimental, inversion of binom_test
来源:https://stackoverflow.com/questions/51794473/calculating-confidence-interval-for-a-proportion-in-one-sample