StatsCalculators.com

Tukey's HSD Test

Created:December 1, 2024
Last Updated:May 20, 2025

This calculator helps you perform multiple comparisons between group means after getting a significant ANOVA result. It identifies which specific groups differ significantly from each other while controlling Type I error rate for multiple comparisons. The calculator provides group statistics, an ANOVA table, assumption checks (normality and homogeneity of variance), visualizations (box and mean plots), and an APA-formatted interpretation. Click here to populate the sample data for a quick example.

Calculator

1. Load Your Data

Note: Column names will be converted to snake_case (e.g., "Product ID" → "product_id") for processing.

2. Select Columns & Options

Related Calculators

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=3×53=12df = 3 \times 5 - 3 = 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
library(emmeans)
library(tidyverse)

# Example data
data <- data.frame(
  group = rep(c("A", "B", "C"), each = 5),
  values = c(25, 30, 28, 32, 29,  # Group A
             42, 38, 40, 45, 41,  # Group B
             35, 33, 31, 34, 32)  # Group C
)

data |>
  group_by(group) |>
  summarize(mean = mean(values), sd = sd(values), n = n())

# Fit ANOVA model
model <- aov(values ~ group, data = data)
summary(model)

q <- qtukey(0.95, nmeans = 3, df = 12)
mse <- summary(model)[[1]]["Residuals", "Mean Sq"]
hsd <- q * sqrt(mse / 5)
print(hsd)

# Get emmeans and perform Tukey's HSD
emmeans_result <- emmeans(model, "group")
pairs(emmeans_result, adjust = "tukey")
Python
import pandas as pd
from statsmodels.stats.multicomp import pairwise_tukeyhsd

# Example data
group1 = [25, 30, 28, 32, 29]
group2 = [42, 38, 40, 45, 41]
group3 = [35, 33, 31, 34, 32]

# Create DataFrame
data = pd.DataFrame({
    'values': group1 + group2 + group3,
    'group': ['A']*5 + ['B']*5 + ['C']*5
})

# Perform Tukey's HSD
tukey = pairwise_tukeyhsd(
    endog=data['values'],
    groups=data['group'],
    alpha=0.05
)

print(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

Verification