来自 t 统计量的 Python p 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17559897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python p-value from t-statistic
提问by Andrew Latham
I have some t-values and degrees of freedom and want to find the p-values from them (it's two-tailed). In the real world I would use a t-test table in the back of a Statistics textbook; how do I do the equivalent in Python?
我有一些 t 值和自由度,想从中找到 p 值(它是双尾的)。在现实世界中,我会使用统计学教科书后面的 t 检验表;我如何在 Python 中做等效的事情?
e.g.
例如
t-lookup(5, 7) = 0.00245
or something like that.
t-lookup(5, 7) = 0.00245
或类似的东西。
I know in SciPy if I had arrays I could do scipy.stats.ttest_ind
, but I don't. I just have t-statistics and degrees of freedom.
我知道在 SciPy 中是否有我可以做的数组scipy.stats.ttest_ind
,但我没有。我只有 t 统计量和自由度。
采纳答案by Andrew Latham
From http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html
来自 http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html
As an exercise, we can calculate our ttest also directly without using the provided function, which should give us the same answer, and so it does:
作为练习,我们也可以不使用提供的函数直接计算我们的 ttest ,这应该给我们相同的答案,所以它这样做:
tt = (sm-m)/np.sqrt(sv/float(n)) # t-statistic for mean
pval = stats.t.sf(np.abs(tt), n-1)*2 # two-sided pvalue = Prob(abs(t)>tt)
print 't-statistic = %6.3f pvalue = %6.4f' % (tt, pval)
t-statistic = 0.391 pvalue = 0.6955