EZ Statistics

Tukey's Honest Significant Difference (HSD) Test

Calculator

Learn More

Tukey's HSD Test

Definition

Tukey's HSD (Honestly Significant Difference) Test is a post-hoc test used after ANOVA to determine which specific groups differ from each other. It controls the family-wise error rate while conducting multiple pairwise comparisons.

Formula

Test Statistic:

HSD=qα,k,NkMSEnHSD = q_{\alpha,k,N-k}\sqrt{\frac{MSE}{n}}

Where:

  • qα,k,Nkq_{\alpha,k,N-k} = studentized range statistic
  • MSEMSE = Mean Square Error from ANOVA, which is equivalent to Mean Square Within (MSWithinMS_{Within})
  • nn = sample size per group
  • kk = number of groups
  • NN = total sample size

Key Assumptions

Independence: Observations must be independent
Normality: Data within each group should be normally distributed
Homogeneity of Variance: Groups should have equal variances
Equal Sample Sizes: Preferably, groups should have equal sample sizes

Practical Example

Step 1: State the Data

Comparing three fertilizer treatments on plant growth (cm):

Treatment ATreatment BTreatment C
254235
303833
284031
324534
294132
Step 2: Calculate Group Statistics
  • Treatment A: xˉ=28.8\bar{x} = 28.8, n=5n = 5
  • Treatment B: xˉ=41.2\bar{x} = 41.2, n=5n = 5
  • Treatment C: xˉ=33.0\bar{x} = 33.0, n=5n = 5
  • MSE (from ANOVA) = 5.35.3
Step 3: Calculate HSD

For α=0.05\alpha = 0.05, k=3k = 3 groups, df=12df = 12:

q0.05,3,12=3.77q_{0.05,3,12} = 3.77HSD=3.775.35=3.884HSD = 3.77\sqrt{\frac{5.3}{5}} = 3.884
Step 4: Compare Group Differences

BA=41.228.8=12.4>3.884|B - A| = |41.2 - 28.8| = 12.4 > 3.884 (significant)

CA=33.028.8=4.2>3.884|C - A| = |33.0 - 28.8| = 4.2 > 3.884 (significant)

BC=41.233.0=8.2>3.884|B - C| = |41.2 - 33.0| = 8.2 > 3.884 (significant)

Step 5: Draw Conclusions

All pairwise comparisons show significant differences at α=0.05\alpha = 0.05. Treatment B produced significantly higher growth than both A and C, and Treatment C produced significantly higher growth than Treatment A.

Code Examples

R
1library(emmeans)
2library(tidyverse)
3
4# Example data
5data <- data.frame(
6  group = rep(c("A", "B", "C"), each = 5),
7  values = c(25, 30, 28, 32, 29,  # Group A
8             42, 38, 40, 45, 41,  # Group B
9             35, 33, 31, 34, 32)  # Group C
10)
11
12data |>
13  group_by(group) |>
14  summarize(mean = mean(values), sd = sd(values), n = n())
15
16# Fit ANOVA model
17model <- aov(values ~ group, data = data)
18summary(model)
19
20q <- qtukey(0.95, nmeans = 3, df = 12)
21mse <- summary(model)[[1]]["Residuals", "Mean Sq"]
22hsd <- q * sqrt(mse / 5)
23print(hsd)
24
25# Get emmeans and perform Tukey's HSD
26emmeans_result <- emmeans(model, "group")
27pairs(emmeans_result, adjust = "tukey")
Python
1import pandas as pd
2from statsmodels.stats.multicomp import pairwise_tukeyhsd
3
4# Example data
5group1 = [25, 30, 28, 32, 29]
6group2 = [42, 38, 40, 45, 41]
7group3 = [35, 33, 31, 34, 32]
8
9# Create DataFrame
10data = pd.DataFrame({
11    'values': group1 + group2 + group3,
12    'group': ['A']*5 + ['B']*5 + ['C']*5
13})
14
15# Perform Tukey's HSD
16tukey = pairwise_tukeyhsd(
17    endog=data['values'],
18    groups=data['group'],
19    alpha=0.05
20)
21
22print(tukey)

Alternative Tests

Consider these alternatives:

  • Bonferroni Test: More conservative, controls family-wise error rate
  • Scheffé's Test: More flexible for complex comparisons
  • Games-Howell Test: When variances are unequal

Related Calculators

One-Way ANOVA Calculator

Two-Way ANOVA Calculator

Dunnett's Test Calculator

Dunn's Test Calculator

Help us improve

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