Python two sample t-test confidence interval

Not sure about Scripy. Maybe there's a Scripy help site that will show the code. [Perhaps this.]

In R, a 95% CI is part of t.test output, where the Welch version of the 2-sample t test is the default [and argument var.eq=T gets you the pooled test].

ts1 = c[11,9,10,11,10,12,9,11,12,9]
ts2 = c[11,13,10,13,12,9,11,12,12,11]
t.test[ts1, ts2]

        Welch Two Sample t-test

data:  ts1 and ts2
t = -1.8325, df = 17.9, p-value = 0.08356
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -2.1469104  0.1469104
sample estimates:
mean of x mean of y 
     10.4      11.4 

Because the 95% CI includes $0$ the 2-sided test does not reject $H_0: \mu_1=\mu_2$ at the 5% level.

The 95% margin of error is $t^*\sqrt{\frac{S_1^2}{n_1}+\frac{S_2^2}{n_2}},$ where $t^*$ cuts probability $0.025=2.5\%$ from the upper tail of Student's t distribution with degrees of freedom $\nu^\prime$ as found from the Welch formula involving sample variances and sample sizes. [Here, $\nu^\prime = 17.9,$ in some software rounded down to an integer. One always has $\min[n_1-1,n_2-1] \le \nu^\prime \le n_1+n_2-2.]$

me = qt[.975, 17.9]*sqrt[var[ts1]/10+var[ts2]/10]; me
[1] 1.146912
pm=c[-1,1]
-1 + pm*me
[1] -2.1469118  0.1469118

It's always a good idea to keep the actual formulas in mind, even if one hopes to use them only rarely.

I am looking for a quick way to get the t-test confidence interval in Python for the difference between means. Similar to this in R:

X1 

Chủ Đề