Confidence Interval for t-test (difference between means) in Python
Here how to use StatsModels' CompareMeans
to calculate the confidence interval for the difference between means:
import numpy as np, statsmodels.stats.api as smsX1, X2 = np.arange(10,21), np.arange(20,26.5,.5)cm = sms.CompareMeans(sms.DescrStatsW(X1), sms.DescrStatsW(X2))print cm.tconfint_diff(usevar='unequal')
Output is
(-10.414599391793885, -5.5854006082061138)
and matches R:
> X1 <- seq(10,20)> X2 <- seq(20,26,.5)> t.test(X1, X2) Welch Two Sample t-testdata: X1 and X2t = -7.0391, df = 15.58, p-value = 3.247e-06alternative hypothesis: true difference in means is not equal to 095 percent confidence interval: -10.414599 -5.585401sample estimates:mean of x mean of y 15 23