HomeDescriptive StatisticsTukey Kramer Test Calculator (Free HSD) | StatsUnlock

Tukey Kramer Test Calculator (Free HSD) | StatsUnlock

Tukey Kramer Test Calculator

Paste comma-separated numbers for each group or upload a CSV. This free Tukey Kramer test calculator finds which group means differ after a one-way ANOVA, even when the sample sizes are unequal, and gives adjusted p-values, confidence intervals, effect sizes and four charts.

Post Hoc TestUnequal Sample SizesOne-Way ANOVAMultiple ComparisonsAdjusted p-ValuesFree Online

⚡ 0. Quick Answer

The Tukey Kramer test is a post hoc test that compares every pair of group means after a one-way ANOVA when the groups have unequal sample sizes, while holding the overall chance of a false positive at 5%.

For each pair it divides the difference in means by a standard error built from the ANOVA error variance and both group sizes. The result, q, is compared with the studentized range distribution. With equal group sizes it gives exactly the same answer as the Tukey HSD test.

q = |x̄i − x̄j| ÷ √[(MSE ÷ 2) × (1 ÷ ni + 1 ÷ nj)]

Rule of thumb: a pair differs when q is larger than the critical value q(α, k, N − k), or when the adjusted p-value is below 0.05. With 4 groups and 22 error degrees of freedom the critical value is 3.927.

Key takeaways

  • The Tukey Kramer test is the version of Tukey HSD for unequal sample sizes, and it is what R, SciPy, SPSS and JMP run by default.
  • With k groups there are k(k − 1) ÷ 2 comparisons, so 4 groups give 6 pairs and 6 groups give 15.
  • It keeps the family-wise error rate at or below α = 0.05. Six uncorrected t-tests would push it to about 26%.
  • It assumes normal residuals and equal variances. If the largest variance is more than 4 times the smallest, use Games-Howell instead.
  • Report the mean difference, the 95% simultaneous confidence interval and the adjusted p-value for every pair, not only the significant ones.

📚 1. What Is the Tukey Kramer Test?

The Tukey Kramer test is a multiple comparison procedure. A one-way ANOVA tells you that at least one group mean differs from the others. It does not tell you which one. The Tukey Kramer post hoc test answers that second question by testing every possible pair of groups in one step.

John Tukey designed the original method in 1949 for groups of equal size. Clyde Kramer extended it in 1956 so that it also works when groups have different numbers of observations. That extension is the only difference between the two names. Many programs still print "Tukey HSD" on output that is really the Tukey Kramer HSD test.

What it measures. For each pair it measures how many standard errors apart the two means are. That number is called q, the studentized range statistic. A large q means the gap between two means is big compared with the noise inside the groups.

A worked one-liner. Fertilizer B plants averaged 69.86 cm from 7 plots and Control plants averaged 53.00 cm from 8 plots. The ANOVA error variance was 14.198. So SE = √[(14.198 ÷ 2) × (1 ÷ 7 + 1 ÷ 8)] = 1.379, and q = 16.857 ÷ 1.379 = 12.22. The critical value is 3.927, so the two groups clearly differ.

5055606570Mean plant height (cm)Control 53.0Fert. A 61.5Fert. B 69.9Fert. C 58.03.50 cm, p = .4355.00 cm, p = .1228.36 cm, p = .0038.50 cm, p = .00211.86 cm, p < .00116.86 cm, p < .001significant after Tukey Kramer adjustmentnot significant
The Tukey Kramer multiple comparison test on four group means. Each bracket is one pairwise comparison. Purple brackets are significant after adjustment, grey brackets are not.

Who uses it. Agronomists comparing treatments in field trials, clinical researchers comparing dose groups, ecologists comparing habitats, teachers comparing class sections, and engineers comparing suppliers. In all of these the groups rarely end up the same size, which is exactly when to use the Tukey Kramer test.

Tukey HSD vs Tukey Kramer vs the alternatives

TestGroup sizesVariancesComparesUse it when
Tukey HSDEqualEqualAll pairsA balanced design with every pair of interest
Tukey KramerEqual or unequalEqualAll pairsGroup sizes differ. This is the general case
Games-HowellEqual or unequalUnequalAll pairsLevene's test fails or variances differ by more than 4 times
DunnettEqual or unequalEqualEach group vs one controlYou only care about comparisons with a control
BonferroniAnyDepends on the testA few chosen pairsYou planned a small number of comparisons in advance
Dunn testAnyNot requiredAll pairs, on ranksData are not normal and you ran Kruskal-Wallis

🧮 2. Set Up Your Data

Type or paste numbers separated by commas, like 52, 48, 55, 61, 47, .... Spaces, tabs, semicolons and new lines also work. Click a group name to rename it. Nothing is calculated until you press Run.
Supports .csv, .txt, .xlsx and .xls. Headers are detected automatically. The file is read in your browser and is never uploaded to a server.

Type one value per cell. Each column becomes a group, and the top row holds the group names. Empty cells are ignored, so columns can have different lengths.


Used in the write-up, report and PDF.

📊 3. Results

Enter or load your data above, then press Run Tukey-Kramer Test. The ANOVA table, every pairwise comparison with its adjusted p-value and confidence interval, assumption checks, four charts and auto-filled reporting sentences will appear here.

🧠 4. Interpretation of Results, In Detail

Run the calculator to fill this section with your own numbers: F = ___, p = ___, significant pairs = ___ of ___. The ten sub-sections below explain every part of the output.

4.1 What the Tukey Kramer test actually tells you

The test gives one answer per pair of groups: is the gap between these two means larger than chance alone would produce, once you allow for the fact that you looked at every pair? That last part matters. If you compare enough pairs, some gap will look big by luck. The Tukey Kramer test raises the bar so that the chance of even one false alarm across the whole set stays at your chosen level, usually 5%.

So a significant pair is a strong statement. It says this difference stood out even after the test was made stricter for all the looking you did. In the worked example, Fertilizer B beat the Control by 16.86 cm with an adjusted p below .001. You can say with confidence that B plants are taller.

4.2 How to read the mean difference and its sign

Each row shows the second group minus the first. A positive number means the second group has the higher mean. A negative number means it has the lower mean. The sign carries no judgement. It only tells you the direction. "Fertilizer C − Fertilizer B = −11.86" means C plants were 11.86 cm shorter than B plants on average.

Always read the difference in the units you measured. A difference of 11.86 cm on plants about 60 cm tall is large. The same number on trees 20 metres tall would not matter. The p-value cannot make that judgement for you.

4.3 The q statistic and the critical value

The q statistic is the difference in means divided by its standard error. It is a signal-to-noise ratio. A q of 5.91 means the two means are 5.91 standard errors apart. The critical value is the size of q you would need to call a pair different. It depends on three things: your alpha, the number of groups k, and the error degrees of freedom N − k.

More groups push the critical value up, because more pairs give chance more opportunities. With 22 error degrees of freedom the critical q is 2.93 for 2 groups, 3.55 for 3 groups, 3.93 for 4 groups and 4.20 for 5 groups. This is why adding groups you do not care about costs you power on the pairs you do care about.

4.4 Adjusted p-values and why they are larger than t-test p-values

The adjusted p-value answers this question: if all group means were truly equal, how often would the largest gap among all pairs be at least this big? Because it refers to the largest gap in the whole family, it is always bigger than the p-value from a plain t-test on the same two groups.

In the worked example, Fertilizer C against Control gives q = 3.29 and an adjusted p of .122. A simple two-sample t-test on those same two groups gives p = .066. Neither is below .05 here, but the gap between them shows the price of looking at six pairs. Never mix the two kinds of p-value in one table.

4.5 Simultaneous confidence intervals are the most useful output

Each interval gives a range of plausible values for the true difference. If the interval does not include zero, the pair is significant. The intervals are called simultaneous because all of them hold together with 95% confidence. That is a stronger promise than six separate 95% intervals, so each one is wider.

Read both ends. Fertilizer A against Control gives 8.50 cm with an interval from 2.85 to 14.15. The fertilizer helps, but the true gain might be as small as 3 cm or as large as 14 cm. If a 3 cm gain would not pay for the fertilizer, the significant result is not yet a decision.

4.6 What "not significant" does and does not mean

A pair that is not significant has not been shown to be equal. The test only says the data cannot separate the two groups. Fertilizer C against Fertilizer A gives a difference of −3.50 cm with an interval from −9.84 to 2.84. The true difference could be zero. It could also be nearly 10 cm. With only 5 and 6 plots, the study cannot tell.

Wide intervals around zero mean "we do not know". Narrow intervals around zero mean "any difference is small". Only the second one supports a claim that two groups are about the same.

4.7 Reading the compact letter display

Letters summarise the whole table in one line. Groups that share a letter are not significantly different. Groups with no letter in common are. In the example the letters are: Fertilizer B a, Fertilizer A b, Fertilizer C bc, Control c.

Fertilizer B stands alone at the top. Fertilizer C has two letters, b and c. It overlaps with Fertilizer A above it and with the Control below it, so it cannot be separated from either. Yet A and the Control do differ from each other. This pattern looks odd at first, but it is normal. It simply reflects that C sits in the middle with a small sample.

4.8 Effect sizes: how big, not only how sure

Eta squared is the share of all variation explained by the groups. In the example it is 0.779, so the fertilizer type accounts for about 78% of the variation in height. Omega squared, 0.741, is a slightly smaller and less biased version, and it is the better one to report for small samples.

Hedges g describes one pair. It is the mean difference divided by the pooled standard deviation, with a small-sample correction. By convention 0.2 is small, 0.5 is medium and 0.8 is large. Field experiments with tight control often give values far above 0.8, as this one does. That is fine. It means the groups barely overlap.

4.9 When the ANOVA and the Tukey Kramer test disagree

Sometimes the ANOVA is significant but no pair is. Sometimes a pair is significant but the ANOVA is not. Both can happen, because the two tests ask different questions. The F test looks at all means together. The Tukey Kramer test looks at the largest gap. Disagreement happens near the boundary, when p-values sit close to 0.05.

You do not need a significant ANOVA before running the Tukey Kramer test. The test controls the error rate on its own. Requiring both makes the procedure more conservative than it claims to be. If they disagree, report both honestly and treat the result as borderline.

4.10 Decision guide and common mistakes this calculator prevents

What you seeWhat to concludeWhat to do next
Adjusted p below alpha, interval far from zeroA clear differenceReport the difference, interval and effect size
Adjusted p below alpha, interval nearly touching zeroA real but possibly small differenceReport it, and discuss whether the lower limit matters in practice
Adjusted p between alpha and about 0.10BorderlineDo not claim a difference. Say the evidence is weak and more data are needed
Adjusted p well above alpha, wide intervalInconclusiveDo not claim the groups are equal. Report the interval
Levene's test failsThe pooled variance is not validSwitch to Games-Howell
Residuals not normal and groups smallp-values may be wrongTransform the data or use Kruskal-Wallis with Dunn tests
Common mistakes this calculator prevents. It never uses the equal-n Tukey HSD formula on unequal groups. It never reports unadjusted t-test p-values as if they were post hoc results. It checks normality on the residuals, not on the raw pooled data. It uses the median-centred Levene test, which stays reliable with skewed data. And it prints every pair, so you cannot report only the ones that reached significance.

✍ 5. How to Write Your Results in Research

When reporting Tukey Kramer test results, readers need five things: the ANOVA result, the name of the post hoc test, why you chose it, the size and direction of each difference with its confidence interval, and the adjusted p-value. The five templates below fill themselves with your numbers after you run the analysis.

▶ Run the analysis above to auto-fill all five examples with your results.

Example 1, APA 7th Edition
📌 Key conventions for this style
  • Italicise F, p, M, SD, n and q in your word processor.
  • Write p-values without a leading zero, and write p < .001 for anything smaller.
  • Give the confidence interval in square brackets after the mean difference.
  • Name the test as "Tukey-Kramer" when group sizes are unequal, not "Tukey HSD".
  • Report non-significant pairs too, at least as a range of p-values.
