import numpy as np import scipy.stats def mean_confidence_interval(data, confidence=0.95): a = 1.0 * np.array(data) n = len(a) m, se = np.mean(a), scipy.stats.sem(a) h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1) return m, m-h, m+h
Here is what the above code is Doing:
1. Convert the data to a numpy array.
2. Calculate the mean and standard error of the mean.
3. Calculate the 95% confidence interval.
4. Return the mean, lower bound, and upper bound.