Here is what is covered in this section:
What is it?
The paired sample t-test is also called dependent sample t-test. It’s an univariate test that tests for a significant difference between 2 related variables. An example of this is if you where to collect the blood pressure for an individual before and after some treatment, condition, or time point.
The hypothesis being test is:
- Null hypothesis (H0): ud = 0, which translates to the mean difference between sample 1 and sample 2 is equal to 0.
- Alternative hypothesis (HA): ud ≠ 0, which translates to the mean difference between sample 1 and sample 2 is not equal to 0.
If the p-value is less than what is tested at, most commonly 0.05, one can reject the null hypothesis.
Paired Sample t-test Assumptions
In order for the paired sample t-test results to be trusted, the following assumptions need to be met:
- The dependent variable (DV) must be continuous which is measured on an interval or ratio scale
- The DV should be approximately normally distributed
- Testing for normality needs to be conducted on the differences between the two conditions, not the raw values of each condition itself
- The paired sample t-test is robust to this violation. If there is a violation of normality, as long as it’s not in a major violation the test results can be considered valid
- The DV should not contain any significant outliers
If any of these assumptions are violated, a different test should be used. An alternative to the paired sample t-test is the Wilcoxon signed-rank Test.
Data used in this example
The data used in this example can be found on our GitHub page. The data set is fictitious and contains blood pressure readings before and after an intervention. These are variables “bp_before” and “bp_after”.
Let’s import pandas as pd, the data, and then take a look at the data!
Checking the Assumptions
Assumption Check: Outliers
First thing we need to do is import the stats library and then test the assumptions of the paired samples t-test. First let’s check for any significant outliers in each of the variables.
There doesn’t appear to be any significant outliers in the variables.
Assumption Check: Normal Distribution
Remember that for the dependent sample T-test the normality check needs to be conducted on differences between the two scores. There are a few ways one can test this assumption – make a histogram, use a Q-Q plot, and/or use a statistical test. Let’s create a variable for the differences and run through these.
The histogram of our data seems to be normally distributed. Another way to check for normally distributed data is to use a Q-Q plot. If you’re unfamiliar with how to read a Q-Q plot, the data should be on the red line. If it’s not, then it suggests that the data may not be normally distributed.
There is some deviation from normality, but it does not appear to be severe so there is no need to worry. To be sure, let’s test this statistically to see if the data is normally distributed. To test this, one can use the Shapiro-Wilk test for normality. Unfortunately the output is not labeled. The first value is the W test value, and the second value it the p-value.
The test was non-significant. Therefore, the difference between the two conditions is normally distributed. If this test were to be significant, an appropriate alternative to use would be the Wilcoxon signed-rank Test.
Paired Samples T-Test Example
To conduct the paired sample t-test, one needs to use the stats.ttest_rel() method.
The findings are statistically significant! One can reject the null hypothesis in support of the alternative.
Another component needed to report the findings is the degrees of freedom (df). This can be calculated by taking the total number of paired observations and subtracting 1. In our case, df = 120 – 1 = 119.
Interpretation of the Results
A paired sample t-test was used to analyze the blood pressure before and after the intervention to test if the intervention had a significant affect on the blood pressure. The blood pressure before the intervention was higher (156.45 ± 11.39 units) compared to the blood pressure post intervention (151.36 ± 14.18 units); there was a statistically significant decrease in blood pressure (t(119)=3.34, p= 0.0011) of 5.09 units.