Skip to content

Instantly share code, notes, and snippets.

@herrbuerger
Created March 5, 2014 12:31
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 herrbuerger/9366299 to your computer and use it in GitHub Desktop.
Save herrbuerger/9366299 to your computer and use it in GitHub Desktop.
from math import sqrt
def confidence(ups, downs):
n = ups + downs
if n == 0:
return 0
z = 1.96 #1.96 = 95%
phat = float(ups) / n
return ((phat + z*z/(2*n) - z * 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