Example 2, Thesis / Dissertation
📌 Key conventions for this style
  • Justify the choice of post hoc test. Examiners ask why not Bonferroni or Games-Howell.
  • Report both assumption checks with their test statistics.
  • Give the MSE, the error degrees of freedom and the critical q so the analysis can be reproduced.
  • Put the full pairwise table in the text or an appendix.
  • Name the software and version used.
Example 3, Plain-Language Summary
📌 Key conventions for this style
  • No symbols, no test names, no p-values.
  • Say "a real difference" or "we could not tell them apart", never "significant".
  • Give the size of the gap in everyday units.
  • Do not say groups are "the same" when the test was only inconclusive.
Example 4, Structured Abstract / Poster
📌 Key conventions for this style
  • Keep to the Objective, Methods, Results, Conclusion headings.
  • State the family-wise alpha once in Methods.
  • On a poster, show chart 1 with the letters and put this text beside it.
  • Give the largest effect with its interval. Leave the full table for a handout.
Example 5, Replication / Pre-Registration
📌 Key conventions for this style
  • State the comparisons, the alpha and the decision rule before collecting data.
  • Give every number needed to recompute the result: group sizes, MSE, degrees of freedom, critical q.
  • List all pairs, not a selection.
  • Say plainly if any comparison was added after seeing the data.

5.1 Methods section wording

Say what was compared, which test was used and why. A good sentence is: "Group means were compared with a one-way ANOVA followed by Tukey-Kramer post hoc tests, because all pairwise comparisons were of interest and group sizes were unequal. The family-wise error rate was set at .05."

5.2 Results sentence

Lead with the ANOVA, then the pairs. Give direction in words: "Fertilizer B produced taller plants than the Control". Follow with the numbers in brackets. Do not write "there was a significant difference between B and Control" without saying which was higher.

5.3 Table and figure conventions

A results table needs one row per pair with the mean difference, standard error, q or t, adjusted p and the confidence interval. A figure should show group means with intervals and the compact letters above each bar, as chart 1 does. State in the caption that groups sharing a letter do not differ by the Tukey-Kramer test at your alpha.

5.4 Discussion sentence

Link the size of the difference to its practical meaning. "The 16.9 cm gain from Fertilizer B is about a third of the control height, which is large enough to matter commercially." Mention any pairs that were inconclusive and what sample size would resolve them.

5.5 Reporting checklist

  • ANOVA: F, both degrees of freedom, p and an effect size.
  • The name "Tukey-Kramer" and the reason for using it.
  • The family-wise alpha.
  • For each pair: difference, confidence interval, adjusted p.
  • Group n, mean and SD.
  • Results of the normality and equal-variance checks.
  • The software used.

∑ 6. Formulas Used

The Tukey Kramer test formula is built in seven steps. Each card below defines one quantity before the next card uses it.

①
Tukey-Kramer Test Statistic
q = |x̄i − x̄j| ÷ SEij
qStudentized range statistic for groups i and j, unitless
x̄i, x̄jThe two group means, in the units of the measurement
SEijThe Kramer standard error for this pair, defined in card 3
ExampleFertilizer B vs Control: 16.857 ÷ 1.379 = 12.22
Noteq equals √2 times the pooled-variance t statistic for the same pair
②
Mean Square Error from the ANOVA
MSE = Σg Σi (xgi − x̄g)² ÷ (N − k)
MSEPooled within-group variance, in squared units of the measurement
xgiObservation i in group g
x̄gThe mean of group g
N, kTotal number of observations and number of groups, both counts
Example312.357 ÷ (26 − 4) = 14.198
RequiresSimilar variances in every group, otherwise pooling is not valid
③
Kramer Standard Error for Unequal n
SEij = √[(MSE ÷ 2) × (1 ÷ ni + 1 ÷ nj)]
ni, njThe sizes of the two groups being compared, counts
MSE ÷ 2The division by 2 puts q on the studentized range scale
Example√[(14.198 ÷ 2) × (1 ÷ 7 + 1 ÷ 8)] = 1.379
RuleWith equal n this becomes √(MSE ÷ n), the Tukey HSD form
NoteEach pair has its own SE, so small groups get wider intervals
④
Degrees of Freedom and Critical Value
df = N − k  ·  qcrit = q(α, k, df)
dfError degrees of freedom, a count
αFamily-wise significance level, a proportion, usually 0.05
qcritUpper α point of the studentized range distribution, unitless
Exampleq(0.05, 4, 22) = 3.927
RuleDeclare a pair different when q is greater than qcrit
⑤
Adjusted p-Value
padj = P(Qk, df ≥ q)
padjProbability, 0 to 1, already adjusted for all pairs
Qk, dfA studentized range variable with k means and df error degrees of freedom
qThe observed statistic from card 1
Exampleq = 5.907 with k = 4 and df = 22 gives p = 0.0021
NoteThis is an upper tail area. There is no one-tailed version of the test
⑥
Simultaneous Confidence Interval
(x̄j − x̄i) ± qcrit × SEij
x̄j − x̄iThe signed difference in means, in the units of the measurement
qcrit × SEijThe margin, also called the minimum significant difference for this pair
Example16.857 ± 3.927 × 1.379 = 11.44 to 22.27
RuleAn interval that excludes zero means the pair is significant
PropertyAll intervals hold together with at least 1 − α confidence
⑦
Effect Sizes Reported Beside the Test
η² = SSB ÷ SST  ·  ω² = (SSB − (k − 1)MSE) ÷ (SST + MSE)  ·  g = J × (x̄j − x̄i) ÷ √MSE
SSB, SSTBetween-group and total sums of squares, in squared units
η², ω²Share of variance explained by the groups, 0 to 1, unitless
gHedges g for one pair, in pooled standard deviation units
JSmall-sample correction, 1 − 3 ÷ (4 df − 1), unitless
Rangeη²: 0.01 small, 0.06 medium, 0.14 large. g: 0.2, 0.5, 0.8
Exampleη² = 1100.104 ÷ 1412.462 = 0.779

🔀 7. Tukey Kramer Test Calculation Flowchart, Step by Step

This flowchart shows how the Tukey Kramer test is calculated step by step, from raw group data to a decision for each pair. Every box uses the worked example from this page: plant height in cm from a fertilizer trial with a Control and three fertilizers.

Start or result Data step Calculation step Yes or no check
Start Raw measurements in three or more groups 26 plant heights in cm from 4 treatments, one plot per value
CheckIs each value from a different, independent unit?
YesCarry on. Here every value is a separate plot.
No, stopRepeated measures on the same unit need a repeated-measures method.
1
Count and average each group ng and x̄g for every group Control n = 8, mean 53.00. A: n = 6, 61.50. B: n = 7, 69.86. C: n = 5, 58.00
2
Add up the squared deviations inside each group SSW = ΣΣ(x − x̄g)² 164.000 + 57.500 + 50.857 + 40.000 = 312.357
3
Divide by the error degrees of freedom MSE = SSW ÷ (N − k) 312.357 ÷ (26 − 4) = 14.198 on 22 df
CheckIs the largest group variance more than 4 times the smallest?
Yes, stopThe pooled MSE is not valid. Use the Games-Howell test.
NoCarry on. Here 23.43 ÷ 8.48 = 2.76, and Levene p = .473.
4
Find the standard error for one pair SE = √[(MSE ÷ 2)(1 ÷ ni + 1 ÷ nj)] Fertilizer B vs Control: √[7.099 × (1 ÷ 7 + 1 ÷ 8)] = 1.379
5
Divide the mean difference by the standard error q = |x̄i − x̄j| ÷ SE |69.857 − 53.000| ÷ 1.379 = 12.22
6
Look up the critical value qcrit = q(α, k, N − k) q(0.05, 4, 22) = 3.927
7
Compare, then repeat for every pair significant if q > qcrit 12.22 > 3.927, so B and Control differ. Six pairs in total: q = 5.91, 12.22, 3.29, 5.64, 2.17, 7.60
Result 4 of 6 pairs differ, F(3, 22) = 25.83 B vs Control p < .001B vs C p < .001A vs Control p = .002B vs A p = .003C vs Control p = .122C vs A p = .435 Rule used: a pair differs when q exceeds 3.927, which is the same as adjusted p below .05.

Check any box yourself: the Excel sheet in Section 9, the R script in Section 10 and the Python script in Section 11 all return MSE = 14.198, critical q = 3.927 and q = 12.22 for Fertilizer B against the Control.

📝 8. How to Use This Calculator

  1. Enter your data. Each group has its own box. Type or paste numbers separated by commas, exactly as the placeholder shows: 52, 48, 55, 61, 47, ... New lines, tabs, semicolons and spaces also work, so a column pasted from Excel is fine.
  2. Name each group. The name field above every box is editable. Type something meaningful such as Fertilizer A. The name appears in every table, all four charts and the exported report.
  3. Add or remove groups. Press Add group for more groups, up to 12. Each box has its own Clear and Remove button.
  4. Or upload a file. On the Upload tab choose a CSV or Excel file, then click the column names you want. Every column you click is loaded as a separate group. Files in long format, with one column of group names and one of values, are also supported.
  5. Try a sample dataset. Ten built-in datasets cover the cases that matter: a textbook example, a clear dose response, a borderline result, a null result, a small pilot, a large survey with a trivial effect and one where the assumptions fail.
  6. Describe the study. The study name, what was measured and the units are optional. They are used to write full sentences in the reports.
  7. Choose alpha. Leave it at 0.05 unless your field or your pre-registration says otherwise.
  8. Press Run Tukey-Kramer Test. Nothing is calculated until you do. Changing any input clears the results, so you never read numbers from old data.
  9. Read the assumption checks before the p-values. If Levene's test fails, the tool tells you to use Games-Howell. If it passes, read the pairwise table and chart 3.
  10. Copy the write-up and export. Section 5 fills five reporting styles with your numbers. The buttons under the charts save a text report or a print-ready PDF.

📈 9. How to Run the Tukey Kramer Test in Excel

Excel has no built-in function for the Tukey Kramer test, and the Analysis ToolPak does not offer it either. What Excel does well is the arithmetic: the group means, the pooled error variance, the standard error for each pair and the q statistic. The one thing Excel cannot do is look up the studentized range distribution. So you compute q in the sheet and compare it with a critical value from the table in Section 12, or from this calculator.

The whole thing in one line: with the two group means in C12 and A12, their sizes in C11 and A11 and the MSE in H4, type =ABS(C12-A12)/SQRT($H$4/2*(1/C11+1/A11)). If the answer is larger than the critical q, the pair differs.

9.1 The functions you need

You wantExcel functionNote
Group size=COUNT(A2:A9)Counts numbers only, so blank cells in a short column are ignored
Group mean=AVERAGE(A2:A9)Ignores blanks and text
Group variance=VAR.S(A2:A9)The sample version, dividing by n − 1. Never VAR.P here
Error degrees of freedom=SUM(A11:D11)-COUNT(A11:D11)N − k
MSE=SUMPRODUCT(A11:D11-1,A13:D13)/H3Each variance weighted by its n − 1
Standard error for a pair=SQRT($H$4/2*(1/C11+1/A11))The Kramer form, valid for unequal n
q statistic=ABS(K3)/L3Mean difference divided by the standard error
Whole ANOVA tableData → Data Analysis → Anova: Single FactorAnalysis ToolPak. Enable it first under File → Options → Add-ins. "MS Within Groups" is the MSE
Critical qNo function existsUse Table 12.1, or the free Real Statistics add-in function QCRIT
The T.TEST trap. It is tempting to run =T.TEST(A2:A9,C2:C8,2,2) on every pair. Those p-values are not adjusted for multiple comparisons, and each one uses only two groups to estimate the variance. With 6 pairs the chance of at least one false positive rises from 5% to about 26%. That is the exact problem the Tukey Kramer test in Excel is meant to solve.

9.2 Step by step

1 Put each group in its own column

Give every group one column with its name in row 1. Columns can have different lengths. Leave the unused cells empty, and never type 0 to fill a gap.

Xtukey-kramer.xlsx - ExcelA2fx52ABCD1ControlFertilizer AFertilizer BFertilizer C252606856348577262455666558561637054647597460750646985871953

The fertilizer trial: Control has 8 values, Fertilizer A has 6, Fertilizer B has 7 and Fertilizer C has 5. Rows 1 to 9 hold all the data.

2 Summarise each group

Under the data, compute the size, mean and variance of every column. Type each formula once in column A and drag it across to column D.

=COUNT(A2:A9)=AVERAGE(A2:A9)=VAR.S(A2:A9)
Xtukey-kramer.xlsx - ExcelA12fx=AVERAGE(A2:A9)ABCDE1ControlFertilizer AFertilizer BFertilizer C95310118675n1253.00061.50069.85758.000mean1323.42911.5008.47610.000variance

Row 11 gives n = 8, 6, 7, 5. Row 12 gives the means 53.000, 61.500, 69.857, 58.000. Row 13 gives the variances 23.429, 11.500, 8.476, 10.000.

3 Compute the MSE

The MSE is the average of the group variances, weighted by each group's degrees of freedom. Build it in four cells so you can see every part.

H1: =COUNT(A11:D11)H2: =SUM(A11:D11)H3: =H2-H1H4: =SUMPRODUCT(A11:D11-1,A13:D13)/H3
Xtukey-kramer.xlsx - ExcelH4fx=SUMPRODUCT(A11:D11-1,A13:D13)/H3GH1k42N263error df224MSE14.1985critical q (typed)3.927

k = 4, N = 26, error df = 22 and MSE = 14.198. The ToolPak ANOVA table shows the same number as "MS Within Groups". Type the critical value 3.927 into H5 from Table 12.1.

4 Build the pairwise table

Make one row per pair. For Fertilizer B against the Control, the difference, standard error and q are:

K3: =C12-A12L3: =SQRT($H$4/2*(1/C11+1/A11))M3: =ABS(K3)/L3
Xtukey-kramer.xlsx - ExcelM3fx=ABS(K3)/L3JKLM1PairdiffSEq2Fert. A - Control8.5001.4395.9073Fert. B - Control16.8571.37912.2254Fert. C - Control5.0001.5193.2925Fert. B - Fert. A8.3571.4825.6386Fert. C - Fert. A-3.5001.6132.1697Fert. C - Fert. B-11.8571.5607.600

Fertilizer B minus Control: difference 16.857, standard error 1.379, q = 12.225. The dollar signs lock the MSE cell so the formula can be copied to the other rows. Change the two column letters for each new pair.

5 Add the confidence interval and the decision

The interval is the difference plus and minus the critical q times the standard error. The pair is significant when q is larger than the critical value.

N3: =K3-$H$5*L3O3: =K3+$H$5*L3P3: =IF(M3>$H$5,"Yes","No")
Xtukey-kramer.xlsx - ExcelP3fx=IF(M3>$H$5,"Yes","No")JMNOP1PairqCI lowCI highSignificant?2Fert. A - Control5.9072.84914.151Yes3Fert. B - Control12.22511.44222.272Yes4Fert. C - Control3.292-0.96510.965No5Fert. B - Fert. A5.6382.53614.178Yes6Fert. C - Fert. A2.169-9.8362.836No7Fert. C - Fert. B7.600-17.984-5.731Yes

Four pairs say Yes and two say No, matching this calculator. The interval for Fertilizer B minus Control is 11.442 to 22.272.

9.3 The awkward cases

Adjusted p-values. Excel cannot compute the Tukey Kramer p-value, because it has no studentized range function. The closest built-in route is a Bonferroni p-value, which is a little larger and so a little more cautious:

=MIN(1, 6*T.DIST.2T(M3/SQRT(2), $H$3))

The 6 is the number of pairs, and dividing q by √2 turns it into a t statistic. For Fertilizer A against the Control this gives 0.0023, where the Tukey Kramer value is 0.0021. For Fertilizer C against the Control it gives 0.1772, against 0.1222. The classic mistake is to leave out the multiplication by the number of pairs.

A critical value for degrees of freedom not in the table. Printed tables skip values. For 22 degrees of freedom, take the entries for 20 (3.958) and 24 (3.901) and interpolate, or read the exact value 3.927 from this calculator.

Many groups. With 6 groups there are 15 pairs and 15 rows to type. Lay the means out in both a row and a column and fill a square table instead. Use INDEX to pick each mean and each n so one formula fills the whole grid.

The fastest check is to paste the same columns into the calculator on this page and compare the q values. They should agree to three decimal places.

9.4 Why your Excel answer might differ from R or Python

SituationWhat happensFix
You typed 0 in the empty cells of a short columnThe zeros are counted as data, so n, the mean and the variance are all wrongDelete them. Leave unused cells truly blank
Numbers stored as textCOUNT and AVERAGE skip them silently, so n is too smallLook for green triangles, then choose Convert to Number
Used VAR.P or STDEV.PThe MSE comes out too small and q too largeUse VAR.S. R and SciPy both use n − 1
Used √(MSE ÷ n) with one n for all pairsThat is the equal-n Tukey HSD formula. It is wrong for unequal groupsUse the Kramer standard error with both group sizes
Forgot to divide the MSE by 2You have computed t, not q. It is smaller by a factor of √2Either divide MSE by 2, or compare with qcrit ÷ √2
p-values from T.TEST are smaller than R'sThey are unadjusted, and they use only two groups for the varianceUse the q comparison, or the Bonferroni formula in 9.3
Critical q from a table for the wrong dfThe decision can flip for pairs near the boundaryInterpolate, or take the exact value from this page
Rounding shown versus rounding storedTyping a rounded MSE of 14.2 changes q in the third decimalAlways refer to the cell, never retype the number
ToolHow to run the Tukey Kramer testHandles unequal n automatically?
ExcelBy formula, as in 9.2Only if you use the Kramer standard error
Google SheetsThe same formulas work unchangedOnly if you use the Kramer standard error
RTukeyHSD(aov(value ~ group))Yes
Pythonscipy.stats.tukey_hsd(a, b, c, d)Yes
SPSSAnalyze → Compare Means → One-Way ANOVA → Post Hoc → Tukey. SPSS applies the Kramer form when n is unequal
JMPFit Y by X → Compare Means → All Pairs, Tukey HSD. JMP labels it Tukey-Kramer HSD
MinitabStat → ANOVA → One-Way → Comparisons → Tukey

9.5 Charting the result in Excel

  1. Select the group names in row 1 and the means in row 12.
  2. Choose Insert → Charts → Clustered Column.
  3. Click the chart, press the + button, tick Error Bars, then choose More Options → Custom → Specify Value. Point it at a row holding =T.INV.2T(0.05,$H$3)*SQRT($H$4/A11) for each group, which is the 95% margin.
  4. Add a text box above each bar with its letter from the compact letter display, and say in the caption that groups sharing a letter do not differ.
  5. Remove the gridlines and the chart border, and label the y axis with the units.

Chart 1 in Section 3 of this page draws the same figure with the letters already placed, which is usually quicker than building it in Excel.

9.6 Excel errors you will probably hit

Excel showsWhyFix
#DIV/0!A group has no numbers, or only one, so its variance cannot be computedEvery group needs at least 2 values. Check the ranges
#VALUE!A cell contains text such as "52 cm" or a stray spaceKeep units in the header, not in the cells
#NUM!SQRT was given a negative number, usually from a wrong cell referenceCheck that the MSE reference points at H4 and is locked with dollar signs
#N/AA lookup into the critical value table found no matching dfInterpolate between the two nearest rows
#NAME?You typed QCRIT or TUKEY without the add-in installedInstall the add-in, or type the critical value by hand
"Data Analysis" is missing from the Data tabThe Analysis ToolPak is not enabledFile → Options → Add-ins → Manage Excel Add-ins → tick Analysis ToolPak
q is the same for every pairThe group size references did not change when you copied the formulaEdit the two column letters in each row

📈 10. How to Run the Tukey Kramer Test in R

The Tukey Kramer test in R is one line: TukeyHSD(aov(value ~ group, data = df)). The function is named for Tukey HSD, but it uses the Kramer standard error whenever group sizes differ, so there is nothing extra to switch on. The one-liner prints a table and stops there. The script below also checks the assumptions, shows the calculation by hand so every number can be traced, prints a plain-English verdict and saves one 300 dpi figure.

Copy the whole block. It runs top to bottom in RStudio, VS Code or plain Rscript. Change only the groups <- list(...) block to use your own data. It uses base R only, so there is nothing to install.

10.1 The complete script

R, base only, saves tukey_kramer_plot.png

# ============================================================
# Tukey-Kramer test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/tukey-kramer-test-calculator/
# Base R only. No packages to install.
# ============================================================

# ---- 1. Your data ------------------------------------------
# Replace this list with your own groups, or read a long-format CSV:
#   df <- read.csv("data.csv")[, c("value", "group")]
#   df <- df[complete.cases(df), ]
groups <- list(
  "Control"      = c(52, 48, 55, 61, 47, 50, 58, 53),
  "Fertilizer A" = c(60, 57, 66, 63, 59, 64),
  "Fertilizer B" = c(68, 72, 65, 70, 74, 69, 71),
  "Fertilizer C" = c(56, 62, 58, 54, 60)
)
alpha <- 0.05
units <- "cm"

df <- stack(groups)
names(df) <- c("value", "group")
df$group <- factor(df$group, levels = names(groups))   # keep your order, not alphabetical

# ---- 2. One-way ANOVA and the pooled error variance --------
fit      <- aov(value ~ group, data = df)
tab      <- summary(fit)[[1]]
k        <- nlevels(df$group)
N        <- nrow(df)
df_error <- tab[["Df"]][2]
mse      <- tab[["Mean Sq"]][2]
F_val    <- tab[["F value"]][1]
p_anova  <- tab[["Pr(>F)"]][1]
eta2     <- tab[["Sum Sq"]][1] / sum(tab[["Sum Sq"]])

# ---- 3. The built-in Tukey-Kramer test ---------------------
tk     <- TukeyHSD(fit, conf.level = 1 - alpha)$group
q_crit <- qtukey(1 - alpha, nmeans = k, df = df_error)

# ---- 4. The same thing by hand, so every number is visible -
n  <- tapply(df$value, df$group, length)
m  <- tapply(df$value, df$group, mean)
pr <- combn(levels(df$group), 2)
hand <- t(apply(pr, 2, function(p) {
  d  <- unname(m[p[2]] - m[p[1]])
  se <- unname(sqrt(mse / 2 * (1 / n[p[1]] + 1 / n[p[2]])))   # the Kramer standard error
  q  <- abs(d) / se
  c(diff = d, se = se, q = q, p = ptukey(q, k, df_error, lower.tail = FALSE))
}))
rownames(hand) <- paste(pr[2, ], pr[1, ], sep = " - ")
stopifnot(all(abs(hand[, "p"] - tk[, "p adj"]) < 1e-6))

# ---- 5. Assumption checks ----------------------------------
sw  <- shapiro.test(residuals(fit))
z   <- abs(df$value - ave(df$value, df$group, FUN = median))
lev <- anova(lm(z ~ df$group))          # Levene test, median centred

# ---- 6. Printed summary ------------------------------------
cat(sprintf("k = %d, N = %d, n per group = %s\n", k, N, paste(n, collapse = ", ")))
cat(sprintf("ANOVA: F(%d, %d) = %.4f, p = %.3g, eta squared = %.4f\n",
            k - 1, df_error, F_val, p_anova, eta2))
cat(sprintf("MSE = %.4f, critical q(%d, %d) = %.4f\n\n", mse, k, df_error, q_crit))
out <- cbind(hand[, c("diff", "se", "q")], "p adj" = tk[, "p adj"],
             lwr = tk[, "lwr"], upr = tk[, "upr"])
print(round(out, 4))
cat(sprintf("\nShapiro-Wilk on residuals: W = %.4f, p = %.4f\n", sw$statistic, sw$p.value))
cat(sprintf("Levene (median): F = %.4f, p = %.4f\n", lev[["F value"]][1], lev[["Pr(>F)"]][1]))
n_sig <- sum(tk[, "p adj"] < alpha)
ok    <- sw$p.value >= 0.05 && lev[["Pr(>F)"]][1] >= 0.05
cat(sprintf("\nVerdict: %d of %d pairs differ at family-wise alpha = %.2f. %s\n",
            n_sig, nrow(tk), alpha,
            if (ok) "Assumptions hold, so report these results."
            else "An assumption failed, so confirm with Games-Howell."))

# ---- 7. One figure: simultaneous confidence intervals ------
png("tukey_kramer_plot.png", width = 2700,
    height = round(300 * (0.62 * nrow(tk) + 2.6)), res = 300)
par(mar = c(5, 13, 5, 2), family = "sans")
ypos <- rev(seq_len(nrow(tk)))
sig  <- tk[, "p adj"] < alpha
plot(NA, xlim = range(c(tk[, "lwr"], tk[, "upr"], 0)),
     ylim = c(0.5, nrow(tk) + 0.5), yaxt = "n", bty = "n", ylab = "",
     xlab = sprintf("Difference in means (%s) with %.0f%% simultaneous CI",
                    units, 100 * (1 - alpha)))
grid(nx = NULL, ny = NA, col = "#e5e7eb", lty = 1)
abline(v = 0, lty = 2, lwd = 1.6, col = "#111827")
segments(tk[, "lwr"], ypos, tk[, "upr"], ypos, lwd = 7, lend = 1,
         col = ifelse(sig, "#7e22ce", "#94a3b8"))
points(tk[, "diff"], ypos, pch = 21, bg = "#111827", col = "white", cex = 1.5)
axis(2, at = ypos, labels = rownames(hand), las = 1, tick = FALSE, cex.axis = 0.85)
title(main = "Tukey-Kramer test: pairwise differences", adj = 0, line = 2.6, cex.main = 1.15)
title(main = sprintf("F(%d, %d) = %.2f, MSE = %.2f, critical q = %.3f",
                     k - 1, df_error, F_val, mse, q_crit),
      adj = 0, line = 1.2, cex.main = 0.95, font.main = 1)
dev.off()
cat("\nSaved tukey_kramer_plot.png\n")

Run it with Rscript tukey_kramer.R from a terminal, or paste it into the RStudio console. The figure is saved as tukey_kramer_plot.png in your working directory, which you can find with getwd(). The script contains no random numbers, so there is nothing to seed and the figure is identical on every run.

10.2 What each part does

Line or functionWhat it does, and why it is there
groups <- list(...)Holds one numeric vector per group. A list is used because the groups have different lengths, which a data frame of columns cannot hold.
stack(groups)Turns the list into long format: one row per observation, with a value column and a group factor. aov() needs this shape. The formula value ~ group does not work on separate vectors.
read.csv() and complete.cases()The commented alternative for a real file. Dropping rows with NA first matters, because aov() removes them silently and your n changes without warning.
factor(df$group, levels = ...)Fixes the group order. Without it R sorts groups alphabetically, which changes the order and the sign of every difference.
aov(value ~ group)Fits the one-way ANOVA. The Mean Sq of the residual row is the MSE that every comparison uses.
TukeyHSD(fit)Runs all pairwise comparisons. Despite the name it applies the Tukey-Kramer adjustment for unequal n. Each row is the later group minus the earlier one.
qtukey(1 - alpha, k, df)The critical value of the studentized range. This is the number Excel cannot compute.
ptukey(q, k, df, lower.tail = FALSE)The adjusted p-value for one q. lower.tail = FALSE gives the upper tail directly, which is more accurate than 1 - ptukey() for tiny p-values.
combn(levels, 2)Lists every pair of groups once, in the same order that TukeyHSD uses, so the by-hand table lines up with the built-in one.
stopifnot(...)Stops the script if the by-hand p-values and the built-in ones disagree. It is a safety check that the formula in Section 6 is what R really computes.
shapiro.test(residuals(fit))Tests normality on the residuals, not the raw data. Raw data from groups with different means will look non-normal even when each group is perfectly normal.
ave(..., FUN = median)Gives each observation its own group median. The absolute deviations from it feed the median-centred Levene test, which base R does not have as a function.
png(..., res = 300)Opens a file device at print quality. Without res = 300 you get a blurry 72 dpi image.
segments() and points()Draw each confidence interval as a thick line and each difference as a dot. Purple means significant, grey means not.
dev.off()Closes the device and writes the file. Forgetting this leaves an empty or locked PNG.

10.3 What the figure shows

The figure has one horizontal line per pair. The dot is the difference in means and the line is its 95% simultaneous confidence interval. The dashed vertical line marks zero. Any interval that does not touch the dashed line is a significant difference, and it is drawn in purple.

For the fertilizer trial, four intervals sit clear of zero and two cross it. The widest intervals belong to pairs that include Fertilizer C, the group with only 5 plots. That is the Kramer standard error at work: smaller groups get wider intervals.

10.4 Common R problems and fixes

SymptomCauseFix
TukeyHSD says "no factors in the fitted model"The group column is numeric, for example doses 10, 20, 40Wrap it: aov(value ~ factor(group))
Groups appear in alphabetical orderR sorts factor levels by defaultSet the order with factor(x, levels = c(...))
The signs of the differences are reversed compared with another programR reports the later level minus the earlier oneNothing is wrong. Reverse the factor levels if you want the other direction
N is smaller than expectedaov() dropped rows containing NA without telling youClean first with complete.cases() and check nrow()
Error in aov() about object not foundTwo separate vectors were passed instead of a long data frameUse stack() as the script does
p-values differ from SPSS in the last digitDifferent numerical integration of the studentized rangeIgnore differences beyond the fourth decimal place
The plot labels are cut off on the leftThe left margin is too narrow for long group namesIncrease the second number in par(mar = c(5, 13, 5, 2))
The PNG is emptydev.off() was never calledRun while (dev.cur() > 1) dev.off()

10.5 Useful one-liners

You wantR code
The test in one lineTukeyHSD(aov(value ~ group, data = df))
99% intervals instead of 95%TukeyHSD(fit, conf.level = 0.99)
The built-in interval plotplot(TukeyHSD(fit), las = 1)
A critical valueqtukey(0.95, nmeans = 4, df = 22)
An adjusted p-value from qptukey(5.907, 4, 22, lower.tail = FALSE)
Compact letters, with the multcompView packagemultcompView::multcompLetters4(fit, TukeyHSD(fit))
Games-Howell for unequal variances, with rstatixrstatix::games_howell_test(df, value ~ group)
Save the table as a CSVwrite.csv(TukeyHSD(fit)$group, "tukey_kramer.csv")

📈 11. How to Run the Tukey Kramer Test in Python

In Python the test is scipy.stats.tukey_hsd(a, b, c, d), available from SciPy 1.8. Like R, the function is named for Tukey HSD but applies the Kramer adjustment when the samples differ in size. The script below is complete and runnable. It computes every number by hand, confirms them against SciPy's own result, checks the assumptions, prints a verdict and saves one 300 dpi figure.

Copy the whole block. Change only the groups = {...} dictionary. The script was run with SciPy 1.18 to produce the numbers on this page.
numpyarrays and the arithmetic
scipy.statsthe ANOVA, the studentized range distribution and the built-in test
matplotlibthe figure
itertools.combinationsevery pair once, standard library

Install with pip install numpy scipy matplotlib. You need SciPy 1.8 or newer. Check with python -c "import scipy; print(scipy.__version__)".

11.1 The complete script

Python 3, saves tukey_kramer_plot.png

# ============================================================
# Tukey-Kramer test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/tukey-kramer-test-calculator/
# ============================================================

import numpy as np
import matplotlib.pyplot as plt
from itertools import combinations
from scipy import stats

# ---- 1. Your data ------------------------------------------
# Replace this dictionary with your own groups, or read a CSV:
#   import pandas as pd
#   df = pd.read_csv("data.csv").dropna(subset=["group", "value"])
#   groups = {g: d["value"].to_numpy(float) for g, d in df.groupby("group")}
groups = {
    "Control":      [52, 48, 55, 61, 47, 50, 58, 53],
    "Fertilizer A": [60, 57, 66, 63, 59, 64],
    "Fertilizer B": [68, 72, 65, 70, 74, 69, 71],
    "Fertilizer C": [56, 62, 58, 54, 60],
}
alpha = 0.05
units = "cm"

names = list(groups)
data  = [np.asarray(groups[g], dtype=float) for g in names]
k     = len(data)
n     = np.array([len(x) for x in data])
N     = n.sum()
means = np.array([x.mean() for x in data])

# ---- 2. One-way ANOVA and the pooled error variance --------
F, p_anova = stats.f_oneway(*data)
df_error   = N - k
mse        = sum(((x - x.mean()) ** 2).sum() for x in data) / df_error
ss_between = sum(len(x) * (x.mean() - np.concatenate(data).mean()) ** 2 for x in data)
eta2       = ss_between / (ss_between + mse * df_error)

# ---- 3. Tukey-Kramer by hand, so every number is visible ---
q_crit = stats.studentized_range.ppf(1 - alpha, k, df_error)
rows = []
for i, j in combinations(range(k), 2):
    diff = means[j] - means[i]
    se   = np.sqrt(mse / 2 * (1 / n[i] + 1 / n[j]))   # the Kramer standard error
    q    = abs(diff) / se
    p    = stats.studentized_range.sf(q, k, df_error)
    rows.append((names[j], names[i], diff, se, q, p, diff - q_crit * se, diff + q_crit * se))

# ---- 4. Cross-check against SciPy's built-in ----------------
res = stats.tukey_hsd(*data)        # uses the Kramer form when n is unequal
for b, a, diff, se, q, p, lo, hi in rows:
    i, j = names.index(a), names.index(b)
    assert abs(res.pvalue[j, i] - p) < 1e-6

# ---- 5. Assumption checks ----------------------------------
resid       = np.concatenate([x - x.mean() for x in data])
W, p_norm   = stats.shapiro(resid)
L, p_levene = stats.levene(*data, center="median")

# ---- 6. Printed summary ------------------------------------
print(f"k = {k}, N = {N}, n per group = {n.tolist()}")
print(f"ANOVA: F({k - 1}, {df_error}) = {F:.4f}, p = {p_anova:.3g}, eta squared = {eta2:.4f}")
print(f"MSE = {mse:.4f}, critical q({k}, {df_error}) = {q_crit:.4f}\n")
print(f"{'comparison':<30}{'diff':>9}{'SE':>9}{'q':>9}{'p adj':>9}{'CI low':>9}{'CI high':>9}")
for b, a, diff, se, q, p, lo, hi in rows:
    flag = "*" if p < alpha else ""
    print(f"{b + ' - ' + a:<30}{diff:>9.4f}{se:>9.4f}{q:>9.4f}{p:>9.4f}{lo:>9.4f}{hi:>9.4f} {flag}")
print(f"\nShapiro-Wilk on residuals: W = {W:.4f}, p = {p_norm:.4f}")
print(f"Levene (median): F = {L:.4f}, p = {p_levene:.4f}")
n_sig = sum(r[5] < alpha for r in rows)
ok = p_norm >= 0.05 and p_levene >= 0.05
print(f"\nVerdict: {n_sig} of {len(rows)} pairs differ at family-wise alpha = {alpha}.",
      "Assumptions hold, so report these results." if ok
      else "An assumption failed, so confirm with Games-Howell.")

# ---- 7. One figure: simultaneous confidence intervals ------
fig, ax = plt.subplots(figsize=(8.5, 0.62 * len(rows) + 2.2))
ypos = np.arange(len(rows))[::-1]
for y, (b, a, diff, se, q, p, lo, hi) in zip(ypos, rows):
    colour = "#7e22ce" if p < alpha else "#94a3b8"
    ax.plot([lo, hi], [y, y], color=colour, lw=6, solid_capstyle="round", alpha=0.75, zorder=2)
    ax.plot(diff, y, "o", color="#111827", ms=7, mec="white", mew=1.3, zorder=3)
ax.axvline(0, color="#111827", lw=1.4, ls="--", zorder=1)
ax.set_yticks(ypos)
ax.set_yticklabels([f"{b} - {a}" for b, a, *_ in rows], fontsize=10)
ax.set_xlabel(f"Difference in means ({units}) with {100 * (1 - alpha):.0f}% simultaneous CI", fontsize=11)
ax.set_title("Tukey-Kramer test: pairwise differences\n"
             f"F({k - 1}, {df_error}) = {F:.2f}, MSE = {mse:.2f}, critical q = {q_crit:.3f}",
             fontsize=12, fontweight="bold", loc="left")
ax.grid(axis="x", alpha=0.25, zorder=0)
ax.spines[["top", "right"]].set_visible(False)
fig.savefig("tukey_kramer_plot.png", dpi=300, bbox_inches="tight")
print("\nSaved tukey_kramer_plot.png")

Run it with python tukey_kramer.py. In Jupyter, add plt.show() after the savefig line to display the figure as well. The script contains no random numbers, so there is nothing to seed.

11.2 What each part does

Line or functionWhat it does, and why it is there
groups = {...}A dictionary of lists, one per group. Lists can be different lengths, which is the whole point of the Kramer version.
np.asarray(..., dtype=float)Converts each list to a float array. Forcing floats avoids integer arithmetic surprises.
pd.read_csv(...).dropna(...)The commented alternative for a real file in long format. Drop missing values first, because np.mean returns nan if even one value is nan.
stats.f_oneway(*data)The one-way ANOVA. The star unpacks the list so each group is passed as its own argument.
mseThe pooled within-group variance: the squared deviations from each group's own mean, summed and divided by N − k. SciPy does not return it, so it is computed by hand.
studentized_range.ppf(1 - alpha, k, df)The critical value. This is the function Excel lacks.
np.sqrt(mse / 2 * (1/n[i] + 1/n[j]))The Kramer standard error. Both group sizes appear, so every pair has its own value.
studentized_range.sf(q, k, df)The adjusted p-value. sf is the survival function, 1 minus the CDF, computed accurately in the tail.
stats.tukey_hsd(*data)SciPy's built-in version. Its pvalue attribute is a k by k matrix. The assert confirms the by-hand numbers match it.
stats.shapiro(resid)Normality test on the residuals, not on the pooled raw data.
stats.levene(*data, center="median")The Brown-Forsythe form of Levene's test. center="median" is SciPy's default, written out so nobody changes it by accident.
f"{value:>9.4f}"Formats a number right-aligned in 9 characters with 4 decimals, so the printed table lines up.
ax.plot([lo, hi], [y, y])Draws one confidence interval as a thick horizontal line.
savefig(dpi=300, bbox_inches="tight")Writes the file at print resolution and trims the white border.

11.3 What the figure shows

The same figure as the R script: one line per pair, with the difference as a dot and its 95% simultaneous confidence interval as a bar. Purple bars are significant, grey bars are not, and the dashed line marks zero.

Reading it takes a few seconds. Four bars sit entirely on one side of zero. Two bars cross it: Fertilizer C against the Control, and Fertilizer C against Fertilizer A. Both involve the smallest group, and both have the widest bars.

11.4 Common Python problems and fixes

SymptomCauseFix
AttributeError: module 'scipy.stats' has no attribute 'tukey_hsd'SciPy is older than 1.8pip install --upgrade scipy
Every result is nanA group contains a missing valueRemove it with x = x[~np.isnan(x)] before running
The signs are reversed compared with Rtukey_hsd prints group i minus group j for every ordered pairRead the row for the direction you want. The script reports later minus earlier, like R
Standard deviation differs from ExcelNumPy defaults to ddof=0, the population formulaUse np.std(x, ddof=1) to match STDEV.S and R
pairwise_tukeyhsd from statsmodels gives a slightly different pOlder statsmodels versions interpolate from a tablePrefer scipy.stats.tukey_hsd, which integrates the distribution directly
TypeError from f_onewayThe list of groups was passed without the starWrite stats.f_oneway(*data)
Nothing appears when the script runsA non-interactive backend, which is normal on serversThe figure is saved to file. Add plt.show() to display it
The y-axis labels are cut offLong group namesbbox_inches="tight" already handles this in the saved file

11.5 Useful one-liners

You wantPython code
The test in one lineprint(stats.tukey_hsd(a, b, c, d))
The matrix of adjusted p-valuesstats.tukey_hsd(a, b, c, d).pvalue
99% simultaneous intervalsres.confidence_interval(confidence_level=0.99)
A critical valuestats.studentized_range.ppf(0.95, 4, 22)
An adjusted p-value from qstats.studentized_range.sf(5.907, 4, 22)
From a long-format data framestats.tukey_hsd(*[g["value"] for _, g in df.groupby("group")])
With statsmodelspairwise_tukeyhsd(df["value"], df["group"]).summary()
Games-Howell for unequal variances, with pingouinpingouin.pairwise_gameshowell(df, dv="value", between="group")
R and Python should agree exactly. Both scripts on this page use the Kramer standard error, the same studentized range distribution and the median-centred Levene test. On the fertilizer data the Python script returns F(3, 22) = 25.83, MSE = 14.198, critical q = 3.927 and adjusted p-values of 0.0021, 0.0000, 0.1222, 0.0032, 0.4352 and 0.0001. R's TukeyHSD applies the same formula, so its table should match to four decimals. If your two results disagree, the cause is almost always missing values handled differently or groups in a different order.

📋 12. Reference Tables

12.1 Critical values of the studentized range, α = 0.05

Error dfk = 2k = 3k = 4k = 5k = 6k = 7k = 8k = 9k = 10
53.6354.6025.2185.6736.0336.3306.5826.8016.995
63.4604.3394.8965.3055.6285.8956.1226.3196.493
83.2614.0414.5294.8865.1675.3995.5965.7675.918
103.1513.8774.3274.6544.9125.1245.3045.4605.598
123.0813.7734.1994.5084.7504.9505.1195.2655.395
153.0143.6734.0764.3674.5954.7824.9405.0775.198
202.9503.5783.9584.2324.4454.6204.7684.8955.008
222.9333.5533.9274.1964.4054.5774.7224.8474.957
242.9193.5323.9014.1664.3734.5414.6844.8074.915
302.8883.4863.8454.1024.3014.4644.6014.7204.824
402.8583.4423.7914.0394.2324.3884.5214.6344.735
602.8293.3993.7373.9774.1634.3144.4414.5504.646
1202.8003.3563.6853.9174.0964.2414.3634.4684.560
∞2.7723.3143.6333.8584.0304.1704.2864.3874.474

Conclusion: find your number of groups across the top and your error degrees of freedom, N − k, down the side. A pair differs when its q is larger than the table value. Values were computed from the studentized range distribution with SciPy and agree with published tables.

12.2 Critical values of the studentized range, α = 0.01

Error dfk = 2k = 3k = 4k = 5k = 6k = 7k = 8k = 9k = 10
55.7026.9767.8048.4218.9139.3219.6699.97110.239
65.2436.3317.0337.5567.9728.3188.6128.8699.097
84.7455.6356.2046.6256.9597.2377.4747.6807.863
104.4825.2705.7696.1366.4286.6696.8757.0547.213
124.3205.0465.5025.8366.1016.3206.5076.6706.814
154.1674.8365.2525.5565.7965.9946.1626.3096.438
204.0244.6395.0185.2935.5105.6885.8395.9706.086
223.9864.5884.9575.2255.4355.6085.7545.8825.994
243.9554.5464.9075.1685.3735.5425.6855.8095.919
303.8894.4554.7995.0485.2425.4015.5365.6535.756
403.8254.3674.6954.9315.1145.2655.3925.5025.599
603.7624.2824.5944.8184.9915.1335.2535.3565.447
1203.7024.2004.4974.7094.8725.0055.1185.2145.299
∞3.6434.1204.4034.6034.7574.8824.9875.0785.157

Conclusion: the stricter 1% level needs a q about 20% to 35% larger once there are 20 or more error degrees of freedom, and much larger with fewer. Use it when a false positive would be costly.

12.3 Why a correction is needed: error rate from uncorrected t-tests

Groups kPairs k(k − 1) ÷ 2Chance of at least one false positive, uncorrectedWith the Tukey Kramer test
215.0%5.0% or less
3314.3%5.0% or less
4626.5%5.0% or less
51040.1%5.0% or less
61553.7%5.0% or less
82876.2%5.0% or less
104590.1%5.0% or less

Conclusion: with 5 groups, ten uncorrected t-tests give about a 40% chance of at least one false positive. The Tukey Kramer multiple comparison test holds that figure at 5% however many groups you have.

12.4 Effect size interpretation bands

Effect sizeSmallMediumLargeUsed for
Eta squared η²0.010.060.14The whole ANOVA: share of variance explained
Omega squared ω²0.010.060.14The same, with less bias in small samples
Cohen's f0.100.250.40Power analysis for ANOVA
Hedges g or Cohen's d0.200.500.80One pair of groups

Conclusion: these are Cohen's general conventions. Many fields see larger effects as routine, especially controlled laboratory and field experiments, so compare with published values in your own area where you can.

12.5 Which post hoc test should you use?

Your situationUseWhy
All pairs, equal variances, equal nTukey HSDExact control of the family-wise error rate
All pairs, equal variances, unequal nTukey KramerProven never to exceed alpha, and only slightly conservative
All pairs, unequal variancesGames-HowellUses a separate variance and Welch degrees of freedom for each pair
Each treatment against one controlDunnettFewer comparisons, so more power for each one
A few comparisons planned in advanceBonferroni or HolmMore powerful than Tukey Kramer when the list is short
Complex contrasts, such as two groups against threeSchefféCovers every possible contrast, at a cost in power
Data not normal, Kruskal-Wallis was usedDunn testWorks on ranks and needs no normality
The same subjects measured in every conditionPaired comparisons with HolmTukey Kramer assumes independent groups

Conclusion: choose the Tukey Kramer test when you want every pair, the variances are similar and the groups are independent. That covers most one-way designs.

12.6 Assumption check thresholds

CheckPassCautionFail
Shapiro-Wilk p on residualsp ≥ 0.05p < 0.05 with 15 or more per groupp < 0.05 with small groups
Levene p, median centredp ≥ 0.05nonep < 0.05
Largest variance ÷ smallest varianceup to 44 to 9above 9
Smallest group size5 or more3 or 41
Largest n ÷ smallest nup to 2above 2 with unequal variancesnone on its own

Conclusion: unequal variances are the serious problem, and they are most damaging when the small groups are the ones with the large variances. Unequal group sizes alone are not a problem for this test.

12.7 Smallest detectable difference by group size

n per groupk = 3k = 4k = 5k = 6
32.512.612.692.74
41.972.102.182.25
51.691.811.891.96
61.501.621.701.76
81.261.371.441.49
101.111.201.271.32
150.890.971.021.06
200.760.830.880.92
300.620.670.710.74
500.470.520.550.57

Conclusion: each entry is the smallest difference between two means that would be significant at α = 0.05, in units of the within-group standard deviation, for equal groups of size n. With 4 groups of 5, two means must be about 1.8 standard deviations apart. With 4 groups of 30 the figure drops to about 0.67. Small studies can only confirm large effects.

📈 13. Example Results

Eight worked examples of the Tukey Kramer test, each with real numbers you can reproduce by choosing the matching sample dataset in Section 2. Every Tukey Kramer test example shows what the result looks like and how to write it up.

1
TEXTBOOK CASE

Four fertilizers in a greenhouse trial

The worked example used in every section of this page.

Twenty-six plots received a Control or one of three fertilizers. Some plots were lost, so the groups ended with 8, 6, 7 and 5 plots. Sample dataset 1 in the calculator.

k = 4, N = 26F(3, 22) = 25.834 of 6 pairs differη² = 0.779critical q = 3.927
506070Mean (cm)cControln = 8, mean 53.00bFertilizer An = 6, mean 61.50aFertilizer Bn = 7, mean 69.86bcFertilizer Cn = 5, mean 58.00Four fertilizers in a greenhouse trial: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Fertilizer B a, Fertilizer A b, Fertilizer C bc, Control c. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Fertilizer A − Control8.505.9070.00212.85 to 14.15Yes
Fertilizer B − Control16.8612.225< 0.000111.44 to 22.27Yes
Fertilizer C − Control5.003.2920.1222−0.96 to 10.96No
Fertilizer B − Fertilizer A8.365.6380.00322.54 to 14.18Yes
Fertilizer C − Fertilizer A−3.502.1690.4352−9.84 to 2.84No
Fertilizer C − Fertilizer B−11.867.6000.0001−17.98 to −5.73Yes

Assumption checks: Shapiro-Wilk W = 0.980, p = .868; Levene F(3, 22) = 0.87, p = .473; variance ratio 2.8.

What it means: Fertilizer B is clearly best and stands apart from every other group. Fertilizer A beats the Control. Fertilizer C sits in the middle and cannot be separated from A or from the Control, mainly because it has only 5 plots.

How to write it: A one-way ANOVA showed a significant effect of group on plant height, F(3, 22) = 25.83, p < .001, η² = .78. Tukey-Kramer post hoc tests showed that Fertilizer B was higher than Control (mean difference = 16.86 cm, 95% CI [11.44, 22.27], p < .001). In total 4 of 6 pairwise comparisons were significant.

2
CLEARLY SIGNIFICANT

A dose-response trial for blood pressure

Large, ordered differences with one adjacent pair left unresolved.

Forty-five patients received a placebo or one of three doses. The outcome is the drop in systolic blood pressure after eight weeks. Sample dataset 2 in the calculator.

k = 4, N = 45F(3, 41) = 29.485 of 6 pairs differη² = 0.683critical q = 3.787
01020Mean (mmHg)cPlacebon = 12, mean 3.89b10 mgn = 11, mean 8.89b20 mgn = 12, mean 12.46a40 mgn = 10, mean 21.00A dose-response trial for blood pressure: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: 40 mg a, 20 mg b, 10 mg b, Placebo c. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
10 mg − Placebo5.003.8870.04230.13 to 9.87Yes
20 mg − Placebo8.576.8110.00013.80 to 13.33Yes
40 mg − Placebo17.1112.969< 0.000112.11 to 22.10Yes
20 mg − 10 mg3.572.7740.2192−1.30 to 8.44No
40 mg − 10 mg12.118.995< 0.00017.01 to 17.21Yes
40 mg − 20 mg8.546.4750.00023.55 to 13.54Yes

Assumption checks: Shapiro-Wilk W = 0.980, p = .609; Levene F(3, 41) = 0.32, p = .814; variance ratio 1.8.

What it means: The response rises with dose and five of six pairs differ. The one exception is 10 mg against 20 mg: the gap of 3.6 mmHg is real in the sample but too small to confirm with 11 and 12 patients.

How to write it: A one-way ANOVA showed a significant effect of group on reduction in systolic blood pressure, F(3, 41) = 29.48, p < .001, η² = .68. Tukey-Kramer post hoc tests showed that 40 mg was higher than Placebo (mean difference = 17.11 mmHg, 95% CI [12.11, 22.10], p < .001). In total 5 of 6 pairwise comparisons were significant.

3
BORDERLINE

Four teaching methods and exam scores

A significant ANOVA where only one pair survives adjustment.

Forty-seven students in four class sections of different sizes sat the same exam after different teaching formats. Sample dataset 3 in the calculator.

k = 4, N = 47F(3, 43) = 3.631 of 6 pairs differη² = 0.202critical q = 3.779
6065707580Mean (points)abLecturen = 14, mean 68.00abFlippedn = 11, mean 70.55bOnlinen = 13, mean 63.54aHybridn = 9, mean 74.11Four teaching methods and exam scores: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Hybrid a, Flipped ab, Lecture ab, Online b. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Flipped − Lecture2.551.1550.8464−5.79 to 10.88No
Online − Lecture−4.462.1170.4482−12.43 to 3.50No
Hybrid − Lecture6.112.6140.2654−2.72 to 14.95No
Online − Flipped−7.013.1260.1367−15.48 to 1.46No
Hybrid − Flipped3.571.4500.7357−5.73 to 12.86No
Hybrid − Online10.574.4560.01511.61 to 19.54Yes

Assumption checks: Shapiro-Wilk W = 0.984, p = .748; Levene F(3, 43) = 1.07, p = .371; variance ratio 2.1.

What it means: The ANOVA is significant, but only Hybrid against Online differs after adjustment. Flipped against Online has a 7-point gap that does not reach significance. Do not claim that Hybrid is the best method overall: it is not separated from Lecture or Flipped.

How to write it: A one-way ANOVA showed a significant effect of group on exam score, F(3, 43) = 3.63, p = .020, η² = .20. Tukey-Kramer post hoc tests showed that Hybrid was higher than Online (mean difference = 10.57 points, 95% CI [1.61, 19.54], p = .015). In total 1 of 6 pairwise comparisons were significant.

4
NULL RESULT

Caffeine dose and reaction time

No pair differs, and the intervals show what can and cannot be ruled out.

Forty-two volunteers received one of four caffeine doses before a reaction-time task. Sample dataset 4 in the calculator.

k = 4, N = 42F(3, 38) = 0.500 of 6 pairs differη² = 0.038critical q = 3.799
280300320340Mean (ms)a0 mgn = 12, mean 314.08a50 mgn = 10, mean 318.60a100 mgn = 11, mean 304.36a200 mgn = 9, mean 308.78Caffeine dose and reaction time: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: 50 mg a, 0 mg a, 200 mg a, 100 mg a. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
50 mg − 0 mg4.520.5260.9822−28.10 to 37.13No
100 mg − 0 mg−9.721.1610.8441−41.52 to 22.08No
200 mg − 0 mg−5.310.6000.9740−38.90 to 28.29No
100 mg − 50 mg−14.241.6250.6619−47.52 to 19.05No
200 mg − 50 mg−9.821.0660.8744−44.82 to 25.18No
200 mg − 100 mg4.410.4900.9855−29.82 to 38.65No

Assumption checks: Shapiro-Wilk W = 0.975, p = .477; Levene F(3, 38) = 1.73, p = .177; variance ratio 5.0.

What it means: Nothing differs. All groups share the letter a. But the intervals are wide, more than 30 ms either side of zero, so a moderate effect of caffeine cannot be ruled out. The study is inconclusive, not negative.

How to write it: A one-way ANOVA showed no significant effect of group on reaction time, F(3, 38) = 0.50, p = .683, η² = .04. Tukey-Kramer post hoc tests found no significant pairwise differences (all adjusted p ≥ .662).

5
SMALL SAMPLE

An enzyme assay pilot with 3 or 4 replicates

Significant results from tiny groups, with assumption checks that cannot be trusted.

A pilot run measured enzyme activity in three buffers, with only 3 or 4 replicates each. Sample dataset 5 in the calculator.

k = 3, N = 10F(2, 7) = 48.823 of 3 pairs differη² = 0.933critical q = 4.165
34567Mean (U/mL)cBuffer An = 3, mean 3.28bBuffer Bn = 4, mean 4.48aBuffer Cn = 3, mean 6.20An enzyme assay pilot with 3 or 4 replicates: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Buffer C a, Buffer B b, Buffer A c. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Buffer B − Buffer A1.196.0840.00870.38 to 2.01Yes
Buffer C − Buffer A2.9113.884< 0.00012.04 to 3.79Yes
Buffer C − Buffer B1.728.7590.00110.90 to 2.54Yes

Assumption checks: Shapiro-Wilk W = 0.892, p = .181; Levene F(2, 7) = 1.64, p = .261; variance ratio 18.3.

What it means: All three pairs differ, because the replicates are very tight. Treat this with care. With 10 values in total, the normality and variance checks have almost no power, and one group has a variance many times the others. Repeat with more replicates before publishing.

How to write it: A one-way ANOVA showed a significant effect of group on enzyme activity, F(2, 7) = 48.82, p < .001, η² = .93. Tukey-Kramer post hoc tests showed that Buffer C was higher than Buffer A (mean difference = 2.91 U/mL, 95% CI [2.04, 3.79], p < .001). In total 3 of 3 pairwise comparisons were significant. Because the equal-variance assumption was doubtful, these results should be confirmed with the Games-Howell test.

6
SIGNIFICANT BUT TRIVIAL

Store layout and customer satisfaction

A tiny p-value that hides a very small effect.

A retailer surveyed 410 shoppers across three store layouts and recorded satisfaction on a 0 to 100 scale. Sample dataset 6 in the calculator.

k = 3, N = 410F(2, 407) = 6.871 of 3 pairs differη² = 0.033critical q = 3.327
70727578Mean (points)bLayout 1n = 140, mean 71.05abLayout 2n = 120, mean 73.70aLayout 3n = 150, mean 75.44Store layout and customer satisfaction: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Layout 3 a, Layout 2 ab, Layout 1 b. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Layout 2 − Layout 12.652.9750.0903−0.31 to 5.61No
Layout 3 − Layout 14.395.2180.00071.59 to 7.19Yes
Layout 3 − Layout 21.741.9840.3402−1.18 to 4.66No

Assumption checks: Shapiro-Wilk W = 0.998, p = .902; Levene F(2, 407) = 0.94, p = .392; variance ratio 1.2.

What it means: Layout 3 beats Layout 1 with a p-value below .001, yet the gap is only 4.4 points on a 100-point scale and the layouts explain 3% of the variation. With large samples, small differences become significant. Judge this one by its size, not its p-value.

How to write it: A one-way ANOVA showed a significant effect of group on satisfaction score, F(2, 407) = 6.87, p = .001, η² = .03. Tukey-Kramer post hoc tests showed that Layout 3 was higher than Layout 1 (mean difference = 4.39 points, 95% CI [1.59, 7.19], p < .001). In total 1 of 3 pairwise comparisons were significant.

7
ASSUMPTION FAILURE

Regional incomes with unequal spread

What the output looks like when the test should not be used.

Annual incomes were sampled in three regions. The urban sample is small and contains a few very high earners. Sample dataset 7 in the calculator.

k = 3, N = 33F(2, 30) = 4.661 of 3 pairs differη² = 0.237critical q = 3.486
20406080Mean (thousand)bRuraln = 18, mean 35.42abSuburbann = 9, mean 45.83aUrbann = 6, mean 66.83Regional incomes with unequal spread: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Urban a, Suburban ab, Rural b. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Suburban − Rural10.421.6450.4838−11.66 to 32.49No
Urban − Rural31.424.2970.01325.93 to 56.91Yes
Urban − Suburban21.002.5690.1814−7.50 to 49.50No

Assumption checks: Shapiro-Wilk W = 0.852, p < .001; Levene F(2, 30) = 24.88, p < .001; variance ratio 87.4.

What it means: Both assumption checks fail badly. The urban variance is far larger than the rural one, and the smallest group has the largest spread, which is the most dangerous pattern. The Tukey Kramer p-values here are not valid. Use Games-Howell, or analyse log income.

How to write it: A one-way ANOVA showed a significant effect of group on annual income, F(2, 30) = 4.66, p = .017, η² = .24. Tukey-Kramer post hoc tests showed that Urban was higher than Rural (mean difference = 31.42 thousand, 95% CI [5.93, 56.91], p = .013). In total 1 of 3 pairwise comparisons were significant. Because the equal-variance assumption was doubtful, these results should be confirmed with the Games-Howell test.

8
APPLIED FIELD EXAMPLE

Bird species richness across four habitats

Unequal survey effort in a field study, handled as it stands.

Point counts recorded the number of bird species in four habitats. Access limited the number of counts in some habitats. Sample dataset 8 in the calculator.

k = 4, N = 32F(3, 28) = 34.135 of 6 pairs differη² = 0.785critical q = 3.861
101520Mean (species)bForest interiorn = 10, mean 13.50aForest edgen = 7, mean 19.00cGrasslandn = 9, mean 9.33aWetlandn = 6, mean 17.33Bird species richness across four habitats: means with 95% CI
Group means with 95% confidence intervals from the pooled error variance. Letters: Forest edge a, Wetland a, Forest interior b, Grassland c. Groups sharing a letter do not differ.
ComparisonMean diffqAdjusted p95% CISignificant
Forest edge − Forest interior5.507.629< 0.00012.72 to 8.28Yes
Grassland − Forest interior−4.176.1990.0008−6.76 to −1.57Yes
Wetland − Forest interior3.835.0750.00650.92 to 6.75Yes
Grassland − Forest edge−9.6713.113< 0.0001−12.51 to −6.82Yes
Wetland − Forest edge−1.672.0480.4812−4.81 to 1.48No
Wetland − Grassland8.0010.376< 0.00015.02 to 10.98Yes

Assumption checks: Shapiro-Wilk W = 0.969, p = .478; Levene F(3, 28) = 0.66, p = .584; variance ratio 2.3.

What it means: Forest edge and wetland are the richest habitats and do not differ from each other. Forest interior is intermediate and grassland is the poorest. Five of six pairs differ, and all assumption checks pass, so the result can be reported directly.

How to write it: A one-way ANOVA showed a significant effect of group on species richness, F(3, 28) = 34.13, p < .001, η² = .79. Tukey-Kramer post hoc tests showed that Forest edge was higher than Grassland (mean difference = 9.67 species, 95% CI [6.82, 12.51], p < .001). In total 5 of 6 pairwise comparisons were significant.

🧪 14. Data Collection Protocol

Study design: the Tukey Kramer test assumes a one-way design with three or more independent groups, one continuous outcome measured once on each unit, and no unit belonging to more than one group.

  1. Decide that you need every pairwise comparison before collecting data. The Tukey Kramer post hoc test is built for the case where all pairs matter. If you only care about each treatment against a control, plan a Dunnett test, which needs fewer units.
  2. Define the unit of observation. One plot, one patient, one student or one test piece. Several readings from the same unit must be averaged first. Treating them as separate values inflates N and produces false positives.
  3. Assign units to groups at random where the design allows it. If groups are natural, such as habitats or regions, sample randomly within each.
  4. Plan the sample size for the Tukey Kramer test, not for the ANOVA. Pairwise tests need more data than the overall F test. Use Table 12.7 to see what difference you could detect.
  5. Aim for equal group sizes, but do not discard data to get them. Equal sizes give the most power. If you lose units along the way, keep every remaining value. Handling unequal sample sizes is what the Tukey Kramer test is for.
  6. Use the same instrument, units and procedure in every group. A difference in method between groups will look like a difference between treatments.
  7. Measure blind to group where a human judgement is involved.
  8. Record missing values as blanks, never as zero. A zero is read as a real measurement and will pull the group mean down.
  9. Write down the outlier rule in advance. One extreme value can inflate the MSE and hide every real difference.
  10. Check the assumptions before reading the p-values. Plot the raw data, then look at the Shapiro-Wilk and Levene results.

The layout this calculator expects:

ControlFertilizer AFertilizer BFertilizer C
52606856
48577262
55666558

One column per group, one row per unit, numbers only below the header row. Blank cells are ignored, so columns can be different lengths. A long layout with a group column and a value column also works on the Upload tab.

Minimum sample: the arithmetic needs at least 2 values per group. For results worth reporting, aim for at least 5 per group, and 10 or more if you expect medium-sized effects.

Pre-registration: record the outcome, the groups, the family-wise alpha and the choice of the Tukey Kramer test before looking at the data. State what you will do if Levene's test fails, for example switch to Games-Howell.

Common collection mistakes:

  • Counting repeated readings from one unit as separate observations.
  • Filling short columns with zeros.
  • Mixing units, such as cm in one group and mm in another.
  • Dropping values to make the groups equal in size.
  • Adding a group after seeing the results.

🎯 15. When to Use the Tukey Kramer Test

This free Tukey Kramer test calculator is designed for one question: which of several independent groups differ from which. Knowing when to use the Tukey Kramer test, and when not to, matters more than the arithmetic.

Use the Tukey Kramer test when:

  • You have 3 or more independent groups and one numeric outcome.
  • You want to compare every pair of groups.
  • Group sizes are unequal, or equal. It works for both.
  • The spread is similar in every group.
  • The residuals are roughly normal, or the groups are fairly large.

Do not use it when:

  • Variances are clearly unequal. Use Games-Howell.
  • The same subjects appear in every group. Use a repeated-measures method.
  • You only want each group against a control. Use Dunnett.
  • The outcome is a rank, a count with many zeros or a yes/no result. Use Kruskal-Wallis with Dunn tests, or a model made for counts or proportions.
  • You have two factors and care about their interaction. Use a two-way ANOVA with comparisons of the cell means.

Real-world examples:

  1. Agriculture. Yield under four fertilizers, where some plots were lost to flooding.
  2. Medicine. Blood pressure change under a placebo and three doses, with different numbers of patients finishing each arm.
  3. Ecology. Species richness at point counts in four habitats, where access limited the number of counts in some.
  4. Education. Exam scores under four teaching methods, in classes of different sizes.

Study design guidance: the test is most powerful with equal groups, so plan for balance. But a design that ends up unbalanced is not a damaged design. Keep all the data and let the Kramer standard error do its job.

Decision tree:

QuestionIf yesIf no
1. Are the groups independent?Go to 2Repeated-measures ANOVA with paired comparisons
2. Is the outcome continuous and roughly normal within groups?Go to 3Kruskal-Wallis, then Dunn tests
3. Are the variances similar?Go to 4Welch ANOVA, then Games-Howell
4. Do you want every pair?Tukey Kramer testDunnett for comparisons with a control, Bonferroni or Holm for a short planned list

🔧 16. Troubleshooting and Common Errors

The ANOVA is significant but no pair is

Cause: the F test looks at all means together, and the result is close to the boundary. Fix: report both results as they are. Look at chart 3 to see which interval comes closest to excluding zero, and say that more data are needed.

A pair is significant but the ANOVA is not

Cause: one large gap among several similar means. The Tukey Kramer test targets the largest gap and can detect it when F cannot. Fix: the pairwise result is valid on its own. Report it with its interval and describe it as borderline.

My results differ from Excel

Cause: usually the equal-n formula √(MSE ÷ n) was used, or VAR.P instead of VAR.S, or zeros were typed into empty cells. Fix: follow Section 9.2 exactly and check that n, the means and the MSE match this page first.

My results differ from SPSS, R or Python

Cause: a different alpha, groups in a different order giving opposite signs, or missing values handled differently. Fix: compare N and the group means first. If those match, the q values and p-values will match to at least three decimals.

The message says a group contains entries that are not numbers

Cause: units, text, a missing-value code such as NA, or a decimal comma. Fix: delete everything that is not a number. Use a full stop as the decimal mark, because a comma is read as a separator between values.

The upload shows no columns to click

Cause: the file is in long format, or the numbers are stored as text with units. Fix: change the layout box to Long and pick the group column and the value column. If numbers carry units, remove the units in the file.

Levene's test fails

Cause: the groups have different spreads. Fix: do not report the Tukey Kramer results. Use Games-Howell, or try a log or square root transformation if the spread grows with the mean, then run the calculator again on the transformed values.

Shapiro-Wilk fails

Cause: skewed data or outliers. Fix: look at chart 2 for a single extreme value and check whether it is a recording error. With 15 or more values per group the test is fairly robust. With small groups, use Kruskal-Wallis and Dunn tests.

All the confidence intervals are very wide

Cause: small groups, high variability, or many groups. Fix: this is information, not an error. Collect more data, or reduce the number of groups to those that matter before the study.

The letters look inconsistent, such as a, ab, b

Cause: the middle group cannot be separated from either end, although the two ends differ. Fix: nothing. This is a correct and common result. Explain it in words.

The error says every value in each group is identical

Cause: there is no variation inside the groups, so the MSE is zero and q would be infinite. Fix: check that you entered raw measurements, not group means.

The charts did not appear

Cause: the chart library was blocked by a network filter or an ad blocker. Fix: allow cdnjs.cloudflare.com, reload the page and run again. All the tables are still complete without the charts.

⚖ 17. Assumptions and Limitations

Assumptions

  1. Independent observations. Each value comes from a different unit, and units in one group are unrelated to units in another. Check: from the study design, since no test on the numbers can show it. If it fails: the standard errors are too small, so p-values are too small and false positives rise.
  2. Normal residuals. Within each group the values follow a roughly normal distribution. Check: the Shapiro-Wilk test on the residuals, and chart 2. If it fails: with heavy tails or outliers the MSE is inflated, so the test loses power and misses real differences. With strong skew and small groups the error rate can go either way.
  3. Equal variances. Every group has the same underlying spread. Check: the Levene test and the variance ratio. If it fails: when small groups have the large variances, p-values are too small and false positives rise. When large groups have the large variances, p-values are too large and power falls.
  4. A continuous outcome. The measurement is on an interval or ratio scale. Check: by inspection. If it fails: means of ranks or categories have no clear meaning, so the conclusions cannot be trusted in either direction.

Limitations

  • It is slightly conservative with unequal n. The true family-wise error rate is a little below alpha, so power is a little lower than the nominal level. No exact alternative of similar simplicity exists, and the loss is small.
  • It tests pairs only. It cannot test a contrast such as the average of two groups against a third. Use the Scheffé method for that.
  • It loses power as groups are added. Every extra group raises the critical value. If only comparisons with a control matter, use the Dunnett test.
  • It is not robust to unequal variances. Use the Games-Howell test.
  • It is not robust to outliers. Use the Kruskal-Wallis test with Dunn comparisons, or a trimmed-means method.
  • It does not handle covariates or more than one factor. Use ANCOVA or a factorial model with estimated marginal means.
  • This calculator handles up to 12 groups. For more, use the R or Python script from Sections 10 and 11.

🏁 18. Conclusion

The Tukey Kramer test answers the question an ANOVA leaves open: which groups differ. It compares every pair of means, it works whether the groups are equal or unequal in size, and it keeps the chance of even one false positive across the whole set of comparisons at the level you choose.

Three habits make the difference between a correct analysis and a misleading one. First, check the equal-variance assumption before reading any p-value, because that is the assumption the test cannot survive. Second, read the confidence intervals and not only the significance labels, because an interval tells you how large the difference might be and a label does not. Third, report every pair, including the ones that did not reach significance, and never describe an inconclusive pair as "no difference".

The method is the same in every program. R's TukeyHSD, SciPy's tukey_hsd, SPSS, JMP and this calculator all compute q from the pooled error variance and both group sizes, then refer it to the studentized range distribution. Excel can do all of the arithmetic but not that last step, which is why a table or a calculator is needed there.

Paste your groups into the calculator above, read the assumption checks first, then use chart 3 and the write-up in Section 5 to report your Tukey Kramer test.

❓ 19. Frequently Asked Questions

Q1. What is the Tukey Kramer test?

The Tukey Kramer test is a post hoc test that compares every pair of group means after a one-way ANOVA. It is the version of the Tukey HSD test that works when the groups have unequal sample sizes, and it keeps the overall chance of a false positive at your chosen alpha, usually 5%.

Q2. What is the Tukey Kramer test formula?

