# How to Find the T Critical Value in Python

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.

## One Reply to “How to Find the T Critical Value in Python”

1. İzzet Türkalp says:

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import seaborn as sns

s1 = np.array([14.67230258, 14.5984991 , 14.99997003, 14.83541808, 15.42533116,
15.42023888, 15.0614731 , 14.43906856, 15.40888636, 14.87811941,
14.93932134, 15.04271942, 14.96311939, 14.0379782 , 14.10980817,
15.23184029])
s2 = np.array([15.23658167, 15.30058977, 15.49836851, 15.03712277, 14.72393502,
14.97462198, 15.0381114 , 15.18667258, 15.5914418 , 15.44854406,
15.54645152, 14.89288726, 15.36069141, 15.18758271, 14.48270754,
15.28841374])

ttest = np.abs(stats.ttest_ind(s1, s2))
print(“t-values: {}, p-values{}” .format(ttest[0],ttest[1]))
criticalvalue = stats.t.ppf(q=1-.05/2,df=30) #for two tailed
print(“Critical value: “, criticalvalue)

if ttest[0] >= criticalvalue:
print(“reject to Null Hypothesis”)
else:
print(“Fail to reject Null Hypothesis”)

sns.kdeplot(s1)
sns.kdeplot(s2)
plt.show()