comparison python/utils.py @ 499:0a93afea8243

alternative confidence interval
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 09 May 2014 14:09:02 -0400
parents 343cfd185ca6
children ad518f0c3218
comparison
equal deleted inserted replaced
496:b96ff16b1c81 499:0a93afea8243
34 if printLatex: 34 if printLatex:
35 print('${0}^2\\frac{{{1}^2}}{{{2}^2}}$'.format(k, stdev, tolerance)) 35 print('${0}^2\\frac{{{1}^2}}{{{2}^2}}$'.format(k, stdev, tolerance))
36 return (k*stdev/tolerance)**2 36 return (k*stdev/tolerance)**2
37 37
38 def confidenceInterval(mean, stdev, nSamples, percentConfidence, trueStd = True, printLatex = False): 38 def confidenceInterval(mean, stdev, nSamples, percentConfidence, trueStd = True, printLatex = False):
39 'if trueStd, use normal distribution, otherwise, Student' 39 '''if trueStd, use normal distribution, otherwise, Student
40
41 Use otherwise t.interval or norm.interval
42 ex: norm.interval(0.95, loc = 0., scale = 2.3/sqrt(11))
43 t.interval(0.95, 10, loc=1.2, scale = 2.3/sqrt(nSamples))
44 loc is mean, scale is sigma/sqrt(n) (for Student, 10 is df)'''
40 from math import sqrt 45 from math import sqrt
41 from scipy.stats.distributions import norm, t 46 from scipy.stats.distributions import norm, t
42 if trueStd: 47 if trueStd:
43 k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200. 48 k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200.
44 else: # use Student 49 else: # use Student