Chapter 19 Apriori and Post-Hoc Analyses

ANOVA tells us that at least one mean differs, but it does not tell us which means differ. This chapter is about how to test hypotheses that are more specific than the original ‘omnibus’ ANOVA. Examples include comparing just two of the means, or comparing one mean (e.g. a control condition) to each of the other means.

The main issue here is familywise error, FWER discussed in the last chapter, which is that the probability of making one or more Type I errors increases with the number of hypothesis tests you make.

For example, if you run 10 independent hypothesis tests on your results, each with an alpha value of 0.05, the probability of getting at least one false positive would be:

\[1-(1-0.05)^{10} = 0.401\]

This number, 0.4013 is clearly unacceptably high. The equation above applies only to independent hypothesis tests. In most of the ANOVA post-hoc settings, the tests are typically correlated, so the exact FWER differs, but the idea is the same: FWER increases with the number of hypothesis tests.

The goal of correcting for FWER is to adjust the tests to make it harder to reject \(H_0\). Specifically, we want the the probability of making 1 or more type I errors to be less than \(\alpha\).

Specific hypothesis tests on ANOVA data fall into two categories, ‘A Priori’ and ‘post-hoc’.

A Priori tests are hypothesis tests that you planned on running before you started your experiment. Often they are written down and preregistered. Since there are many possible tests we could make, setting aside a list of just a few specific A Priori tests lets us correct for a relatively low familywise error rate.

Post-hoc tests are hypothesis tests that you came up with after looking at the data. For example, you might want to go back and see if there is a significant difference between the highest and lowest means. Under the null hypothesis, the probability of rejecting a test on the most extreme difference between means will be much greater than \(\alpha\). Or, perhaps we want to go crazy and compare all possible pairs of means. Since there are many tests that you could have run, even if you only care about a few, you need to correct for a larger FWER than if you just had a few A priori tests in mind.

19.1 One-Factor ANOVA Example:

We’ll go through A Priori and post-hoc tests with an example. Suppose you want to study the effect of background noise on test score. You randomly select 10 subjects for each of 5 conditions and have them take a standardized reading comprehension test with the following background noise: silence, white noise, rock music, classical music, and voices.

Throughout this chapter we’ll be referencing this same set of data. You can access it yourself at:

http://courses.washington.edu/psy524a/datasets/AprioriPostHocExample.csv

Your experiment generates the following statistics:

Table 19.1:
mean n sd sem
silence 77.11 10 25.26436 7.989291
white noise 80.45 10 16.70617 5.282955
rock music 60.56 10 11.63856 3.680435
classical music 58.15 10 20.61112 6.517809
voices 48.37 10 15.04113 4.756424

The result of the ANOVA is:

Table 19.2:
df SS MS F p
Between 4 7285.217 1821.3042 5.3445 p = 0.0013
Within 45 15335.044 340.7788
Total 49 22620.261

Here’s a plot of the means with error bars as the standard error of the mean:

19.2 Comparing Means with Contrasts

The simplest example of a ‘contrast’ is the comparison of one mean to another mean, but it could also be the comparison of the average of one group of means to the average of another group of means.
The same contrast can be specified in advance (A Priori) or chosen after looking at the data (post-hoc). Here we’ll learn how to construct and test a contrast. Later we’ll decide which family of comparisons needs protection against false positives.

19.2.1 t-test for Two Means

In our example, suppose that before we ran the experiment we had the prior hypothesis that there is a difference in mean test score between the silence and the voices conditions. This leads to comparing the means \(\overline{X}_{1} = 77.11\) and \(\overline{X}_{5} = 48.37\)

You’d think that we would simply conduct an independent measures two-tailed t-test using these two group means and variances, while ignoring all of the other conditions (and sometimes this is what people do). But since we have \(MS_{within}\), and if we assume homogeneity of variance, we can use this value in the denominator of the t-test since it’s a better estimate of the population variance than the pooled variance from just two groups.

The regular old t-statistic was (since we have equal sample size, n):

\[t=\frac{\overline{X}_{1}-\overline{X}_{5}}{\sqrt{\frac{s_{1}^2+s_{5}^2}{n}}} = \frac{77.11 - 48.37}{\sqrt{\frac{25.3^2 + 15^2}{10}}} = 3.091 \]

With \(df = (n-1)+(n-1) = 2n-2 = 18\).

However, we have mean-squared error within (\(MS_w\)) from the ANOVA, which is a better estimate of our population variance than \(s_{1}^2\) and \(s_{5}^2\). So we’ll use it instead of the pooled variance:

\[t= \frac{\overline{X}_{1}-\overline{X}_{5}}{\sqrt{\frac{2MS_{w}}{n}}}\]

The degrees of freedom is now N-k, since this is the df for \(SS_{within}\).

For our example:

\[t= \frac{77.11 - 48.37}{\sqrt{\frac{(2)340.8}{10}}} = 3.4813\]

