简体   繁体   English

从Python中的t分布和自由度中寻找双尾P值

[英]Finding Two-Tailed P Value from t-distribution and Degrees of Freedom in Python

How do I determine the P Value of a t-distrobution with n degrees of freedom. 如何确定具有n个自由度的t-分布的P值。

Research on this subject points me to this stack exchange answer: https://stackoverflow.com/a/17604216 关于这个主题的研究指出了这个堆栈交换答案: https//stackoverflow.com/a/17604216

I assume np.abs(tt) is the T-value, but how do i work in degrees of freedom, is that the n-1? 我假设np.abs(tt)是T值,但我如何在自由度上工作,是n-1?

Thanks in advance 提前致谢

Yes, n-1 is the degrees of freedom in that example. 是的, n-1是该例子中的自由度。

Given a t-value and a degrees of freedom, you can use the "survival function" sf of scipy.stats.t (aka the complementary CDF) to compute the one-sided p-value. 给定t值和自由度,您可以使用scipy.stats.t (也称为补充CDF)的“生存函数” sf来计算单侧p值。 The first argument is the T value, and the second is the degrees of freedom. 第一个参数是T值,第二个参数是自由度。

For example, the first entry of the table on this page says that for 1 degree of freedom, the critical T value for p=0.1 is 3.078. 例如, 该页面上表格的第一个条目表示,对于1个自由度,p = 0.1的临界T值为3.078。 Here's how you can verify that with t.sf : 以下是使用t.sf验证的t.sf

In [7]: from scipy.stats import t

In [8]: t.sf(3.078, 1)
Out[8]: 0.09999038172554342   # Approximately 0.1, as expected.

For the two-sided p-value, just double the one-sided p-value. 对于双侧p值,只需将单侧p值加倍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM