简体   繁体   中英

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.

Research on this subject points me to this stack exchange answer: 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?

Thanks in advance

Yes, n-1 is the degrees of freedom in that example.

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. The first argument is the T value, and the second is the degrees of freedom.

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. Here's how you can verify that with 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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