With df =N-k = 50 - 5 = 45, the p-value of t is 0.0011.

Since we planned on making this comparison ahead of time, and this is our only A Priori comparison, we can use this test to reject \(H_{0}\) and say that there is a significant difference in the mean test score between the silence and the voices conditions.

As an exercise, make a planned comparison t-test between the silence and classical music conditions. You should get a t-value of 2.2966 and a p-value of 0.0263.

19.2.2 ‘Contrast’ for two means

Another way of thinking about the comparison we just made between the means from the silence and the voices conditions is to consider the numerator of our t-test as a ‘linear combination’ of means. A linear combination is simply a sum of weighted values. If we call \(a_i\) the weight for group \(i\), then for this comparison, we assign a weight of \(a_{1} = 1\) for the silence condition and a weight of \(a_{5} = -1\) for the voices condition. All other means get zero weights. We use a lower case ‘psi’ (\(\psi\)) to indicate this weighted sum of means:

\[\psi = \sum{a_i\overline{X}_i}\]

For this example is simply difference between the two means:

\[\psi = (1)(77.11) + (-1)(48.37) = 28.7400\]

The t-statistic for any contrast is:

\[ t = \frac{\psi}{\sqrt{MS_w\sum{{(a_i^2/n_i)}}}} \]

Where \(a_i\) is the weight for for group \(i\) and \(n_i\) is the sample size for group \(i\). For equal sample sizes, like this example, the t-statistic simplifies to:

\[ t = \frac{\psi}{\sqrt{MS_w(\sum{{a_i^2})/n}}} \]

Which for our example, t is exactly as we calculated above:

\[t = \frac{28.74}{\sqrt{340.78(1^2+(-1)^2)/10}} = 3.4813\] Note that our contrast weights, 1 and -1, can vary by a scale factor. If we used, for example, \(\frac{1}{2}\) and \(-\frac{1}{2}\) we’d get the same t statistic and p-value. But the contrasts do have to add up to zero in order to test the null hypothesis that the population means are the same.

Sometimes you’ll see contrasts computed in terms of the F statistic instead of t. This is equivalent because, as we’ve discussed earlier, \(F = t^2\).

19.2.3 Contrast for groups of means

Contrasts also allow us to compare groups of means with other groups of means. In our example, suppose we have the prior hypothesis that music in general has a different effect on test scores than white noise. That is, we want to compare the average of the two music conditions (rock and classical) with the white noise condition.

Our weights will be 1 for the white noise condition, and -.5 for the rock and -.5 for the classical conditions, and zero for the remaining conditions. The corresponding linear combination of means is:

\[\psi = (1)(80.45) + (-0.5)(60.56) + (-0.5)(58.15) = 21.0950\]

You should convince yourself that this value, \(\psi\), is the difference between the white noise condition and the average of the two music conditions. It should have an expected value of zero for the null hypothesis because the weights add up to zero.

The t-statistic for this contrast is:

\[t = \frac{21.095}{\sqrt{340.78\frac{(1)^2 +(-0.5)^2+(-0.5)^2}{10}}} = 2.95\]

The degrees of freedom for all contrasts is equal to the degrees of freedom for \(MS_w\), which is 45. The p-value for this contrast is 0.005

19.2.3.1 Orthogonal contrasts and independence

The estimates of these two contrasts are independent under the normal ANOVA model because they use different groups. Their test statistics still share the same estimated error variance.

Contrast estimates can be independent even if they share groups. In this balanced design, their covariance is zero when the dot product of their weights is zero. Under the normal ANOVA model, zero covariance implies independence of the estimates. When this happens, the two contrasts are called orthogonal. In our example:

c1 = [1, 0, 0, 0, -1]

and our new contrast is

c2 = [0, 1, -1/2, -1/2, 0]

The sum of their products is 0:

(1)(0) + (0)(1) + (0)(-.5) + (0)(-.5) + (-1)(0) = 0

Another contrast that is orthogonal to the second one is:

c3 = [0, 0, 1, -1, 0]

This is because (0)(0) + (1)(0) + (-.5)(1) + (.5)(1) + (0)(0) = 0

What does this contrast test? It compares the test scores for the rock and classical music conditions. Notice that this contrast is also orthogonal to c1, the first contrast.

It turns out that there are exactly as many mutually orthogonal contrasts as there are degrees of freedom for the numerator of the omnibus (k-1). So there should be 4 orthogonal contrasts for our example (though this is not a unique set of 4 orthogonal contrasts). This leaves one more contrast. Can you think of it?

The answer is:

c4 = [1/2 -1/3 -1/3 -1/3 1/2]

Show that c4 is orthogonal to the other three. What is it comparing? It’s the mean of the silence and voices conditions compared to the mean of the other three conditions (white noise, rock and classical). This doesn’t make much sense, so we probably wouldn’t have had an A Priori hypothesis about this particular contrast.

Notice that since each contrast has one degree of freedom, the sum of degrees freedom across all possible contrasts is equal to the degrees of freedom of the omnibus ANOVA. Likewise, it turns out that the sums of the \(SS_{contrast}\) across all orthogonal contrasts adds up to the \(SS_{between}\).

19.3 Contrasts with R

R has a very convenient package emmeans that has functions for conducting all of the Apriori and post-hoc analyses in this chapter.

Let’s load in the data set that we’ve been working with and compute the ANOVA. This just as we covered in the chapter ANOVA Part 2: Partitioning Sums of Squares:

# choose your alpha
alpha <- .05
# load in the data
mydata<-read.csv("http://www.courses.washington.edu/psy524a/datasets/AprioriPostHocExample.csv")
# reorder the levels of 'backgroundnoises'
mydata$backgroundnoises <- factor(
  mydata$backgroundnoises,
  levels = c("silence",
             "white noise",
             "rock music",
             "classical music",
             "voices"))
# run the ANOVA, saving the output of 'lm'
lm.out <- lm(testscores ~ backgroundnoises,data=mydata)
anova.out <- anova(lm.out)

Notice that we saved the output of lm as lm.out before passing it into anova. The first step is to pass this output of lm function into the emmeans function to calculate the ‘marginal means’:

emm <- emmeans(lm.out, ~ backgroundnoises)
emm
##  backgroundnoises emmean   SE df lower.CL upper.CL
##  silence            77.1 5.84 45     65.4     88.9
##  white noise        80.5 5.84 45     68.7     92.2
##  rock music         60.6 5.84 45     48.8     72.3
##  classical music    58.1 5.84 45     46.4     69.9
##  voices             48.4 5.84 45     36.6     60.1
## 
## Confidence level used: 0.95

The result is a table that is a lot like the output of summarySE - it includes the mean for each group and standard errors. However, the standard error is based on the \(MS_{w}\) from the omnibus ANOVA, not the standard deviations for each group. That’s why the ‘SE’ values in the table are all the same. As discussed earlier, all contrasts use this common value of \(MS_{w}\).

We next define our contrasts as a list of vectors, each containing the weights for the 5 levels.

contrasts <- list(
  c1 = c(1, 0, 0, 0, -1),                # silence vs voices
  c2 = c(0, 1, -0.5, -0.5, 0),           # white vs avg(music)
  c3 = c(0, 0, 1, -1, 0),                # rock vs classical
  c4 = c(0.5, -1/3, -1/3, -1/3, 0.5)     # silence+voices vs others
)

Contrasts are run using the contrast function on the output of emmeans:

contrast(emm, method = contrasts)
##  contrast estimate   SE df t.ratio p.value
##  c1          28.74 8.26 45   3.481  0.0011
##  c2          21.09 7.15 45   2.951  0.0050
##  c3           2.41 8.26 45   0.292  0.7717
##  c4          -3.65 5.33 45  -0.684  0.4973

The ‘estimate’ is the value of \(\psi\) and ‘SE’ is the denominator of the t-test. You should recognize the \(\psi\), t, and p-values for the first two contrasts.

To access these values, you need to pass the output of contrast into summary. For example, to report the results of the first contrast using APA format:

contrast.result <- summary(contrast(emm,method = contrasts))
sprintf('t(%d) = %0.2f, p = %0.4f',  contrast.result$df[1],  contrast.result$t.ratio[1],contrast.result$p.value[1])
## [1] "t(45) = 3.48, p = 0.0011"

19.3.1 Breaking down \(SS_{between}\) across contrasts

For an ANOVA with \(k\) groups there will be \(k-1\) independent contrasts. These contrasts are not unique - there can be multiple sets of \(k-1\) orthogonal contrasts. But for any set, it turns out that each of the \(k-1\) orthogonal contrasts accounts for its own portion of the variability across means, \(SS_{between}\).

To see this, we need to think of contrasts in terms of F-tests instead of t-tests. This can be done because for each contrast, the equivalent F-test would have an F value of \(F = t^2\). Also, since

\[t^2 = F = \frac{MS_{contrast}}{MS_{within}}\] since \(df_{contrast}\) = 1, \(MS_{contrast} = SS_{contrast}\), so

\[SS_{contrast}= t^2MS_{within}\] For our first contrast, \(t = 3.4813\), so, borrowing \(SS_{within}\) from the omnibus ANOVA,

If you do this for all four contrasts you’ll se that \(SS_{between}\) is the sum the \(k-1\) \(SS_{contrast}\) values:

\[4129.94+2966.66+29.0405+159.578 = 7285.22 = SS_{between}\]

The intuition behind this is that the 4 contrasts are breaking down the total amount of variability between the means (\(SS_{between}\)) into separate independent components, each producing their own hypothesis test.

19.4 Controlling for familywise error rates

19.4.1 Which comparisons belong to the family?

To decide which comparisons belong in a family, ask: Which comparisons could have ended up in the results? If you planned a single contrast and stuck to it, there is nothing to adjust for. If you planned several contrasts, adjust for that set. If you looked at every pair of means and reported only the largest difference, adjust for all the pairs you considered, even though you reported only one.

19.4.2 A fixed set of comparisons

Controlling for familywise error typically involves making it harder to reject \(H_0\) by decreasing alpha. This comes at the expense of lowering the power for each individual test because, remember, decreasing alpha decreases power.

We’ll cover three adjustments for a fixed set of tests. Bonferroni and Holm do not require independent tests; the Šidák calculation below uses independence.

19.4.2.1 Bonferroni correction

The Bonferroni correction is simple. If you are making \(m\) comparisons using \(\alpha\) as your original rejection criterion, you test each comparison at \(\alpha/m\).

Why does this work? There’s a theorem called the ‘union bound’ or ‘Boole’s inequality’ that implies that the probability at least one type I error occurring is less than or equal to the sum of their individual probabilities. So if we lower each probability of a type I error to \(\frac{\alpha}{m}\), then the FWER will be no higher than \(\sum_{i=1}^{m}\frac{\alpha}{m} = \alpha\).

Our contrasts produced p-values of 0.0011, 0.005, 0.7717, and 0.4973. If we were to make all four A Priori comparisons, we’d need to adjust alpha to be 0.05/4 = 0.0125.

Using a Bonferroni correction we reject the null hypothesis for contrasts 1 and 2 but not for contrasts 3 and 4.

Equivalently, instead of dividing \(\alpha\), we can ‘adjust’ our p-values by multiplying them by 4 and compare them to \(\alpha\). These ‘adjusted p-values’ for the Bonferroni correction are the result using the emmeans package by adding an ‘adjust’ argument to the contrast function:

contrast(emm, method = contrasts, adjust = "bonferroni")
##  contrast estimate   SE df t.ratio p.value
##  c1          28.74 8.26 45   3.481  0.0045
##  c2          21.09 7.15 45   2.951  0.0201
##  c3           2.41 8.26 45   0.292  1.0000
##  c4          -3.65 5.33 45  -0.684  1.0000
## 
## P value adjustment: bonferroni method for 4 tests

Adjusted p-values have become the common way to report corrections for familywise error. They’re easy to interpret since they can be simply compared to \(\alpha\). Since adjusted p-values are the original p-values multiplied by the number of tests, then it’s possible for adjusted p-values to be greater than 1, which doesn’t make sense for probabilities. For those cases, adjusted p-values are set to a ceiling of 1.

19.4.2.2 Šidák correction

The Šidák correction assumes that all \(m\) tests are independent. The goal is to find the corrected value of \(\alpha\), which we’ll call \(\alpha'\) that lowers the FWER to alpha. With a little algebra we can solve for \(\alpha'\):

