Function Problems

Run a Tukey HSD Test After Two-Way ANOVA in Excel

Ayan MasoodAyan Masood Dec 2, 2026 868 views

Question details

Determine how to perform Tukey HSD post-hoc comparisons after Excel's two-way ANOVA with replication, and whether a macro can do the test.

How to Run a Tukey HSD Test After Two-Way ANOVA in Excel
Product
Microsoft Excel Analysis ToolPak
Device & OS
not provided
Scenario
The user has run a two-way ANOVA with replication and wants to compare factor levels while accounting for multiple comparisons.
Observed behavior
Excel's Analysis ToolPak does not provide a built-in Tukey HSD post-hoc test for the two-way ANOVA results.
Before you start

Keep the original observations and identify both factors and their levels; the ANOVA summary alone is not enough to reproduce the model in R. Check that the observations are independent and that a two-way ANOVA with replication is appropriate for the design.

Solution 1Recommended

Run Tukey HSD comparisons in R

Use R to refit the two-way ANOVA from the original observations and compare factor levels or factor-level combinations.

TukeyHSD uses the fitted model's residual error and adjusts for multiple pairwise comparisons. If the factors interact, interpret main-effect comparisons cautiously and consider simple-effect comparisons instead.

1
Arrange the observations

In Excel, create a table with one observation per row and columns named factorA, factorB, and response. Enter each observation's two factor levels and numeric response.

2
Export the table

Select File > Save As and choose CSV as the file type. Save the table as anova_data.csv; CSV saves only the active sheet.

3
Fit the model in R

In R, run: d <- read.csv('anova_data.csv'); d$factorA <- factor(d$factorA); d$factorB <- factor(d$factorB); model <- aov(response ~ factorA * factorB, data = d); summary(model). Use the path to your CSV if it is not in R's working directory.

4
Run pairwise comparisons

In the R console, run TukeyHSD(model, which = c('factorA', 'factorB')) for main-effect comparisons, or TukeyHSD(model, which = 'factorA:factorB') to compare factor-level combinations. Review the adjusted p-values and confidence intervals.

Check the design and assumptions: The standard two-way ANOVA model assumes independent observations, approximately normal residuals, and similar residual variances. R's TukeyHSD is exact for balanced designs and includes an adjustment intended for mildly unbalanced designs.
Free Microsoft Office alternative

Prepare ANOVA Data with WPS Spreadsheet

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files, organize observations into columns, and export a CSV for analysis in statistical software. It does not add Tukey HSD to Excel's Analysis ToolPak.

Organize factor levels and response values for a two-way ANOVA.Open and edit Microsoft Excel XLSX and XLS files for easier migration.Export spreadsheet data to CSV for use in R.Use a familiar, easy-to-learn spreadsheet interface.
microsoft office alternative - wps office

Frequently Asked Questions

Does Excel's Analysis ToolPak include Tukey HSD?

No. The Analysis ToolPak provides two-way ANOVA with replication but does not include a built-in Tukey HSD post-hoc test. Export the original observations and use R or another statistical tool.

Can a VBA macro run Tukey HSD after a two-way ANOVA?

A custom VBA macro is possible, but it must use the correct model residual mean square and degrees of freedom, account for the replication structure, and adjust for multiple comparisons. Excel does not provide such a macro as part of the Analysis ToolPak.

What should I compare if the two factors interact?

Consider comparing levels of one factor within each level of the other. In R, pairs(emmeans(model, ~ factorA | factorB), adjust = 'tukey') performs those comparisons for factorA.

Can I run the R analysis using only Excel's ANOVA summary?

The R workflow shown here requires the original observations to refit the model. Arrange them in factorA, factorB, and response columns, then save the active sheet as a CSV file.