Created
September 19, 2013 17:58
-
-
Save paulgb/6627336 to your computer and use it in GitHub Desktop.
Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
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
from scipy.stats import beta | |
def binom_interval(success, total, confint=0.95): | |
quantile = (1 - confint) / 2. | |
lower = beta.ppf(quantile, success, total - success + 1) | |
upper = beta.ppf(1 - quantile, success + 1, total - success) | |
return (lower, upper) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think this works if success equals zero or total. You need to calculate a one-sided interval in those cases.