comparison python/utils.py @ 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 f6f423e25c7f
children 20f9cd972dde
comparison
equal deleted inserted replaced
300:f65b828e5521 301:27f06d28036d
55 return optionValues 55 return optionValues
56 56
57 ######################### 57 #########################
58 # simple statistics 58 # simple statistics
59 ######################### 59 #########################
60
61 def confidenceInterval(mean, stdev, nSamples, percentConfidence, printLatex = False):
62 from math import sqrt
63 from scipy.stats.distributions import norm
64 k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200.
65 e = k*stdev/sqrt(nSamples)
66 if printLatex:
67 print('${0} \pm {1}\\frac{{{2}}}{{\sqrt{{{3}}}}}$'.format(mean, k, stdev, nSamples))
68 return mean-e, mean+e
60 69
61 def computeChi2(expected, observed): 70 def computeChi2(expected, observed):
62 '''Returns the Chi2 statistics''' 71 '''Returns the Chi2 statistics'''
63 result = 0. 72 result = 0.
64 for e, o in zip(expected, observed): 73 for e, o in zip(expected, observed):