我希望在Python中快速获得两个均值差的t-test置信区间,类似于R中的函数:
X1 <- rnorm(n = 10, mean = 50, sd = 10)
X2 <- rnorm(n = 200, mean = 35, sd = 14)
# the scenario is similar to my data
t_res <- t.test(X1, X2, alternative = 'two.sided', var.equal = FALSE)
t_res
输出:
Welch Two Sample t-test
data: X1 and X2
t = 1.6585, df = 10.036, p-value = 0.1281
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.539749 17.355816
sample estimates:
mean of x mean of y
43.20514 35.79711
接下来:
>> print(c(t_res$conf.int[1], t_res$conf.int[2]))
[1] -2.539749 17.355816
在statsmodels或scipy中我没有找到类似的内容,这很奇怪,因为显著性区间在假设检验中非常重要(以及最近只报告p值的做法受到了多少批评)。
numpy
、scipy
和pandas
进行手动编码。 - Warm_Duscher