Paired T-test
tags: #statistics/inferential/ttest/paired
What is a paired t-test?
The data is described as unpaired or independent when the sets of data arise from separate individuals or paired when it arises from the same individual at different points in time, e.g.,you might have before-and-after measurements for a group of people.
Need to recognize paired data when you have it because two-sampled t-tests are not valid unless they are independent. Paired data ARE NOT independent.
The paired sample t-test is also called dependent sample t-test, used when we are interested in the difference between two measures for the same subject (i.e., sample) separated by time[1].
Shares the same assumption as {Test} Two-Sample (Independent) T-tests, including:
To apply the paired t-test to test for differences between paired measurements, the following assumptions need to hold:
-
Subjects are independent i.e., outcome of one subject does not influence the outcome of another
-
Each of the paired measurements must be obtained from the same subject.
-
The DV for each samples are normally distributed (e.g., before and after)
If assumptions are violated (e.g., not normally distributed) an appropriate alternative to use would be the Wilcoxon signed-rank Test.
Hypothesis Model
In a paired t-test, you are testing whether the mean differences are statistically different from 0 or not:
The test statistic is calculated as:
With a degree of freedom of
Running Paired T-tests in Python
To conduct the paired sample t-test, we can use the stats.ttest_rel() function from SciPy:
from scripy.stats import ttest_rel
# conduct paried t test
ttest_rel(a, b, alternative="two-sided", alpha=0.05)
# a, b - array-like observations of the sample (before and after)
# alternative - type of hypothesis testing (two-tailed, greater, or less)
This returns a tuple of:
(statistic, p-value)