Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python p-value from t-statistic

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.

like image 591
Andrew Latham Avatar asked Jul 09 '13 23:07

Andrew Latham


People also ask

How do you find the p-value from T stat in Python?

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.

How do you get the p-value from the t-value?

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.

What is the p-value in Python?

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.

How is p-value related to t statistic?

The larger the absolute value of the t-value, the smaller the p-value, and the greater the evidence against the null hypothesis.


1 Answers

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 
like image 104
Andrew Latham Avatar answered Oct 09 '22 16:10

Andrew Latham