[Tutor] confidence interval

Andrew Fithian afith13 at gmail.com
Thu Jan 14 02:45:40 CET 2010


Hi tutor,

I have this code for generating a confidence interval from an array of
values:
  import numpy as np
  import scipy as sp
  def mean_confidence_interval(data, confidence=0.95):
    a = 1.0*np.array(data)
    n = len(a)
    m, se = np.mean(a), sp.stats.stderr(a)
    h = se * sp.stats.t._ppf((1+confidence)/2., n-1)
    return m, m-h, m+h

This works but I feel there's a better and more succinct way to do this.
Does anyone know of an existing python package that can do this for me?

Thanks,

-Drew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100113/e54f30e5/attachment.htm>


More information about the Tutor mailing list