Skip to content

Instantly share code, notes, and snippets.

@DavidWalz
Created January 21, 2014 11:29
Show Gist options
  • Save DavidWalz/8538435 to your computer and use it in GitHub Desktop.
Save DavidWalz/8538435 to your computer and use it in GitHub Desktop.
python: clopper pearson binomial confidence belt
import scipy.stats
def clopper_pearson(k,n,alpha=0.32):
"""
http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
alpha confidence intervals for a binomial distribution of k expected successes on n trials
Clopper Pearson intervals are a conservative estimate.
"""
lo = scipy.stats.beta.ppf(alpha/2, k, n-k+1)
hi = scipy.stats.beta.ppf(1 - alpha/2, k+1, n-k)
return lo, hi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment