Home » How to Find the T Critical Value in Python

How to Find the T Critical Value in Python

by Tutor Aspire

Whenever you conduct a t-test, you will get a test statistic as a result. To determine if the results of the t-test are statistically significant, you can compare the test statistic to a T critical value. If the absolute value of the test statistic is greater than the T critical value, then the results of the test are statistically significant.

The T critical value can be found by using a t distribution table or by using statistical software.

To find the T critical value, you need to specify:

  • A significance level (common choices are 0.01, 0.05, and 0.10)
  • The degrees of freedom

Using these two values, you can determine the T critical value to be compared with the test statistic.

How to Find the T Critical Value in Python

To find the T critical value in Python, you can use the scipy.stats.t.ppf() function, which uses the following syntax:

scipy.stats.t.ppf(q, df)

where:

  • q: The significance level to use
  • df: The degrees of freedom

The following examples illustrate how to find the T critical value for a left-tailed test, right-tailed test, and a two-tailed test.

Left-tailed test 

Suppose we want to find the T critical value for a left-tailed test with a significance level of .05 and degrees of freedom = 22:

import scipy.stats

#find T critical value
scipy.stats.t.ppf(q=.05,df=22)

-1.7171

The T critical value is -1.7171. Thus, if the test statistic is less than this value, the results of the test are statistically significant.

Right-tailed test 

Suppose we want to find the T critical value for a right-tailed test with a significance level of .05 and degrees of freedom = 22:

import scipy.stats

#find T critical value
scipy.stats.t.ppf(q=1-.05,df=22)

1.7171

The T critical value is 1.7171. Thus, if the test statistic is greater than this value, the results of the test are statistically significant.

Two-tailed test 

Suppose we want to find the T critical value for a two-tailed test with a significance level of .05 and degrees of freedom = 22:

import scipy.stats

#find T critical value
scipy.stats.t.ppf(q=1-.05/2,df=22)

2.0739

Whenever you perform a two-tailed test, there will be two critical values. In this case, the T critical values are 2.0739 and -2.0739. Thus, if the test statistic is less than -2.0739 or greater than 2.0739, the results of the test are statistically significant.

Refer to the SciPy documentation for the exact details of the t.ppf() function.

You may also like