EZ Statistics

Paired T-Test

Calculator

2. Select Columns & Options

Learn More

Paired T-Test

Definition

Paired T-Test is a statistical test used to compare two related/dependent samples to determine if there is a significant difference between their means. It's particularly useful when measurements are taken from the same subject before and after a treatment, or when subjects are matched pairs.

Formula

Test Statistic:

t=dˉsd/nt = \frac{\bar{d}}{s_d/\sqrt{n}}

Degrees of freedom:

df=n1df = n - 1

Confidence Intervals:

Two-sided confidence interval:

CI=dˉ±tα/2,n1sdnCI = \bar{d} \pm t_{\alpha/2, n-1} \cdot \frac{s_d}{\sqrt{n}}

One-sided confidence intervals:

CI=dˉ±tα,n1sdnCI = \bar{d} \pm t_{\alpha, n-1} \cdot \frac{s_d}{\sqrt{n}}

Where:

  • dˉ\bar{d} = mean difference between paired observations
  • sds_d = standard deviation of the differences
  • nn = number of pairs

Key Assumptions

Paired Observations: Each data point in one sample has a matched pair in the other sample
Normality: The differences between pairs should be approximately normally distributed
Independence: The pairs should be independent of each other

Practical Example

Testing the effectiveness of a weight loss program by measuring participants' weights before and after the program:

Given Data:

  • Before weights (kg): 70, 75, 80, 85, 90
  • After weights (kg): 68, 72, 77, 82, 87
  • Differences (After - Before): -2, -3, -3, -3, -3
  • α=0.05\alpha = 0.05 (two-tailed test)

Hypotheses:

Null Hypothesis (H0H_0): μd=0\mu_d = 0 (no difference between before and after)

Alternative Hypothesis (H1H_1): μd0\mu_d \neq 0 (there is a difference)

Step-by-Step Calculation:

  1. Calculate mean difference: dˉ=2.8\bar{d} = -2.8
  2. Calculate standard deviation of differences: sd=0.447s_d = 0.447
  3. Degrees of freedom: df=4df = 4
  4. Calculate t-statistic: t=2.80.447/5=14.0t = \frac{-2.8}{0.447/\sqrt{5}} = -14.0
  5. Critical value: t0.025,4=±2.776t_{0.025,4} = \pm 2.776
  6. Confidence interval: dˉ±tα/2,dfsdn=2.8±2.7760.4475=[3.2,2.4]\bar{d} \pm t_{\alpha/2,df} \cdot \frac{s_d}{\sqrt{n}} = -2.8 \pm 2.776 \cdot \frac{0.447}{\sqrt{5}} = [-3.2, -2.4]

Conclusion:

14.0>2.776|-14.0| > 2.776, we reject the null hypothesis. There is sufficient evidence to conclude that the weight loss program resulted in a significant change in participants' weights (p<0.05p < 0.05). We are 95% confident that the true mean difference lies between -3.2 and -2.4 kg.

Effect Size

Cohen's d for paired samples:

d=dˉsdd = \frac{|\bar{d}|}{s_d}

Interpretation guidelines:

  • Small effect: d0.2\text{Small effect: }|d| \approx 0.2
  • Medium effect: d0.5\text{Medium effect: }|d| \approx 0.5
  • Large effect: d0.8\text{Large effect: }|d| \approx 0.8

Power Analysis

Required sample size (n) for desired power (1-β):

n=(z1α/2+z1β)2σd2Δ2n = \frac{(z_{1-\alpha/2} + z_{1-\beta})^2\sigma_d^2}{\Delta^2}

Where:

  • α\alpha = significance level
  • β\beta = probability of Type II error
  • σd\sigma_d = standard deviation of differences
  • Δ\Delta = minimum detectable difference

Decision Rules

Reject H0H_0 if:

  • Two-sided test: t>tα/2,n1|t| > t_{\alpha/2,n-1}
  • Left-tailed test: t<tα,n1t < -t_{\alpha,n-1}
  • Right-tailed test: t>tα,n1t > t_{\alpha,n-1}
  • Or if p-value<αp\text{-value} < \alpha