For groups i and j the statistic is q = |mean i minus mean j| divided by the square root of (MSE / 2) times (1/n i + 1/n j). MSE is the within-group mean square from the ANOVA. The pair differs when q is larger than the critical value of the studentized range for k groups and N minus k degrees of freedom.

Q3. When should I use the Tukey Kramer test?

Use it when you have three or more independent groups, one numeric outcome, similar variances in every group, and you want to compare every pair. It is the right choice whether group sizes are equal or unequal. Do not use it for repeated measures or when variances clearly differ.

Q4. What is the difference between Tukey HSD and Tukey Kramer?

They are the same test with a different standard error. Tukey HSD assumes every group has the same size n and uses the square root of MSE / n. Tukey Kramer uses both group sizes, so it also works for unequal groups. With equal group sizes the two give identical results.

Q5. Is the Tukey Kramer test a post hoc test?

Yes. It is one of the most widely used post hoc tests. It is normally run after a one-way ANOVA to find out which groups differ, although it controls the error rate by itself and does not strictly need a significant F test first.

Q6. How do I run the Tukey Kramer test in Excel?

Excel has no built-in function for it. Compute each group mean with AVERAGE, each variance with VAR.S, and the MSE as the weighted average of the variances. Then for each pair type =ABS(mean1-mean2)/SQRT(MSE/2*(1/n1+1/n2)) and compare the answer with a critical value from a studentized range table.

Q7. How do I run the Tukey Kramer test in R?

Fit the ANOVA and pass it to TukeyHSD: TukeyHSD(aov(value ~ group, data = df)). The function is named for Tukey HSD, but it applies the Tukey-Kramer adjustment automatically when the group sizes are unequal. Make sure the group column is a factor.

Q8. How do I run the Tukey Kramer test in Python?

Use scipy.stats.tukey_hsd(a, b, c), available from SciPy 1.8. It uses the Kramer form for unequal sample sizes and returns adjusted p-values and simultaneous confidence intervals. The statsmodels function pairwise_tukeyhsd is an alternative that works on a long-format data frame.

Q9. How do I interpret Tukey Kramer test results?

Look at each pair in turn. If the adjusted p-value is below alpha, or the confidence interval does not include zero, those two groups differ. The sign of the mean difference tells you which is higher. Then read the interval limits to judge whether the difference is large enough to matter.

Q10. What are the assumptions of the Tukey Kramer test?

There are four: independent observations, a continuous outcome, roughly normal residuals, and equal variances in all groups. Equal variances matter most. If the largest group variance is more than about four times the smallest, use the Games-Howell test instead.

Q11. Can I use the Tukey test with unequal sample sizes?

Yes, as long as you use the Kramer version of the standard error, which nearly all software does by default. With unequal sizes the test is slightly conservative, meaning the true false positive rate is a little below alpha. You do not need to delete data to make groups equal.

Q12. What is the q critical value in the Tukey Kramer test?

It is the cut-off from the studentized range distribution. It depends on alpha, the number of groups and the error degrees of freedom. For 4 groups and 22 degrees of freedom at alpha 0.05 it is 3.927. A pair is significant when its q statistic is larger than this value.

Q13. Do I need a significant ANOVA before running the Tukey Kramer test?

No. The test controls the family-wise error rate on its own. Many textbooks teach it as a follow-up to a significant F test, and that is the common workflow, but requiring both makes the procedure more conservative than its stated alpha.

Q14. Why is the ANOVA significant when no Tukey Kramer comparison is?

The two tests ask different questions. The F test looks at the spread of all means together, and the Tukey Kramer test looks at the largest single gap. Near the 0.05 boundary they can disagree. Report both and describe the evidence as borderline.

Q15. What is the difference between Tukey Kramer and Bonferroni?

Both control the family-wise error rate. Tukey Kramer is designed for all pairwise comparisons and is more powerful in that case. Bonferroni is more general and wins when you test only a few comparisons chosen in advance. For all pairs among three or more groups, prefer Tukey Kramer.

Q16. What is the difference between Tukey Kramer and Games-Howell?

Tukey Kramer pools the variance across all groups and assumes it is equal. Games-Howell uses a separate variance and separate degrees of freedom for each pair, so it stays valid when variances differ. If Levene's test fails, use Games-Howell.

Q17. What do the letters a, b and ab mean in Tukey Kramer results?

They are a compact letter display. Groups that share a letter are not significantly different. Groups with no letter in common are. A group labelled ab cannot be separated from the a groups or from the b groups, even though the a and b groups differ from each other.

Q18. How many groups can the Tukey Kramer test compare?

There is no fixed limit, but the number of pairs grows quickly: 3 groups give 3 pairs, 5 give 10 and 10 give 45. Each extra group raises the critical value and lowers the power of every comparison. This calculator accepts up to 12 groups.

Q19. What sample size do I need for the Tukey Kramer test?

The calculation runs with 2 values per group, but that is too few to trust. Aim for at least 5 per group, and 10 or more for medium effects. With 4 groups of 5, two means must be about 1.8 standard deviations apart to be detected.

Q20. Is this Tukey Kramer test calculator free and accurate?

Yes. It is free, runs in your browser and does not upload your data. The studentized range p-values and critical values agree with SciPy to at least six decimal places on test datasets. For published work, confirm the result in R, Python or other statistical software.

📑 20. Cite This Tool

APA 7th edition
StatsUnlock. (2026). Tukey Kramer test calculator [Interactive statistical tool]. https://statsunlock.com/tukey-kramer-test-calculator/
BibTeX
@misc{statsunlock_tukey_kramer_2026, title={Tukey Kramer Test Calculator}, author={{StatsUnlock}}, year={2026}, note={Interactive statistical tool}, url={https://statsunlock.com/tukey-kramer-test-calculator/}}
Methods wording

🔗 21. Related Tools

📖 22. Glossary of Terms

Adjusted p-value
A p-value that already allows for the number of comparisons made. Compare it directly with alpha.
Alpha
The chance of a false positive you are willing to accept, usually 0.05.
ANOVA
Analysis of variance. A test of whether three or more group means are all equal.
Compact letter display
Letters placed beside group means. Groups that share a letter are not significantly different.
Confidence interval
A range of plausible values for a true difference, built from the data.
Critical value
The size a test statistic must exceed to be called significant.
Degrees of freedom
The number of independent pieces of information used to estimate a variance. Here it is N minus k.
Effect size
A measure of how large a difference is, separate from how certain it is.
Eta squared
The share of total variation explained by the groups, from 0 to 1.
Family-wise error rate
The chance of at least one false positive across a whole set of comparisons.
Games-Howell test
A post hoc test for all pairs that does not assume equal variances.
Hedges g
The difference between two means divided by the pooled standard deviation, corrected for small samples.
HSD
Honestly significant difference. The smallest gap between two means that the Tukey test calls significant.
Levene test
A test of whether groups have equal variances.
MSE
Mean square error. The pooled variance inside the groups, taken from the ANOVA table.
Multiple comparisons
Running several tests on the same data, which raises the chance of a false positive unless corrected.
Omega squared
A version of eta squared with less upward bias in small samples.
Post hoc test
A test run after an ANOVA to find which groups differ.
Residual
An observation minus the mean of its own group.
Shapiro-Wilk test
A test of whether data follow a normal distribution.
Simultaneous confidence intervals
A set of intervals that all contain their true values together with the stated confidence.
Standard error
The expected amount by which an estimate, such as a difference in means, varies from sample to sample.
Studentized range
The gap between the largest and smallest of several means, divided by a standard error. Its distribution gives the Tukey critical values.
Tukey-Kramer test
The Tukey HSD test with a standard error that allows for unequal group sizes.

📚 23. References

The Tukey Kramer test calculator on this page follows the methods in these 20 peer-reviewed journal articles. Each entry links to the publisher through its DOI.

  1. Tukey, J. W. (1949). Comparing individual means in the analysis of variance. Biometrics, 5(2), 99–114. https://doi.org/10.2307/3001913
  2. Kramer, C. Y. (1956). Extension of multiple range tests to group means with unequal numbers of replications. Biometrics, 12(3), 307–310. https://doi.org/10.2307/3001469
  3. Hayter, A. J. (1984). A proof of the conjecture that the Tukey-Kramer multiple comparisons procedure is conservative. The Annals of Statistics, 12(1), 61–75. https://doi.org/10.1214/aos/1176346392
  4. Dunnett, C. W. (1980). Pairwise multiple comparisons in the homogeneous variance, unequal sample size case. Journal of the American Statistical Association, 75(372), 789–795. https://doi.org/10.1080/01621459.1980.10477551
  5. Dunnett, C. W. (1980). Pairwise multiple comparisons in the unequal variance case. Journal of the American Statistical Association, 75(372), 796–800. https://doi.org/10.1080/01621459.1980.10477552
  6. Stoline, M. R. (1981). The status of multiple comparisons: Simultaneous estimation of all pairwise comparisons in one-way ANOVA designs. The American Statistician, 35(3), 134–141. https://doi.org/10.1080/00031305.1981.10479331
  7. Games, P. A., & Howell, J. F. (1976). Pairwise multiple comparison procedures with unequal n’s and/or variances: A Monte Carlo study. Journal of Educational Statistics, 1(2), 113–125. https://doi.org/10.3102/10769986001002113
  8. Copenhaver, M. D., & Holland, B. (1988). Computation of the distribution of the maximum studentized range statistic with application to multiple significance testing of simple effects. Journal of Statistical Computation and Simulation, 30(1), 1–15. https://doi.org/10.1080/00949658808811082
  9. Piepho, H.-P. (2004). An algorithm for a letter-based representation of all-pairwise comparisons. Journal of Computational and Graphical Statistics, 13(2), 456–466. https://doi.org/10.1198/1061860043515
  10. Day, R. W., & Quinn, G. P. (1989). Comparisons of treatments after an analysis of variance in ecology. Ecological Monographs, 59(4), 433–463. https://doi.org/10.2307/1943075
  11. Midway, S., Robertson, M., Flinn, S., & Kaller, M. (2020). Comparing multiple comparisons: Practical guidance for choosing the best multiple comparisons test. PeerJ, 8, e10387. https://doi.org/10.7717/peerj.10387
  12. Ruxton, G. D., & Beauchamp, G. (2008). Time for some a priori thinking about post hoc testing. Behavioral Ecology, 19(3), 690–693. https://doi.org/10.1093/beheco/arn020
  13. Dunnett, C. W. (1955). A multiple comparison procedure for comparing several treatments with a control. Journal of the American Statistical Association, 50(272), 1096–1121. https://doi.org/10.1080/01621459.1955.10501294
  14. Scheffé, H. (1953). A method for judging all contrasts in the analysis of variance. Biometrika, 40(1–2), 87–110. https://doi.org/10.1093/biomet/40.1-2.87
  15. Dunn, O. J. (1961). Multiple comparisons among means. Journal of the American Statistical Association, 56(293), 52–64. https://doi.org/10.1080/01621459.1961.10482090
  16. Welch, B. L. (1951). On the comparison of several mean values: An alternative approach. Biometrika, 38(3–4), 330–336. https://doi.org/10.1093/biomet/38.3-4.330
  17. Brown, M. B., & Forsythe, A. B. (1974). Robust tests for the equality of variances. Journal of the American Statistical Association, 69(346), 364–367. https://doi.org/10.1080/01621459.1974.10482955
  18. Shapiro, S. S., & Wilk, M. B. (1965). An analysis of variance test for normality (complete samples). Biometrika, 52(3–4), 591–611. https://doi.org/10.1093/biomet/52.3-4.591
  19. Royston, P. (1995). Remark AS R94: A remark on Algorithm AS 181: The W-test for normality. Journal of the Royal Statistical Society: Series C (Applied Statistics), 44(4), 547–551. https://doi.org/10.2307/2986146
  20. Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. https://doi.org/10.3389/fpsyg.2013.00863
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Important Plots & Charts

Calculators and Converters