comparison python/utils.py @ 511:ad518f0c3218

merged pulling from main
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 28 May 2014 17:46:38 -0400
parents 935430b1d408 0a93afea8243
children 0c86c73f3c09
comparison
equal deleted inserted replaced
510:b0dac840c24f 511:ad518f0c3218
30 if printLatex: 30 if printLatex:
31 print('${0}^2\\frac{{{1}^2}}{{{2}^2}}$'.format(k, stdev, tolerance)) 31 print('${0}^2\\frac{{{1}^2}}{{{2}^2}}$'.format(k, stdev, tolerance))
32 return (k*stdev/tolerance)**2 32 return (k*stdev/tolerance)**2
33 33
34 def confidenceInterval(mean, stdev, nSamples, percentConfidence, trueStd = True, printLatex = False): 34 def confidenceInterval(mean, stdev, nSamples, percentConfidence, trueStd = True, printLatex = False):
35 'if trueStd, use normal distribution, otherwise, Student' 35 '''if trueStd, use normal distribution, otherwise, Student
36
37 Use otherwise t.interval or norm.interval
38 ex: norm.interval(0.95, loc = 0., scale = 2.3/sqrt(11))
39 t.interval(0.95, 10, loc=1.2, scale = 2.3/sqrt(nSamples))
40 loc is mean, scale is sigma/sqrt(n) (for Student, 10 is df)'''
36 from math import sqrt 41 from math import sqrt
37 from scipy.stats.distributions import norm, t 42 from scipy.stats.distributions import norm, t
38 if trueStd: 43 if trueStd:
39 k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200. 44 k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200.
40 else: # use Student 45 else: # use Student