Reporting Results

Standard format for scientific reporting:

"A paired-samples t-test was conducted to compare [variable] before and after [treatment]. Results indicated that [treatment] produced a [significant/non-significant] difference in scores from [before] (M = [mean1], SD = [sd1]) to [after] (M = [mean2], SD = [sd2]), t([df]) = [t-value], p = [p-value], d = [Cohen's d]. The mean difference was [diff] (95% CI: [lower] to [upper])."

Code Examples

R
1library(tidyverse)
2library(car)
3library(effsize)
4
5set.seed(42)
6n <- 30
7baseline <- rnorm(n, mean = 100, sd = 15)
8followup <- baseline + rnorm(n, mean = -5, sd = 5)  # Average decrease of 5 units
9
10# Create data frame
11data <- tibble(
12  subject = 1:n,
13  baseline = baseline,
14  followup = followup,
15  difference = followup - baseline
16)
17
18# Basic summary
19summary_stats <- data %>%
20  summarise(
21    mean_diff = mean(difference),
22    sd_diff = sd(difference),
23    n = n()
24  )
25
26# Paired t-test
27t_test_result <- t.test(data$followup, data$baseline, paired = TRUE)
28
29# Effect size
30cohens_d <- mean(data$difference) / sd(data$difference)
31
32# Visualization
33ggplot(data) +
34  geom_point(aes(x = baseline, y = followup)) +
35  geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
36  theme_minimal() +
37  labs(title = "Baseline vs Follow-up Measurements",
38       subtitle = paste("Mean difference:", round(mean(data$difference), 2)))
Python
1import numpy as np
2from scipy import stats
3import matplotlib.pyplot as plt
4import seaborn as sns
5from statsmodels.stats.power import TTestPower
6
7# Generate example data
8np.random.seed(42)
9n = 30
10baseline = np.random.normal(100, 15, n)
11followup = baseline + np.random.normal(-5, 5, n)
12differences = followup - baseline
13
14# Basic statistics
15mean_diff = np.mean(differences)
16sd_diff = np.std(differences, ddof=1)
17se_diff = sd_diff / np.sqrt(n)
18
19# Paired t-test
20t_stat, p_value = stats.ttest_rel(followup, baseline)
21
22# Effect size
23cohens_d = mean_diff / sd_diff
24
25# Power analysis
26analysis = TTestPower()
27power = analysis.power(effect_size=cohens_d, 
28                      nobs=n,
29                      alpha=0.05)
30
31# Visualization
32plt.figure(figsize=(12, 5))
33
34# Scatterplot
35plt.subplot(1, 2, 1)
36plt.scatter(baseline, followup)
37min_val = min(baseline.min(), followup.min())
38max_val = max(baseline.max(), followup.max())
39plt.plot([min_val, max_val], [min_val, max_val], '--', color='red')
40plt.xlabel('Baseline')
41plt.ylabel('Follow-up')
42plt.title('Baseline vs Follow-up')
43
44# Differences histogram
45plt.subplot(1, 2, 2)
46sns.histplot(differences, kde=True)
47plt.axvline(mean_diff, color='red', linestyle='--')
48plt.xlabel('Differences (Follow-up - Baseline)')
49plt.title('Distribution of Differences')
50
51plt.tight_layout()
52plt.show()
53
54print(f"Mean difference: {mean_diff:.2f}")
55print(f"Standard deviation of differences: {sd_diff:.2f}")
56print(f"t-statistic: {t_stat:.2f}")
57print(f"p-value: {p_value:.4f}")
58print(f"Cohen's d: {cohens_d:.2f}")
59print(f"Statistical Power: {power:.4f}")

Alternative Tests

Consider these alternatives when assumptions are violated:

  • Wilcoxon Signed-Rank Test: When normality of differences is violated or data is ordinal
  • Independent t-test: When samples are independent rather than paired

Related Calculators

One-Sample T-Test

Two-Sample T-Test (Unpaired)

One Way ANOVA Calculator

Help us improve

Found an error or have a suggestion? Let us know!