Chapter 1 Paired t-Test

The paired t-test is by far the most powerful test when the assumptions are met for comparing means between two samples. Here are the assumptions:

  1. Paired observations are a random sample (independent) from population of all possible pairs
  2. The differences are normally distributed

Note: By the Central Limit Theorem, we can assume that the sample means will start looking normal at large sample sizes (\(n \geq 40\)).

1.1 How It Works

Paired t-test statistic: \[ t=\frac{\bar{x}_{d}}{S_{d} / \sqrt{n_{d}}} \sim t\left(n_{d}-1\right) \]

  • \(\bar{x}_{d}\) is the sample mean difference.
  • \(s_{d}\) is the sample standard deviation of the differences.
  • \(n_{d}\) is the number of pairs.

We’re trying to test the hypothesis: \[ \begin{aligned} H_0&: \mu_d = 0 \\ H_a&: \mu_d > 0,~<0,~\text{or}~\neq 0 \end{aligned} \]

1.2 Code

1.2.1 R

library(stats)

samp.before <- c(1.1, 2.1, 4.2, 3.2, 1.7, 2.2, 2.7)
samp.after  <- c(3.9, 2.9, 3.8, 1.8, 3.3, 2.8, 2.3)

t.test(x=samp.before, y=samp.after, alternative='two.sided', paired=T)

1.2.2 Python

from scipi.stats import ttest_rel

samp_before = [1.1, 2.1, 4.2, 3.2, 1.7, 2.2, 2.7]
samp_after = [3.9, 2.9, 3.8, 1.8, 3.3, 2.8, 2.3]

ttest_rel(samp_before, samp_after)