Skip to content

Instantly share code, notes, and snippets.

@bshlgrs
Last active August 29, 2015 13:56
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 bshlgrs/9015672 to your computer and use it in GitHub Desktop.
Save bshlgrs/9015672 to your computer and use it in GitHub Desktop.
from sympy.statistics import Normal
def getStdDev(distance,confidence,x = Normal(0,1)):
"Distance = end point - mean"
confidenceDistance = x.confidence(confidence)[1]
stddev = confidenceDistance * distance
return stddev
def confidenceInterval(start,end,confidence):
"""If I give a 50 percent chance that my variable x is between 10 and 13,
then this function converts that to a Gaussian centered at 11.5 with an
appropriate standard deviation."""
mean = 0.5*(end+start)
stddev = getStdDev(0.5*(end-start), confidence)
return (mean,stddev)
print confidenceInterval(300,500,0.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment