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?
e.g.
t-lookup(5, 7) = 0.00245
or something like that.
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.
Suppose we want to find the p-value associated with a t-score of 1.24 and df = 22 in a two-tailed hypothesis test. To find this two-tailed p-value we simply multiplied the one-tailed p-value by two. The p-value is 0.2280.
For an upper-tailed test, the p-value is equal to one minus this probability; p-value = 1 - cdf(ts). For a two-sided test, the p-value is equal to two times the p-value for the lower-tailed p-value if the value of the test statistic from your sample is negative.
The p-value is about the strength of a hypothesis. We build hypothesis based on some statistical model and compare the model's validity using p-value. One way to get the p-value is by using T-test.
The larger the absolute value of the t-value, the smaller the p-value, and the greater the evidence against the null hypothesis.
From 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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With