Sharedobe
Sharedobe

Reputation: 145

Calculating Confidence Interval for a Proportion in One Sample

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/: enter image description here

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: enter image description here

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.

enter image description here

Upvotes: 6

Views: 9842

Answers (1)

Kelvin
Kelvin

Reputation: 855

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

Upvotes: 6

Related Questions