Skip to content

Tukey HSD test

Compare every pair of group means with Tukey HSD, interpret simultaneous intervals, and distinguish family-wise error control from unadjusted tests and FDR.

The Tukey HSD test—Tukey's honestly significant difference test—compares every pair of population means while controlling the chance of at least one false rejection across that family. For a quant comparing mean execution costs across several venues, it answers which gaps are statistically detectable after accounting for the whole set of pairwise comparisons.
An omnibus analysis of variance asks whether all means are equal. It does not identify the pairs responsible for a difference. Tukey HSD is commonly used for that follow-up question; its adjustment is designed specifically for all pairwise mean comparisons. NIST explains the simultaneous confidence guarantee.

One threshold for a balanced design

Suppose there are k≥2k\ge2 fixed groups, each containing n≥2n\ge2 observations. The classical model assumes observations are independent within and across groups, each group's errors are normally distributed, and all groups share a common positive, finite error variance. Their population means may differ.

Let yˉi\bar y_i be group ii's sample mean. Estimate the common variance using the pooled within-group mean square:

MSE=∑i=1k∑r=1n(yir−yˉi)2ν,ν=k(n−1).\mathrm{MSE}=\frac{\sum_{i=1}^{k}\sum_{r=1}^{n}(y_{ir}-\bar y_i)^2}{\nu}, \qquad \nu=k(n-1).
Write q1−α;k,νq_{1-\alpha;k,\nu} for the lower-tail 1−α1-\alpha quantile of the studentised range distribution. The honestly significant difference is
HSD=q1−α;k,νMSEn.\mathrm{HSD}=q_{1-\alpha;k,\nu}\sqrt{\frac{\mathrm{MSE}}{n}}.
Reject the pairwise null hypothesis μi=μj\mu_i=\mu_j when ∣yˉi−yˉj∣>HSD|\bar y_i-\bar y_j|>\mathrm{HSD}. Equivalently, check whether zero falls outside the interval
(yˉi−yˉj)±HSD.(\bar y_i-\bar y_j)\pm\mathrm{HSD}.
These are simultaneous confidence intervals: under the balanced normal model, the entire collection covers its true pairwise differences with probability 1−α1-\alpha over repeated samples. The studentised range calibrates the largest standardised spread, so the threshold accounts for inspecting every pair. The denominator here is MSE/n\sqrt{\mathrm{MSE}/n}; inserting the ordinary two-mean standard error 2MSE/n\sqrt{2\mathrm{MSE}/n} would add an erroneous factor of 2\sqrt{2}. Abdi and Williams give both balanced and unequal-size formulas.

Three venues, only one detected gap

Consider a stipulated teaching example of execution cost in basis points (bp), where a larger value means a higher cost. Venues A, B and C have five observations each and sample means of 10, 12 and 15 bp. Stipulate pooled MSE=4 bp2\mathrm{MSE}=4\ \mathrm{bp}^2 and the model assumptions above.

There are 15−3=1215-3=12 residual degrees of freedom. At family level α=0.05\alpha=0.05,

q0.95;3,12≈3.772929,HSD=3.7729294/5≈3.374610 bp.q_{0.95;3,12}\approx3.772929, \qquad \mathrm{HSD}=3.772929\sqrt{4/5}\approx3.374610\ \mathrm{bp}.
The quantile is computed using the studentised range distribution's inverse CDF.
Directed comparisonObserved gap (bp)95% simultaneous interval (bp)Reject equal means?
B minus A2[−1.375, 5.375][-1.375,\ 5.375]No
C minus B3[−0.375, 6.375][-0.375,\ 6.375]No
C minus A5[1.625, 8.375][1.625,\ 8.375]Yes
Stipulated three-venue example: B minus A is 2 bp with interval minus 1.375 to 5.375; C minus B is 3 bp with interval minus 0.375 to 6.375; C minus A is 5 bp with interval 1.625 to 8.375. Only C minus A excludes zero.
Stipulated three-venue example: B minus A is 2 bp with interval minus 1.375 to 5.375; C minus B is 3 bp with interval minus 0.375 to 6.375; C minus A is 5 bp with interval 1.625 to 8.375. Only C minus A excludes zero.
Original fixed-input illustration. All three intervals use the same 3.3746 bp margin and jointly target 95% coverage under the stated model.

Only A versus C clears the threshold. The other two nonrejections do not establish equality, and they do not imply that A and C must have equal means. A statistically detected cost gap also does not determine which venue is preferable after fees, fill quality and operational constraints.

These summary inputs support the arithmetic, not evidence that a real dataset satisfies the assumptions. No raw observations or sampling design are supplied. In an actual venue study, shared market shocks, repeated parent orders and changing volatility can undermine independence or a common variance; checking a formula cannot resolve those design issues.

What the adjustment protects

The family-wise error rate is the probability of one or more false rejections within the defined family. Tukey's procedure controls it at no more than α\alpha under its model. This differs from the false discovery rate, which concerns the expected proportion of false rejections among all rejections, with that proportion defined as zero when nothing is rejected.

Running each pair's t-test at an unadjusted 5% level does not generally provide a 5% family guarantee. Nor does Tukey's adjustment for three declared venues automatically cover an earlier search over many venue definitions, time windows or performance measures. Define the comparison family and analysis before using the result as evidence.

Unequal group sizes need Tukey–Kramer

With unequal nin_i, the common-variance extension uses a pair-specific margin:
q1−α;k,N−kMSE2(1ni+1nj),N=∑i=1kni.q_{1-\alpha;k,N-k} \sqrt{\frac{\mathrm{MSE}}{2}\left(\frac{1}{n_i}+\frac{1}{n_j}\right)}, \qquad N=\sum_{i=1}^{k}n_i.
This is the Tukey–Kramer method; substituting one convenient sample size into the balanced formula is incorrect. The expression reduces to HSD when both sizes equal nn. Unequal sample sizes do not remove the common-variance assumption. Unequal-variance alternatives such as Games–Howell use different uncertainty calculations; SciPy's documentation distinguishes these procedures and states their assumptions.
For a full derivation of the pooled variance and the global test, read One-Way Analysis of Variance (public preview; full lesson requires membership).

Sources

Last updated
  • multiple comparisons
  • anova
  • pairwise means
  • family wise error
  • tukey kramer
← Back to the glossaryBack to top ↑