\[FWER = 1-(1-\alpha')^m = \alpha \qquad \Longrightarrow \qquad \alpha' = 1-(1-\alpha)^{1/m}.\]

The Šidák correction is close to the Bonferroni correction for small values of \(\alpha'\). For our example with \(m\) comparisions at \(\alpha\) = 0.05, \(\alpha'\) = 0.0127, which is close to the Bonferroni correction of 0.0125.

The emmeans package reports the Šidák correction with adjusted p-values. If \(p\) is the original p-value, the adjusted p-value is \(1-(1-p)^m\). For example, the p-value from our first contrast is 0.0011. So the adjusted p-value is:

\[1-(1-0.0011)^4 = 0.0045\]

contrast(emm, method = contrasts, adjust = "Sidak")
##  contrast estimate   SE df t.ratio p.value
##  c1          28.74 8.26 45   3.481  0.0045
##  c2          21.09 7.15 45   2.951  0.0199
##  c3           2.41 8.26 45   0.292  0.9973
##  c4          -3.65 5.33 45  -0.684  0.9361
## 
## P value adjustment: sidak method for 4 tests

Notice that the adjusted p-values are just a little lower than for the Bonferroni correction.

19.4.2.3 Holm-Bonferroni Multistage Procedure

The Holm-Bonferroni procedure is a more forgiving way to correct for familywise error, and has been used more recently, especially for large number of comparisons. The procedure is best described by example. First, we rank-order our p-values from our multiple comparisons in from lowest to highest. From our four contrasts: 0.0011, 0.005, 0.4973, and 0.7717 for contrast numbers 1, 2, 4, and 3 respectively.

We start with the lowest p-value and compare it to the alpha that we’d use for the Bonferroni correction (\(\frac{0.05}{4} = 0.0125\)).

If our lowest p-value is less than this adjusted alpha, then we reject the hypothesis for this contrast. If we fail to reject then we stop. For our example, p = 0.0011 is less than 0.0125, so we reject the corresponding contrast (number 1) and move on.

We then compare or next lowest p-value to a new adjusted alpha. This time we divide alpha by 4-1=3 to get \(\frac{0.05}{3} = 0.0167\), a less conservative value. If we reject this contrast, the we move on to the next p-value and the next adjusted alpha \(\frac{0.05}{2}=0.025\).

This continues until we fail to reject a comparison, and then we stop.

The idea is that if you manage to reject with the lowest p-value using the full Bonferroni correction for m tests (\(\frac{\alpha}{m}\)), then you can move on to the next p-value and correct only for the remaining m-1 tests (\(\frac{\alpha}{m-1}\)), and so on.

Here’s how to run the Holm-Bonferroni procedure with the contrast function in emmeans.

contrast(emm, method = contrasts, adjust = "holm")
##  contrast estimate   SE df t.ratio p.value
##  c1          28.74 8.26 45   3.481  0.0045
##  c2          21.09 7.15 45   2.951  0.0151
##  c3           2.41 8.26 45   0.292  0.9946
##  c4          -3.65 5.33 45  -0.684  0.9946
## 
## P value adjustment: holm method for 4 tests

Like for the other tests, you get are the adjusted p-values - so that for our example, the lowest p-value gets multiplied by 4, the second lowest is multiplied by 3 and so on. The nice thing about thinking in terms of adjusted p-values (instead of adjusting \(\alpha\)) is that the stop rule is implicit - once the first test is rejected with an adjusted p-value greater than \(\alpha\), all of the other tests will also be rejected.

19.5 Methods for Specific Families of Comparisons

The next three methods are organized by the number of possible comparisons that could be made. These methods apply whether that test was planned in advance (Apriori) or were part of an ‘exploratory analysis’ made after viewing the results (post-hoc).

19.5.1 Each treatment versus a control: Dunnett’s test

Dunnett’s test protects the family of comparisons against a control condition. These comparisons are often planned before collecting any data. For our example, it makes sense to compare all of our conditions to the silence condition, giving us 4 tests. Bonferroni is valid for these comparisons even though they share a control. Dunnett uses their joint distribution to account for that dependence and can be less conservative.

Dunnett’s test relies on finding critical values from a distribution that is related to the t-distribution called the Dunnett’s t Statistic which has its own parametric distribution. R doesn’t have a built-in pdunnet or qdunnet function. Fortunately you don’t have to worry about this distribution since emmeans handles this naturally.

With the silence condition as the control condition, we’ll compare the other four means to this one mean (\(\overline{X}_1 = 77.11)\)

Again, it’s done contrast, but setting the method to “trl.vs.ctrl” and defining the control conditon with ‘ref’:

contrast(emm, method = "trt.vs.ctrl", ref = "silence")
##  contrast                  estimate   SE df t.ratio p.value
##  white noise - silence         3.34 8.26 45   0.405  0.9582
##  rock music - silence        -16.55 8.26 45  -2.005  0.1610
##  classical music - silence   -18.96 8.26 45  -2.297  0.0880
##  voices - silence            -28.74 8.26 45  -3.481  0.0042
## 
## P value adjustment: dunnettx method for 4 tests

These p-values are all adjusted for familywise error, so no further correction is needed.

19.5.2 All pairwise comparisons: Tukey’s test

The Tukey Test is a way of correcting for FWER when testing all possible pairs of means. For our example there are 10 pairs of means to test. We could use a Bonferroni test, but the Tukey test uses the distribution of the range of the group means to account for that dependence and can be less conservative. Note that the 4 tests that we ran with Dunnett’s test are a subset of the 10 tests that we’ll be running with the Tukey Test.

The test is based on the distribution that is expected when you specifically compare the largest and smallest mean. If the null hypothesis is true, the probability of a significant t-test for these most extreme means will be quite a bit greater than \(\alpha\), which is the probability of rejecting any random pair of means.

The way for correcting for this inflated false positive rate when comparing the most extreme means is to use a statistic called the Studentized Range Statistic and goes by the letter q.

The statistic q is calculated as follows:

\[q = \frac{\overline{X}_l-\overline{X}_s}{\sqrt{\frac{MS_{within}}{n}}}\]

Where \(\overline{X}_{l}\) is the largest mean, \(\overline{X}_{s}\) is the smallest mean, and n is the sample size of each group (assuming that all sample sizes are equal).

The q-statistic for our most extreme pairs of means is:

\[q = \frac{80.45 - 48.37} {\sqrt{\frac{340.7788}{10}}} = 5.4954\]

The q statistic has its own distribution. Like the t-statistic, it has heavier tails than the normal distribution for small degrees of freedom. Also, q increases in width with increasing number of groups. That’s because as the number of possible comparisons increases, the difference between the extreme means increases.

R has the functions ptukey and qtukey to test the statistical significance of this difference of extreme means. ptukey needs our value of q, the number of groups, and \(df_{within}\). For our pair of extreme means:

1-ptukey(5.4954,5,45)
## [1] 0.002925262

Importantly, even though we selected these two means after running the experiment, this p-value accounts for this bias.

In fact, almost magically, we can use this procedure to compare any or all pairs of means, and we won’t have to do any further correction for multiple comparisons.

19.5.2.1 Tukey’s ‘HSD’

Back in the chapter on effect sizes and confidence intervals we discussed how an alternative way to make a decision about \(H_{0}\) is to see if the null hypothesis is covered by the confidence interval. The same thing is often done with the Tukey Test.

Instead of finding a p-value from our q-statistic with ptukey, we’ll go the other way and find the value \(q_{crit}\) that covers the middle 95of the q distribution using qtukey. Since it’s a two-tailed test, we need to find q for the top 97.5%

q_crit <- qtukey(1-0.05,5,45)
## [1] 4.018417

We can go through the same logic that we did when we derived the equation for the confidence interval. If we assume that the observed difference between a pair of means, \(\overline{X}_i-\overline{X}_j\) is the true difference between the means, then we expect that in future experiments, we can expect to find a difference 95% of the time within:

\[\overline{X}_i-\overline{X}_j \pm q_{crit}\sqrt{\frac{MS_{w}}{n}}\] For our example:

\[ q_{crit}\sqrt{\frac{MS_{w}}{n}} = 4.0184\sqrt{\frac{340.7788}{10}} = 23.4579\]

This value, 23.4579 is called Tukeys’ honestly significant difference, or HSD. Any pair of means that differs by more than this amount can be considered statistically significant at the level of \(\alpha\).

The ‘H’ in Tukey’s HSD is for ‘honestly’ presumably because it takes into account all possible pairwise comparisons of means, so we’re being honest and accounting for familywise error.

We can use Tukey’s HSD to calculate a confidence interval by adding and subtracting it from the observed difference between means. Our most extreme means had a difference of

\[80.45 - 48.37 = 32.08\]

The 95% confidence interval for the difference between these means is:

\[(32.08 - 23.4579, 32.08 + 23.4579)\]

which is

\[( 8.6221, 55.5379)\]

The lowest end of this interval is greater than zero, which is consistent with the fact that the p-value for the difference between means (0.0029) is less than \(\alpha\) = 0.05. If the difference between the means is significantly significant (with \(\alpha\) = 0.05), then the 95% confidence interval will never contain zero.

All this is easy to do in R using the pairs function in the emmeans package.

pairs(emm, adjust = "tukey")
##  contrast                      estimate   SE df t.ratio p.value
##  silence - white noise            -3.34 8.26 45  -0.405  0.9942
##  silence - rock music             16.55 8.26 45   2.005  0.2804
##  silence - classical music        18.96 8.26 45   2.297  0.1649
##  silence - voices                 28.74 8.26 45   3.481  0.0094
##  white noise - rock music         19.89 8.26 45   2.409  0.1315
##  white noise - classical music    22.30 8.26 45   2.701  0.0695
##  white noise - voices             32.08 8.26 45   3.886  0.0029
##  rock music - classical music      2.41 8.26 45   0.292  0.9984
##  rock music - voices              12.19 8.26 45   1.477  0.5826
##  classical music - voices          9.78 8.26 45   1.185  0.7600
## 
## P value adjustment: tukey method for comparing a family of 5 estimates

The p-values in the column ‘p.value’ reflect the correction for FWER, so they don’t need to be adjusted to compare to \(\alpha\). Any test for a pair of means with an adjusted p-value less than \(\alpha\) can be rejected.

Here you’ll see adjusted p-values for all possible \(\frac{5 \times 4}{2} = 10\) comparisons. Can you find the row for the biggest difference between means?

You can also add confidence intervals by passing the output of pairs in to the confint function like this:

 pairs(emm, adjust = "tukey") %>% confint()
##  contrast                      estimate   SE df lower.CL upper.CL
##  silence - white noise            -3.34 8.26 45   -26.80     20.1
##  silence - rock music             16.55 8.26 45    -6.91     40.0
##  silence - classical music        18.96 8.26 45    -4.50     42.4
##  silence - voices                 28.74 8.26 45     5.28     52.2
##  white noise - rock music         19.89 8.26 45    -3.57     43.3
##  white noise - classical music    22.30 8.26 45    -1.16     45.8
##  white noise - voices             32.08 8.26 45     8.62     55.5
##  rock music - classical music      2.41 8.26 45   -21.05     25.9
##  rock music - voices              12.19 8.26 45   -11.27     35.6
##  classical music - voices          9.78 8.26 45   -13.68     33.2
## 
## Confidence level used: 0.95 
## Conf-level adjustment: tukey method for comparing a family of 5 estimates

You’ll also see the columns ‘lower.CL’ and ‘upper.CL’. These are the ranges for the 95% confidence interval on the differences between the means. For all cases, if the p-value ‘p.value’ is less than .05, then the 95% confidence interval will not include zero. Is the confidence interval the same as our calculation? You should notice that the range between ‘lower.CL’ and ‘upper.CL’ is always the same value of Tukey’s HSD = 23.4579.

19.5.2.2 Tukey–Kramer test for unequal sample sizes

If the sample sizes varies across groups (called an ‘unbalanced design’) there is a modification of the Tukey test called the ‘Tukey-Kramer method’ which has a more general definition of q.

Specifically, to compare means from group i to group j, with sample sizes \(n_{i}\) and \(n_{j}\), the q-statistic is:

\[q = \frac{\overline{X}_i-\overline{X}_j}{\sqrt{\frac{MS_{within}}{2}(\frac{1}{n_i}+\frac{1}{n_j})}}\] The pairs function in emmeans automatically runs the Tukey-Cramer test if the design is unbalanced.

19.5.3 All possible contrasts: Scheffé’s method

The Scheffé’ test allows for post-hoc comparisons across all possible contrasts (including non-orthogonal contrasts). Since there are many more possible contrasts than pairs of means, the Scheffé’ test has to control for more possible comparisons than either Dunnett’s test or the Tukey Test, and is therefore the most conservative and least powerful.

The Scheffé test works by converting the results of a contrast to the F-statistic. For the first contrast, t-statistic was \(t = 3.48\). So \(F = 3.48^2 = 12.12\).

We compare this to the critical value of F from the omnibus ANOVA, scaled by \(k-1\), where k is the number of groups. The critical value of F for 4 and 45 and \(\alpha\) = 0.05 is, using the qf function:

## [1] "F_crit <- qf(1-0.05,4,45)"
## [1] 2.578739

The Scheffé’ test adjusts for multiple comparisons by multiplying the critical value of F for the original ‘omnibus’ test by k-1 (the number of groups minus one).

Our adjusted critical value for F is (4)(2.5787) = 10.315. Any contrast with an F-statistic greater than this can be considered statistically significant.

Or, we can calculate an adjusted p-value for the Scheffé test by scaling the F-statistic from the contrast by \(k-1\) and using pf:

## [1] "p.adj <- 1 - pf(12.12/4,4,45)"
## [1] 0.02697962

With emmeans, the Scheffé test is easy, just set ‘adjust’ to “sheffe”:

contrast(emm, method = contrasts, adjust = "scheffe",sheffe.rank = 4)
##  contrast estimate   SE df t.ratio p.value
##  c1          28.74 8.26 45   3.481  0.0270
##  c2          21.09 7.15 45   2.951  0.0869
##  c3           2.41 8.26 45   0.292  0.9991
##  c4          -3.65 5.33 45  -0.684  0.9758
## 
## P value adjustment: scheffe method with rank 4

There’s our adjusted p-value for the first contrast - the only one that survived the Scheffé test.

19.5.3.1 A note about Scheffé’s test in R

There’s an important subtlety in how the emmeans package implements Scheffé’s test. As we’ve discussed, Scheffé’s test controls the familywise error rate across all possible contrasts, including contrasts chosen after looking at the data. For an ANOVA with (k) group means, the critical F-value is multiplied by (k-1).

Surprisingly, this is not the default behavior of emmeans. Instead, R determines the rank from the particular contrasts included in the command. If we supply only one contrast, it uses a rank of 1, resulting in no adjustment at all! Adding more independent contrasts can actually change the adjusted p-value for our original contrast. To override this, we input sheffe.rank = 4 into the contrast function. In general, you should enter a sheffe rank of k-1 where k is the number of means in your design. See this link in the emmeans documentation for more details.

With the Scheffé test, the door is wide open to test any post-hoc comparison we want. Looking at the bar graph, it looks like there is a difference between the average of the silence, and white noise conditions, and the average of the rock music, classical music, and voices conditions. This would be a contrast with weights:

new_contrast <- list(6*c(1/2, 1/2, -1/3, -1/3, -1/3))

Notice that I muliplied the fractions by 6, the least common divisor so that the weights are integers. Remember, scaling doesn’t matter as long as our weights add up to zero.

The adjusted p-value for this is:

contrast(emm, method = new_contrast, adjust = "scheffe", scheffe.rank = 4)
##  contrast            estimate SE df t.ratio p.value
##  c(3, 3, -2, -2, -2)      139 32 45   4.332 <0.0001
## 
## P value adjustment: scheffe method with rank 1

This is highly significant, so we can say that there is a significant difference between these groups of means.

It feels like cheating - that we’re making stuff up. And we kind of are - post-hoc tests are things you made up after you look at the data. And with the Sheffe’ test we can ‘honestly’ test as many contrasts as we can think of!

I think if feels wrong because we’re so concerned about replicability and preregistration. But with the proper correction for FWER, this is totally fine. In fact, I’ll bet that most of the major discoveries on science have been made after noticing something interesting in the data that wasn’t anticipated. I would even argue that sticking strictly to your preregistered hypotheses could slow down the progress of science.

19.6 Summary

This has been a bit of a fire-hose of different kinds of adjustments for FWER. Let’s step back and review these tests.

First we defined the concept of a contrast, which is a way of comparing groups of means to other groups of means. Then, if we assumed that we had m A Priori (pre-planned) contrasts, we covered three ways to adjust the p-value for FWER in increasing levels of power:

  1. Bonferroni correction
  2. Šidák correction
  3. Holm-Bonferroni multistage procedure

Bonferroni and Holm control familywise error without assuming independence. Holm’s step-down procedure rejects at least as many hypotheses as ordinary Bonferroni at the same familywise level. Šidák gives a cutoff close to Bonferroni’s, but its exact calibration follows from independence when all the null hypotheses are true.

We then covered three methods that protect specific families. With a designated control, the control comparisons are a subset of all pairs, and every pairwise comparison is a contrast:

  1. Dunnett: Compares one ‘reference’ mean to the m-1 remaining means
  2. Tukey: Compares each mean to every other mean.
  3. Scheffé: Protects the family of all possible contrasts among the means.

Which to use? As the number of possible tests go up, the severity of the correction goes up, so the power goes down. So you should use the test that is the most powerful that is consistent with your question. Do you have just one control condition to compare to the other means? Then use the Dunnett test, not any less powerful test if you don’t need to.

19.7 One contrast, five families

Let’s compare silence with classical music five ways. Note that the t statistic stays the same for all corrections. What changes is the family of comparisons for which we control the familywise error rate.

# The levels in emm are silence, white noise, rock, classical, and voices.
focus <- list("silence - classical music" = c(1, 0, 0, -1, 0))
planned <- c(focus, list("white noise - rock music" = c(0, 1, -1, 0, 0)))

single <- summary(contrast(emm, method = focus, adjust = "none"))
two_planned <- summary(contrast(emm, method = planned, adjust = "bonferroni"))
control <- summary(contrast(emm, method = "trt.vs.ctrl", ref = "silence",
                            adjust = "mvt"))
all_pairs <- summary(pairs(emm, adjust = "tukey"))
all_contrasts <- summary(contrast(emm, method = focus), adjust = "scheffe",
                         scheffe.rank = k - 1)
Family Adjustment adjusted p-value Bonferroni p-value
One planned contrast None 0.0263 0.0263
Two planned orthogonal contrasts Bonferroni 0.0527 0.0527
Four comparisons with silence as the control Dunnett 0.0851 0.1054
All ten pairs Tukey 0.1649 0.2635
All possible contrasts Scheffé 0.2776 —

Note: The em dash indicates that Bonferroni requires a finite family of comparisons; the family of all possible contrasts is infinite.

At \(\alpha=.05\), silence versus classical music is significant on its own (\(p=0.0263\)), but adding just one other planned contrast raises the Bonferroni-adjusted p-value to 0.0527, just above the significance threshold.

Dunnett reports classical music minus silence, which reverses the sign but gives the same two-sided p-value. Its four control comparisons could all have been planned in advance. For Scheffé, we set the rank to k - 1 because we’re protecting the full contrast space even though we display only one contrast.

Read across the Dunnett and Tukey rows to compare each method with Bonferroni for the same family: four comparisons against silence for Dunnett, and ten pairs for Tukey. Dunnett gives 0.0851 versus 0.1054, a reduction of about 19%. Tukey gives 0.1649 versus 0.2635, a reduction of about 37%. Neither reduction changes the decision at .05. Bonferroni multiplies the unadjusted p-value by the number of comparisons, capping the result at 1.

Compare the p-values down the table. A broader search generally calls for more protection, but the middle rows need not be ordered this way in every example. In particular, white noise versus rock music is in our planned set but isn’t a comparison against silence, so those two families aren’t nested. The question to ask is: If a different comparison had looked interesting, could we have reported it instead?

19.8 Conclusion

This chapter covers a few of the methods for controlling familywise error in planned and exploratory analyses. Statistics is a relatively new and developing field of mathematics, so the standards for these methods are in flux. Indeed, SPSS alone provides a confusing array of post-hoc methods and allows you to run many or all of them at once. It is clearly wrong to run a bunch of post-hoc comparisons and then pick the comparison that suits you. This sort of post hoc post hoc analysis can lead to a sort of meta-familywise error rate.

It’s also not OK to treat a post hoc comparison with an A Priori method. You can’t go back and say “Oh yeah, I meant to make that comparison” if it hadn’t crossed your mind.

In the end, all of these methods differ by relatively small amounts. If the significance of your comparisons depend on which specific A Priori or post hoc test you choose, then you’re probably taking the .05 or .01 criterion too seriously anyway.