Confidence interval for means with unknown standard deviation using the Student t distribution.
Code: "stat_conf_interval.py". Programming language: Python
DMelt Version 1. Last modified: 05/25/2015. License: Pro
https://datamelt.org/code/cache/stat_conf_interval_8466.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
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
You see the box below because you did not login.