Skip to content

Instantly share code, notes, and snippets.

@Sandy4321
Forked from paulgb/binom_interval.py
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sandy4321/592519d2cd9eafab0071 to your computer and use it in GitHub Desktop.
Save Sandy4321/592519d2cd9eafab0071 to your computer and use it in GitHub Desktop.
Compute two-sided binomial confidence interval in Python. Based on R's binom.test.
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