Tukey's Honest Significant Difference (HSD) Test
Calculator
1. Load Your Data
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:
Where:
- = studentized range statistic
- = Mean Square Error from ANOVA, which is equivalent to Mean Square Within ()
- = sample size per group
- = number of groups
- = 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 A | Treatment B | Treatment C |
---|---|---|
25 | 42 | 35 |
30 | 38 | 33 |
28 | 40 | 31 |
32 | 45 | 34 |
29 | 41 | 32 |
Step 2: Calculate Group Statistics
- Treatment A: ,
- Treatment B: ,
- Treatment C: ,
- MSE (from ANOVA) =
Step 3: Calculate HSD
For , groups, :
Step 4: Compare Group Differences
(significant)
(significant)
(significant)
Step 5: Draw Conclusions
All pairwise comparisons show significant differences at . 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!