Created
January 21, 2014 11:29
-
-
Save DavidWalz/8538435 to your computer and use it in GitHub Desktop.
python: clopper pearson binomial confidence belt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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