Two-Sample T-Test with Pingouin
Pingouin is a statistical-type package project that is based on Pandas and NumPy. Pingouin provides a wide range of features. The package is used to conduct the T-Test but also for computing the degree of freedoms, Bayes factor, etc.
Firstly, let’s create the sample data. We are creating two arrays and now let’s perform two sample T-Test. For this purpose, we have ttest() function in the pingouin package of Python. The syntax is given below,
Syntax: ttest(data_group1, data_group2, correction = True/False)
Here,
- data_group1: First data group
- data_group2: Second data group
- correction = “True”: The standard independent two sample t-test will be conducted by taking into consideration the homogeneity assumption.
- correction = “False”: The Welch’s t-test will be conducted by not taking into consideration the homogeneity assumption.
Note that by default equal_var is True
Example:
Python3
# Python program to conduct two-sample # T-test using pingouin library # Importing library from statsmodels.stats.weightstats import ttest_ind import numpy as np import pingouin as pg # Creating data groups data_group1 = np.array([ 160 , 150 , 160 , 156.12 , 163.24 , 160.56 , 168.56 , 174.12 , 167.123 , 165.12 ]) data_group2 = np.array([ 157.97 , 146 , 140.2 , 170.15 , 167.34 , 176.123 , 162.35 , 159.123 , 169.43 , 148.123 ]) # Conducting two-sample ttest result = pg.ttest(data_group1, data_group2, correction = True ) # Print the result print (result) |
Output:
Interpreting the result
This is the time to analyze the result. The p-value of the test comes out to be equal to 0.523, which is greater than the significance level alpha (that is, 0.05). This implies that we can say that the average height of students in one class is statistically not different from the average height of students in another class. Also, the Cohen’s D that is obtained in a t-test is in terms of the relative strength. According to Cohen:
- cohen-d = 0.2 is considered as the ‘small’ effect size
- cohen-d = 0.5 is considered as the ‘medium’ effect size
- cohen-d = 0.8 is considered as the ‘large’ effect size
It implies that even if the two data groups’ means don’t differ by 0.2 standard deviations or more then the difference is trivial, even if it is statistically significant.
How to Conduct a Two Sample T-Test in Python
In this article, we are going to see how to conduct a two-sample T-test in Python.
This test has another name as the independent samples t-test. It is basically used to check whether the unknown population means of given pair of groups are equal. tt allows one to test the null hypothesis that the means of two groups are equal