Skip to content

Instantly share code, notes, and snippets.

@ksamson
Created July 3, 2018 05:54
Show Gist options
  • Save ksamson/15b3945fc4fbc818773882a73e228597 to your computer and use it in GitHub Desktop.
Save ksamson/15b3945fc4fbc818773882a73e228597 to your computer and use it in GitHub Desktop.
Confidence Interval python implementation based on http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
import math
import scipy.stats as st
def ci_lower_bound(pos, n, confidence=None, z=None):
if n == 0:
return 0
if z is None:
z = st.norm.ppf(1 - (1 - confidence) / 2)
phat = 1.0 * pos / n
return (phat + z * z / (2 * n) - z * math.sqrt((phat * (1 - phat) + z * z / (4 * n)) / n)) / (1 + z * z / n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment