

from org.apache.commons.math3.distribution import *
from org.apache.commons.math3.stat.descriptive import *
import math

data=[63.5, 81.3, 88.9, 63.5, 76.2, 67.3, 66.0, 64.8, 74.9, 81.3, 76.2, 72.4, 76.2, 81.3, 71.1, 80.0, 73.7, 74.9, 76.2, 86.4, 73.7, 81.3, 68.6, 71.1, 83.8, 71.1, 68.6, 81.3, 73.7, 74.9]

stats = SummaryStatistics();
for i  in range(len(data)):
      stats.addValue(data[i]);

level=0.95
tDist = TDistribution(stats.getN() - 1);
tVal = tDist.inverseCumulativeProbability(1.0 - (1 - level) / 2);
ci=tVal * stats.getStandardDeviation() / math.sqrt(stats.getN());
lower = stats.getMean() - ci;
upper = stats.getMean() + ci;

print "Confidence Interval 95%: (low, upper): ", lower, upper
