changeset 301:27f06d28036d

added simple helper for confidence intervals
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 11 Mar 2013 01:07:08 -0400
parents f65b828e5521
children 9d88a4d97473
files python/utils.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/python/utils.py	Wed Feb 13 18:26:49 2013 -0500
+++ b/python/utils.py	Mon Mar 11 01:07:08 2013 -0400
@@ -58,6 +58,15 @@
 # simple statistics
 #########################
 
+def confidenceInterval(mean, stdev, nSamples, percentConfidence, printLatex = False):
+    from math import sqrt
+    from scipy.stats.distributions import norm
+    k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200.
+    e = k*stdev/sqrt(nSamples)
+    if printLatex:
+        print('${0} \pm {1}\\frac{{{2}}}{{\sqrt{{{3}}}}}$'.format(mean, k, stdev, nSamples))
+    return mean-e, mean+e
+
 def computeChi2(expected, observed):
     '''Returns the Chi2 statistics'''
     result = 0.