【发布时间】:2015-10-24 10:46:14
【问题描述】:
我正在寻找一种快速方法来获取 Python 中的 t 检验置信区间,以了解均值之间的差异。与 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 值的做法受到了多少批评)。
【问题讨论】:
-
我都标记了它;也许使用 R 的人知道 Python 的答案。现在很多人都同时使用。
-
statsmodels里有,但是界面不太方便statsmodels.org/stable/generated/…
-
这些函数中的哪一个可以满足我的要求?
-
相当多的SO问题举例,请看t test和confidence interval
-
我查看了很多 SO 示例,但没有一个能准确地解决我想要做的事情。我需要计算均值差异的 t 检验的置信区间,而不是描述我的数据的 t 检验。
标签: python statistics hypothesis-test