Examples follow the book’s section numbers.
Chapter 5 takes up the multiple-comparisons problem: any time several tests are performed on the same data, the probability of at least one Type I error somewhere in the experiment exceeds the alpha level used for each single test. The chapter develops methods that control that experimentwise rate, and matches each method to the kind of question being asked — Bonferroni for a planned set of contrasts, Tukey’s HSD for all pairwise comparisons, Scheffé for complex contrasts chosen after seeing the data, Dunnett for comparisons against a control, Hsu’s modification of Dunnett for identifying the best treatment, and the false discovery rate as a different way of defining error control altogether. It closes by showing what each of these choices costs in statistical power.
These notes build on Chapters 1, 3, and 4; see Chapter 1 for how to
obtain the book’s data sets from the AMCP package and how
those data sets are named. Chapter 5 uses one of them,
chapter_5_table_4, the blood pressure data of Table
5.4.
# Load all of the packages used.
library(dplyr) # data manipulation
library(ggplot2) # figures
library(AMCP) # the textbook's data sets
library(DMAR) # design, measurement, and analysis
library(multcomp) # multiple-comparison procedures (glht)
library(gt) # polished HTML tables
library(modelsummary) # side-by-side model-comparison tablesThe book’s starting point is the four-treatment hypertension study with three orthogonal contrasts, each tested at . Equation 5.1 gives the probability of at least one Type I error across an orthogonal set of contrasts,
alpha_PC <- 0.05 # per-comparison alpha used for each single contrast
C <- 3 # number of orthogonal contrasts tested
# Equation 5.1.
alpha_EW <- 1 - (1 - alpha_PC)^C
alpha_EW[1] 0.142625
#> 0.1426 — the .143 reported on book p. 208
# Equation 5.7: the expected number of errors per experiment, ENEPE.
C * alpha_PC[1] 0.15
Three quantities that are easy to confuse have three different values here: the per-comparison rate is .05, the expected number of errors per experiment is .15, and the experimentwise rate is .143. Only one of them can be set to .05, and the book’s preference is to control . In single-factor designs and the familywise rate are identical, so this chapter works with throughout; the distinction between them waits until Chapter 7.
The figure below is a companion illustration of why the uncorrected rate is a problem: as the number of orthogonal contrasts grows, the probability of at least one spurious “significant” result climbs away from the nominal .05.
error_inflation <- data.frame(
C = 1:20,
alpha_EW = 1 - (1 - 0.05)^(1:20)
)
ggplot(error_inflation, aes(x = C, y = alpha_EW)) +
geom_hline(yintercept = 0.05, linetype = "dashed", colour = "#0C2340") +
annotate("text", x = 11, y = 0.10, label = "alpha[plain(PC)] == 0.05",
parse = TRUE, colour = "#0C2340") +
geom_line() +
geom_point() +
scale_y_continuous(limits = c(0, 1)) +
labs(x = expression("Number of orthogonal contrasts" ~ (italic(C))),
y = expression("Experimentwise error rate" ~ (alpha[plain(EW)])),
title = "Inflation of the experimentwise Type I error rate")Pushing the logic to its limit, the book quotes R. G. Miller’s “ultraconservative statistician” who treats every test of a lifetime — say 1,000 of them — as a single family. Equation 5.2 solves for the per-comparison alpha that such a statistician would need.
[1] 5.129198e-05
The price of that protection is power, which the next companion figure traces. Each point holds at .05 across tests and asks what power remains for a two-sample comparison with per group and a population standardized mean difference of .
C_values <- seq(1, 1000, by = 10)
# Equation 5.2 again: the per-comparison alpha that holds alpha_EW at .05.
alpha_PC_adjusted <- 1 - (1 - 0.05)^(1 / C_values)
power_values <- vapply(
alpha_PC_adjusted,
function(a) power.t.test(n = 64,
delta = 0.5,
sd = 1,
sig.level = a,
type = "two.sample",
alternative = "two.sided",
strict = TRUE)$power,
numeric(1)
)
# Power at C = 1, the uncorrected single-test benchmark.
power_values[1][1] 0.8014596
power_cost <- data.frame(C = C_values, power = power_values)
ggplot(power_cost, aes(x = C, y = power)) +
geom_hline(yintercept = power_values[1], linetype = "dashed",
colour = "#0C2340") +
annotate("text", x = 600, y = power_values[1] + 0.04,
label = "Power with no correction", colour = "#0C2340") +
geom_line(linewidth = 1) +
scale_y_continuous(limits = c(0, 0.9)) +
labs(x = expression("Number of tests" ~ (italic(C))),
y = "Power for a single contrast",
title = "The power cost of controlling a very large family")Every procedure in this chapter is built from one formula. Equation 5.3 writes a confidence interval for a contrast under homogeneity of variance as
and Equation 5.12 states the same thing in words: estimate (critical value)(estimated standard error). What separates Bonferroni from Tukey from Scheffé from Dunnett is only the critical value . So the estimate and its standard error are built once here, and each later section supplies its own .
data(chapter_5_table_4)
# Table 5.4 names the four groups, so each code is mapped to its treatment
# explicitly; factor() is then used only to fix the order of the levels.
blood_pressure <- chapter_5_table_4 |>
mutate(Treatment = case_when(
group == 1 ~ "Drug Therapy",
group == 2 ~ "Biofeedback",
group == 3 ~ "Diet",
group == 4 ~ "Combination"
)) |>
mutate(Treatment = factor(
Treatment,
levels = c("Drug Therapy", "Biofeedback", "Diet", "Combination")
))
blood_pressure group sbp Treatment
1 1 84 Drug Therapy
2 1 95 Drug Therapy
3 1 93 Drug Therapy
4 1 104 Drug Therapy
5 1 99 Drug Therapy
6 1 106 Drug Therapy
7 2 81 Biofeedback
8 2 84 Biofeedback
9 2 92 Biofeedback
10 2 101 Biofeedback
11 2 80 Biofeedback
12 2 108 Biofeedback
13 3 98 Diet
14 3 95 Diet
15 3 86 Diet
16 3 87 Diet
17 3 94 Diet
18 3 101 Diet
19 4 91 Combination
20 4 78 Combination
21 4 85 Combination
22 4 80 Combination
23 4 81 Combination
24 4 76 Combination
Summary_5_4 <- blood_pressure |>
group_by(Treatment) |>
summarize(mean = mean(sbp), sd = sd(sbp), s2 = var(sbp), n = n()) |>
as.data.frame()
Summary_5_4 Treatment mean sd s2 n
1 Drug Therapy 96.83333 8.035339 64.56667 6
2 Biofeedback 91.00000 11.489125 132.00000 6
3 Diet 93.50000 5.958188 35.50000 6
4 Combination 81.83333 5.419102 29.36667 6
The contrasts themselves are the point of the chapter, but the omnibus analysis supplies the pooled error term and its degrees of freedom, which every procedure that assumes homogeneity of variance uses.
ANOVA_Object <- aov(sbp ~ Treatment, data = blood_pressure)
ANOVA_Result <- anova(ANOVA_Object)
ANOVA_ResultAnalysis of Variance Table
Response: sbp
Df Sum Sq Mean Sq F value Pr(>F)
Treatment 3 744.79 248.264 3.7985 0.02637 *
Residuals 20 1307.17 65.358
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
[1] 65.35833
#> 65.358 — matches the error term printed beneath Table 5.7, book p. 228
df_between <- ANOVA_Result$"Df"[1]
df_error <- ANOVA_Result$"Df"[2]
c(df_between = df_between, df_error = df_error)df_between df_error
3 20
The book does not print the omnibus test for the Table 5.4 data, so only is checked against the printed page here; the remaining entries of the table follow from it.
This is a model-comparison text, so it is worth making the comparison behind that table explicit. The restricted model gives every participant the grand mean; the full model gives each treatment its own mean. The from comparing them is the omnibus above.
fit_restricted <- lm(sbp ~ 1, data = blood_pressure) # grand mean only
fit_full <- lm(sbp ~ Treatment, data = blood_pressure) # group means
anova(fit_restricted, fit_full)Analysis of Variance Table
Model 1: sbp ~ 1
Model 2: sbp ~ Treatment
Res.Df RSS Df Sum of Sq F Pr(>F)
1 23 2052.0
2 20 1307.2 3 744.79 3.7985 0.02637 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The same omnibus analysis as an APA-style table, built with
gt so the formatting carries over to HTML. The numbers
are exactly those in the anova() printout above.
anova_table <- data.frame(
Source = c("Treatment (between groups)", "Within (error)"),
SS = ANOVA_Result$"Sum Sq",
df = ANOVA_Result$"Df",
MS = ANOVA_Result$"Mean Sq",
Fstat = ANOVA_Result$"F value",
p = ANOVA_Result$"Pr(>F)"
)
# Partial eta-squared: the effect's share of effect-plus-error variance.
anova_table$peta <- c(
anova_table$SS[1] / (anova_table$SS[1] + anova_table$SS[2]),
NA_real_
)
anova_table |>
gt() |>
fmt_number(columns = c(SS, MS, Fstat), decimals = 2) |>
fmt_number(columns = peta, decimals = 3) |>
fmt_number(columns = p, decimals = 4) |>
sub_missing(missing_text = "") |>
cols_label(Fstat = md("*F*"), p = md("*p*"),
peta = md("Partial η<sup>2</sup>")) |>
tab_header(title = md("**Table 1**. Analysis of Variance for Systolic Blood Pressure")) |>
cols_align(align = "center", columns = -Source)| Table 1. Analysis of Variance for Systolic Blood Pressure | ||||||
| Source | SS | df | MS | F | p | Partial η2 |
|---|---|---|---|---|---|---|
| Treatment (between groups) | 744.79 | 3 | 248.26 | 3.80 | 0.0264 | 0.363 |
| Within (error) | 1,307.17 | 20 | 65.36 | |||
A side-by-side modelsummary table places the two models in adjacent columns, with standard errors in parentheses (APA style) and fit statistics at the foot:
modelsummary(
list("Grand mean" = fit_restricted, "Group means" = fit_full),
estimate = "{estimate}",
statistic = "({std.error})",
gof_map = c("nobs", "aic", "bic", "logLik"),
output = "gt"
)| Grand mean | Group means | |
|---|---|---|
| (Intercept) | 90.792 | 96.833 |
| (1.928) | (3.300) | |
| TreatmentBiofeedback | -5.833 | |
| (4.668) | ||
| TreatmentDiet | -3.333 | |
| (4.668) | ||
| TreatmentCombination | -15.000 | |
| (4.668) | ||
| Num.Obs. | 24 | 24 |
| AIC | 178.9 | 174.1 |
| BIC | 181.2 | 179.9 |
| Log.Lik. | -87.436 | -82.025 |
Choosing gives Equation 4.40 from Chapter 4, which controls confidence at the per-interval level rather than simultaneously. Note the numerator degrees of freedom: a contrast is a single-degree-of-freedom question, so , and the multiplier is equivalently a central quantile because .
CV_per_interval <- sqrt(qf(1 - 0.05, df1 = 1, df2 = df_error))
c(from_F = CV_per_interval, from_t = qt(1 - 0.05 / 2, df = df_error)) from_F from_t
2.085963 2.085963
#> 2.0860 both ways
per_interval <- do.call(rbind, lapply(
Contrasts, contrast_ci,
means = Summary_5_4$mean, n = Summary_5_4$n, MS_W = MS_W,
critical_value = CV_per_interval
))
per_interval psi_hat se lower upper
Drug - Biofeedback 5.833333 4.667559 -3.903025 15.569692
Drug - Diet 3.333333 4.667559 -6.403025 13.069692
Biofeedback - Diet -2.500000 4.667559 -12.236358 7.236358
Mean(1, 2, 3) - Combin 11.944444 3.811046 3.994741 19.894148
#> psi_hat 5.833, 3.333, -2.500, 11.944 and se 4.668, 4.668, 4.668, 3.811 —
#> match the "Assumes equal variances" rows of Table 5.5, book p. 221. The
#> book's fourth contrast was given to SPSS as 1, 1, 1, -3, so its printed
#> estimate (35.83) and standard error (11.4331) are three times these.DMAR’s ci_c() also gives the 95% interval for each
contrast from the group means, sample sizes, and pooled within-group
standard deviation.
ci_c(means = Summary_5_4$mean, s_anova = sqrt(MS_W), c_weights = C1,
n_per_group = Summary_5_4$n, N = sum(Summary_5_4$n), conf_level = 0.95)| term | value |
|---|---|
| ci_lower | -3.903 |
| contrast | 5.833 |
| ci_upper | 15.570 |
Confidence level: 95%
#> -3.903 to 15.570 — agrees with the hand computation.
# Collect all four contrasts in one table.
bind_rows(lapply(Contrasts, function(cw) {
fit <- ci_c(means = Summary_5_4$mean, s_anova = sqrt(MS_W),
c_weights = cw, n_per_group = Summary_5_4$n,
N = sum(Summary_5_4$n), conf_level = 0.95)
rows <- generics::tidy(fit)
tibble::tibble(estimate = rows$estimate[rows$term == "contrast"],
lower = rows$estimate[rows$term == "ci_lower"],
upper = rows$estimate[rows$term == "ci_upper"])
}), .id = "comparison")# A tibble: 4 × 4
comparison estimate lower upper
<chr> <dbl> <dbl> <dbl>
1 Drug - Biofeedback 5.83 -3.90 15.6
2 Drug - Diet 3.33 -6.40 13.1
3 Biofeedback - Diet -2.5 -12.2 7.24
4 Mean(1, 2, 3) - Combin 11.9 3.99 19.9
The Bonferroni adjustment sets . The book illustrates it with the strategy-training study: four groups, 11 participants per group, three planned contrasts, and an observed of 4.23 on 1 and 40 degrees of freedom.
[1] 0.01666667
#> 0.01667 — the .0167 of book p. 216
# Critical F without adjustment.
qf(1 - alpha_EW, df1 = 1, df2 = 40)[1] 4.084746
#> 4.0847 — the 4.08 of book p. 216
# Critical F with the Bonferroni adjustment. This is the single line of R the
# book itself prints on p. 217.
qf(1 - alpha_PC, df1 = 1, df2 = 40)[1] 6.24428
#> 6.2443 — the 6.24 of book pp. 216 and 217, so the observed F of 4.23 is
#> not significant once alpha_EW is controlled
# The matching critical t, since t^2 = F.
qt(1 - alpha_PC / 2, df = 40)[1] 2.498856
Equation 5.5 is an inequality, , so the actual experimentwise rate under the Bonferroni adjustment could in principle fall well below .05. Table 5.3 shows that for orthogonal contrasts it does not: the inequality is an equality for practical purposes, and the adjustment is therefore not conservative here.
C_values <- c(1, 2, 3, 4, 5, 10, 20, 50)
# Actual probability of at least one Type I error when each of C orthogonal
# contrasts is tested at .05/C.
data.frame(
C = C_values,
Actual_Probability = round(1 - (1 - (0.05 / C_values))^C_values, 6),
Bonferroni_Limit = 0.05
) C Actual_Probability Bonferroni_Limit
1 1 0.050000 0.05
2 2 0.049375 0.05
3 3 0.049171 0.05
4 4 0.049070 0.05
5 5 0.049010 0.05
6 10 0.048890 0.05
7 20 0.048830 0.05
8 50 0.048794 0.05
When the group variances are not pooled, the contrast’s standard error uses each group’s own variance (Equation 5.10) and its denominator degrees of freedom come from the Welch–Satterthwaite expression given as Equation 5.14 and in the footnote to Table 5.17. Both are written out below as functions of the -weights.
# Standard error of a contrast without pooling (Equations 5.10 and 5.11).
contrast_se_heterogeneous <- function(c_weights, s2, n) {
sqrt(sum(c_weights^2 * s2 / n))
}
# Denominator degrees of freedom for that standard error (Equation 5.14; the
# same expression appears as Chapter 4's Equation 4.34).
contrast_df_heterogeneous <- function(c_weights, s2, n) {
components <- c_weights^2 * s2 / n
sum(components)^2 / sum(components^2 / (n - 1))
}
se_heterogeneous <- vapply(Contrasts, contrast_se_heterogeneous, numeric(1),
s2 = Summary_5_4$s2, n = Summary_5_4$n)
df_heterogeneous <- vapply(Contrasts, contrast_df_heterogeneous, numeric(1),
s2 = Summary_5_4$s2, n = Summary_5_4$n)
round(rbind(se = se_heterogeneous, df = df_heterogeneous), 3) Drug - Biofeedback Drug - Diet Biofeedback - Diet Mean(1, 2, 3) - Combin
se 5.724 4.084 5.284 3.032
df 8.947 9.222 7.508 13.288
With the estimates and both kinds of standard error in hand, the tests at the top of Table 5.5 follow directly. The Bonferroni decision rule is to compare each value with , and only the fourth contrast clears it, whether or not homogeneity is assumed.
psi_hat <- vapply(Contrasts, function(cw) sum(cw * Summary_5_4$mean), numeric(1))
se_pooled <- vapply(Contrasts, function(cw) sqrt(MS_W * sum(cw^2 / Summary_5_4$n)),
numeric(1))
contrast_tests <- data.frame(
psi_hat = round(psi_hat, 3),
se_equal = round(se_pooled, 3),
t_equal = round(psi_hat / se_pooled, 3),
df_equal = df_error,
p_equal = round(2 * pt(-abs(psi_hat / se_pooled), df = df_error), 3),
se_unequal = round(se_heterogeneous, 3),
t_unequal = round(psi_hat / se_heterogeneous, 3),
df_unequal = round(df_heterogeneous, 3),
p_unequal = round(2 * pt(-abs(psi_hat / se_heterogeneous),
df = df_heterogeneous), 3)
)
contrast_tests psi_hat se_equal t_equal df_equal p_equal se_unequal
Drug - Biofeedback 5.833 4.668 1.250 20 0.226 5.724
Drug - Diet 3.333 4.668 0.714 20 0.483 4.084
Biofeedback - Diet -2.500 4.668 -0.536 20 0.598 5.284
Mean(1, 2, 3) - Combin 11.944 3.811 3.134 20 0.005 3.032
t_unequal df_unequal p_unequal
Drug - Biofeedback 1.019 8.947 0.335
Drug - Diet 0.816 9.222 0.435
Biofeedback - Diet -0.473 7.508 0.650
Mean(1, 2, 3) - Combin 3.940 13.288 0.002
For the Bonferroni method the critical value is with .
CV_bonferroni <- sqrt(qf(1 - 0.05 / 4, df1 = 1, df2 = df_error))
c(F_value = CV_bonferroni^2, CV = CV_bonferroni) F_value CV
7.531602 2.744376
#> F 7.5316 — the 7.53 of Table 5.5 (book p. 221) and the df = 20, C = 4
#> entry of Appendix Table A.3 (book p. 985); CV 2.7444
bonferroni_homogeneous <- do.call(rbind, lapply(
Contrasts, contrast_ci,
means = Summary_5_4$mean, n = Summary_5_4$n, MS_W = MS_W,
critical_value = CV_bonferroni
))
round(bonferroni_homogeneous, 2) psi_hat se lower upper
Drug - Biofeedback 5.83 4.67 -6.98 18.64
Drug - Diet 3.33 4.67 -9.48 16.14
Biofeedback - Diet -2.50 4.67 -15.31 10.31
Mean(1, 2, 3) - Combin 11.94 3.81 1.49 22.40
#> -6.98 to 18.64, -9.48 to 16.14, -15.31 to 10.31, 1.49 to 22.40 — matches
#> the upper half of Table 5.5, book p. 221, to roundingThe first two lower limits print as and where the book shows and . The difference is where the rounding happens, not in the method: Table 5.5 does the arithmetic from the rounded intermediate values it displays, , while the code above carries the unrounded critical value and standard error through to the end. Substituting the book’s own displayed values reproduces its printed endpoints exactly.
# The book's literal intermediate values for the first contrast.
5.8333 + c(-1, 1) * sqrt(7.53) * 4.6676[1] -6.974989 18.641589
Only the fourth interval excludes zero, which is the same conclusion the values gave: the combination treatment differs from the average of the three single treatments, and nothing else is established.
Equation 5.11 keeps the Bonferroni critical value but evaluates it at each contrast’s own heterogeneous degrees of freedom. Two versions are worth seeing. The first uses the exact, non-integer degrees of freedom, which is what the book recommends when a program is available (p. 222). The second rounds those degrees of freedom down to the integers that Appendix Table A.3 is indexed by, which is what produces the printed intervals.
contrast_ci_heterogeneous <- function(c_weights, means, s2, n, critical_value) {
psi_hat <- sum(c_weights * means)
se <- contrast_se_heterogeneous(c_weights, s2, n)
data.frame(
psi_hat = psi_hat,
se = se,
lower = psi_hat - critical_value * se,
upper = psi_hat + critical_value * se
)
}
# Exact (non-integer) denominator degrees of freedom.
CV_exact <- sqrt(qf(1 - 0.05 / 4, df1 = 1, df2 = df_heterogeneous))
round(CV_exact^2, 2) Drug - Biofeedback Drug - Diet Biofeedback - Diet
9.71 9.57 10.66
Mean(1, 2, 3) - Combin
8.33
bonferroni_exact_df <- do.call(rbind, Map(
function(cw, cv) contrast_ci_heterogeneous(
cw, Summary_5_4$mean, Summary_5_4$s2, Summary_5_4$n, cv),
Contrasts, CV_exact
))
round(bonferroni_exact_df, 2) psi_hat se lower upper
Drug - Biofeedback 5.83 5.72 -12.00 23.66
Drug - Diet 3.33 4.08 -9.30 15.97
Biofeedback - Diet -2.50 5.28 -19.75 14.75
Mean(1, 2, 3) - Combin 11.94 3.03 3.19 20.70
# Degrees of freedom rounded down, as the book's appendix tables require.
CV_table <- sqrt(qf(1 - 0.05 / 4, df1 = 1, df2 = floor(df_heterogeneous)))
round(CV_table^2, 2) Drug - Biofeedback Drug - Diet Biofeedback - Diet
10.28 9.68 11.12
Mean(1, 2, 3) - Combin
8.39
#> 10.28, 9.68, 11.12, 8.39 — match the critical F values shown in the lower
#> half of Table 5.5, book p. 221
bonferroni_table_df <- do.call(rbind, Map(
function(cw, cv) contrast_ci_heterogeneous(
cw, Summary_5_4$mean, Summary_5_4$s2, Summary_5_4$n, cv),
Contrasts, CV_table
))
round(bonferroni_table_df, 2) psi_hat se lower upper
Drug - Biofeedback 5.83 5.72 -12.52 24.18
Drug - Diet 3.33 4.08 -9.37 16.04
Biofeedback - Diet -2.50 5.28 -20.12 15.12
Mean(1, 2, 3) - Combin 11.94 3.03 3.16 20.73
#> -12.52 to 24.18, -9.37 to 16.04, -20.12 to 15.12, 3.16 to 20.73 — matches
#> the lower half of Table 5.5, book p. 221As the book notes on p. 223, relaxing homogeneity makes little practical difference in these data: two intervals widen appreciably, two narrow slightly, and the fourth contrast remains the only one that excludes zero.
The Bonferroni multiplier is a central- quantile at , and cv_t()
reports both of its tails. Passing to ci_c() as the confidence level
gives the simultaneous interval from the summary statistics.
| term | value | area_less | area_greater |
|---|---|---|---|
| lower_cv | -2.744 | 0.006 | 0.994 |
| upper_cv | 2.744 | 0.994 | 0.006 |
#> upper_cv 2.744 — the same multiplier as sqrt(qf(1 - .05/4, 1, 20)) above,
#> and the square root of the 7.53 in Appendix Table A.3 (book p. 985)
ci_c(means = Summary_5_4$mean, s_anova = sqrt(MS_W), c_weights = C1,
n_per_group = Summary_5_4$n, N = sum(Summary_5_4$n),
conf_level = 1 - 0.05 / 4)| term | value |
|---|---|
| ci_lower | -6.976 |
| contrast | 5.833 |
| ci_upper | 18.643 |
Confidence level: 98.75%
Tukey’s HSD judges every pairwise difference against the sampling distribution of the largest one. That distribution is the studentized range, written , and the critical value for an observed is ; equivalently an observed is compared with . Note that the familywise alpha is not split between the two tails here, because the studentized range is already a distribution of an absolute largest difference.
[1] 4
# Critical studentized range for the blood pressure data.
q_critical <- qtukey(p = 1 - 0.05, nmeans = a, df = df_error)
q_critical[1] 3.958293
#> 3.9583 — the df = 20, r = 4 entry of Appendix Table A.4, book p. 988
# On the t scale and on the F scale.
c(critical_t = q_critical / sqrt(2), critical_F = q_critical^2 / 2)critical_t critical_F
2.798936 7.834044
Table 5.6 sets the Tukey critical value beside the unadjusted and the Bonferroni critical values for all pairwise comparisons, holding at 12. For groups there are pairs, and that count is the the Bonferroni column uses.
groups <- 2:6
comparisons <- groups * (groups - 1) / 2
data.frame(
Number_of_Groups = groups,
Number_of_Comparisons = comparisons,
Per_Comparison = round(qf(1 - 0.05, df1 = 1, df2 = 12), 2),
Tukey = round(qtukey(1 - 0.05, nmeans = groups, df = 12)^2 / 2, 2),
Bonferroni = round(qf(1 - 0.05 / comparisons, df1 = 1, df2 = 12), 2)
) Number_of_Groups Number_of_Comparisons Per_Comparison Tukey Bonferroni
1 2 1 4.75 4.75 4.75
2 3 3 4.75 7.12 7.73
3 4 6 4.75 8.81 9.94
4 5 10 4.75 10.16 11.75
5 6 15 4.75 11.28 13.31
#> per-comparison 4.75 throughout; Tukey 4.75, 7.12, 8.81, 10.16, 11.28;
#> Bonferroni 4.75, 7.73, 9.94, 11.75, 13.31 — matches Table 5.6, book p. 225Whenever the Tukey critical value is smaller than the Bonferroni value, which is the sense in which Tukey’s HSD is the more powerful way to test all pairwise comparisons.
With unequal but pooled variances, Kramer’s modification simply computes each observed with the general unequal- formula and keeps the critical value. When variances are heterogeneous the book recommends Dunnett’s T3 for small samples, which compares the observed of Equation 5.13 — on the degrees of freedom of Equation 5.14 — with a critical value from the studentized maximum modulus distribution.
SPSS’s “Tamhane” option is Tamhane’s T2, the close relative of T3 that uses a Sidak-adjusted rather than the maximum modulus, and that is what the lower half of Table 5.7 reports. Both pieces are base R: a Welch standard error and degrees of freedom per pair, then a Sidak-adjusted quantile over the pairs.
pairs_index <- combn(a, 2)
pair_labels <- paste(levels(blood_pressure$Treatment)[pairs_index[1, ]],
levels(blood_pressure$Treatment)[pairs_index[2, ]],
sep = " - ")
g <- pairs_index[1, ]
h <- pairs_index[2, ]
difference <- Summary_5_4$mean[g] - Summary_5_4$mean[h]
# Equation 5.13, as a standard error rather than an F.
se_pair <- sqrt(Summary_5_4$s2[g] / Summary_5_4$n[g] +
Summary_5_4$s2[h] / Summary_5_4$n[h])
# Equation 5.14.
df_pair <- (Summary_5_4$s2[g] / Summary_5_4$n[g] +
Summary_5_4$s2[h] / Summary_5_4$n[h])^2 /
((Summary_5_4$s2[g] / Summary_5_4$n[g])^2 / (Summary_5_4$n[g] - 1) +
(Summary_5_4$s2[h] / Summary_5_4$n[h])^2 / (Summary_5_4$n[h] - 1))
C_pairwise <- a * (a - 1) / 2
alpha_sidak <- 1 - (1 - 0.05)^(1 / C_pairwise)
CV_tamhane <- qt(1 - alpha_sidak / 2, df = df_pair)
data.frame(
Comparison = pair_labels,
Difference = round(difference, 2),
Std_Error = round(se_pair, 3),
Sig = round(1 - (1 - 2 * pt(-abs(difference / se_pair), df = df_pair))^C_pairwise, 3),
Lower = round(difference - CV_tamhane * se_pair, 2),
Upper = round(difference + CV_tamhane * se_pair, 2)
) Comparison Difference Std_Error Sig Lower Upper
1 Drug Therapy - Biofeedback 5.83 5.724 0.913 -13.38 25.04
2 Drug Therapy - Diet 3.33 4.084 0.967 -10.26 16.93
3 Drug Therapy - Combination 15.00 3.957 0.027 1.65 28.35
4 Biofeedback - Diet -2.50 5.284 0.998 -21.17 16.17
5 Biofeedback - Combination 9.17 5.186 0.535 -9.49 27.83
6 Diet - Combination 11.67 3.288 0.032 0.91 22.42
#> differences 5.83, 3.33, 15.00, -2.50, 9.17, 11.67 with standard errors
#> 5.724, 4.084, 3.957, 5.284, 5.186, 3.288, significance values .913, .967,
#> .027, .998, .535, .032, and intervals -13.38 to 25.04, -10.26 to 16.93,
#> 1.65 to 28.35, -21.17 to 16.17, -9.49 to 27.83, 0.91 to 22.42 — all match
#> the Tamhane half of Table 5.7, book p. 228Relaxing homogeneity makes one more pairwise difference statistically significant here: the combination treatment is now distinguishable from diet as well as from drug therapy, exactly as the book reports on p. 227.
DMAR supplies the critical value that Dunnett’s T3 needs, through
cv_smm(). Its n_comparisons argument is the
number of pairs, and it can be checked against Appendix Table A.5, whose
columns are indexed by the number of groups.
| term | value | area_less | area_greater |
|---|---|---|---|
| upper_cv | 2.897 | 0.950 | 0.050 |
#> 2.897 — the df = 20, four-groups entry of Appendix Table A.5 (2.90),
#> book p. 989
cv_smm(alpha_level = 0.05, df = 8, n_comparisons = C_pairwise)| term | value | area_less | area_greater |
|---|---|---|---|
| upper_cv | 3.365 | 0.950 | 0.050 |
TukeyHSD() is base R and needs only the fitted
aov() object. It reports every pairwise difference with its
simultaneous interval and its adjusted value.
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = sbp ~ Treatment, data = blood_pressure)
$Treatment
diff lwr upr p adj
Biofeedback-Drug Therapy -5.833333 -18.89753 7.230868 0.6038383
Diet-Drug Therapy -3.333333 -16.39753 9.730868 0.8903064
Combination-Drug Therapy -15.000000 -28.06420 -1.935799 0.0208593
Diet-Biofeedback 2.500000 -10.56420 15.564201 0.9493084
Combination-Biofeedback -9.166667 -22.23087 3.897534 0.2345096
Combination-Diet -11.666667 -24.73087 1.397534 0.0905811
#> differences -5.833, -3.333, -15.000, 2.500, -9.167, -11.667 with intervals
#> -18.90 to 7.23, -16.40 to 9.73, -28.06 to -1.94, -10.56 to 15.56, -22.23
#> to 3.90, -24.73 to 1.40 and adjusted p .604, .890, .021, .949, .235, .091
#> — match the Tukey HSD half of Table 5.7, book p. 228. R subtracts the
#> earlier level from the later one, so each difference carries the opposite
#> sign from the book's (I) minus (J) row.Under the homogeneity assumption the only statistically significant pairwise difference is between drug therapy and the combination treatment. The interval runs from roughly 2 to 28 units, so although the combination therapy is confidently better, the data say little about by how much.
The same intervals as a figure. An interval that crosses the dashed line at zero leaves the direction of that difference unresolved.
tukey_df <- as.data.frame(Tukey_Result$Treatment)
tukey_df$Comparison <- factor(rownames(tukey_df),
levels = rev(rownames(tukey_df)))
ggplot(tukey_df, aes(x = diff, y = Comparison)) +
geom_vline(xintercept = 0, linetype = "dashed", colour = "#0C2340") +
geom_pointrange(aes(xmin = lwr, xmax = upr)) +
labs(x = "Difference in mean systolic blood pressure",
y = NULL,
title = "Tukey HSD 95% simultaneous confidence intervals")TukeyHSD() works from a fitted model;
ci_tukey_kramer() takes a response vector and a grouping
vector instead, and reports the studentized-range statistic for each
pair alongside the interval.
| contrast | mean_difference | se | q_statistic | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Biofeedback - Drug Therapy | -5.833 | 3.300 | -1.767 | -18.898 | 7.231 | 0.6038 |
| Diet - Drug Therapy | -3.333 | 3.300 | -1.010 | -16.398 | 9.731 | 0.8903 |
| Combination - Drug Therapy | -15.000 | 3.300 | -4.545 | -28.064 | -1.936 | 0.0209 |
| Diet - Biofeedback | 2.500 | 3.300 | 0.757 | -10.564 | 15.564 | 0.9493 |
| Combination - Biofeedback | -9.167 | 3.300 | -2.777 | -22.231 | 3.898 | 0.2345 |
| Combination - Diet | -11.667 | 3.300 | -3.535 | -24.731 | 1.398 | 0.0906 |
Confidence level: 95%, simultaneous interval (Tukey)
#> the same six differences, intervals, and adjusted p values as TukeyHSD()
#> above, hence the same agreement with Table 5.7, book p. 228
cv_tukey_hsd(alpha_level = 0.05, df = df_error, n_groups = a)| term | value | area_less | area_greater |
|---|---|---|---|
| upper_cv | 2.799 | 0.950 | 0.050 |
Scheffé’s method judges a contrast against the sampling distribution of the largest obtainable from any contrast, pairwise or complex. Because (Section 5.7.1), that distribution is times a central on and degrees of freedom, so the critical value of Equation 5.22 is . The price of being allowed to test infinitely many data-suggested contrasts is that this critical value is large.
# The illustration of book p. 232: a = 4 groups, so df numerator = 3, with
# df denominator = 30.
3 * qf(1 - 0.05, df1 = 3, df2 = 30)[1] 8.766832
Scheffé’s cost is fixed; Bonferroni’s grows with every contrast added. Table 5.8 shows where the two cross for and .
a_illustration <- 4
df_error_illustration <- 30
C_values <- 1:10
scheffe_cv <- (a_illustration - 1) *
qf(1 - 0.05, df1 = a_illustration - 1, df2 = df_error_illustration)
table_5_8 <- data.frame(
C = C_values,
Bonferroni = round(qf(1 - 0.05 / C_values, df1 = 1,
df2 = df_error_illustration), 2),
Scheffe = round(scheffe_cv, 2)
)
table_5_8 C Bonferroni Scheffe
1 1 4.17 8.77
2 2 5.57 8.77
3 3 6.43 8.77
4 4 7.06 8.77
5 5 7.56 8.77
6 6 7.98 8.77
7 7 8.34 8.77
8 8 8.65 8.77
9 9 8.93 8.77
10 10 9.18 8.77
#> Bonferroni 4.17, 5.57, 6.43, 7.06, 7.56, 7.98, 8.34, 8.65, 8.93, 9.18
#> against a constant Scheffé 8.77 — matches Table 5.8, book p. 232
# The largest C for which Bonferroni is still the smaller critical value.
max(table_5_8$C[table_5_8$Bonferroni < scheffe_cv])[1] 8
So up to eight planned contrasts can be tested with a smaller critical value under Bonferroni than under Scheffé. Only a researcher who might test more than eight, or who cannot specify the contrasts in advance, gains from Scheffé here. And for pairwise comparisons specifically, Tukey beats both.
The Brown–Forsythe separate-variances modification keeps the form of Equation 5.22 and substitutes the heterogeneous denominator degrees of freedom already computed in Section 5.5.2.
The same four contrasts are now treated as having been chosen after seeing the data, so Scheffé is the method of choice. Nothing about the estimates or their standard errors changes — only the critical value.
CV_scheffe <- sqrt(df_between * qf(1 - 0.05, df1 = df_between, df2 = df_error))
c(F_value = CV_scheffe^2, CV = CV_scheffe) F_value CV
9.295174 3.048799
#> F 9.2952 — the 9.30 shown in Table 5.10, book p. 234
scheffe_homogeneous <- do.call(rbind, lapply(
Contrasts, contrast_ci,
means = Summary_5_4$mean, n = Summary_5_4$n, MS_W = MS_W,
critical_value = CV_scheffe
))
round(scheffe_homogeneous, 2) psi_hat se lower upper
Drug - Biofeedback 5.83 4.67 -8.40 20.06
Drug - Diet 3.33 4.67 -10.90 17.56
Biofeedback - Diet -2.50 4.67 -16.73 11.73
Mean(1, 2, 3) - Combin 11.94 3.81 0.33 23.56
#> -8.40 to 20.06, -10.90 to 17.56, -16.73 to 11.73, 0.33 to 23.56 — matches
#> Table 5.10, book p. 234 (whose complex-contrast row, computed from the
#> rounded sqrt(9.30), prints as 0.32 to 23.57)Every Scheffé interval is wider than the corresponding Bonferroni interval of Section 5.5.3, which is what choosing contrasts post hoc costs. The conclusion is unchanged: only the complex contrast supports a confident statement of direction.
Without the homogeneity assumption, the critical value becomes on each contrast’s own degrees of freedom. As in Section 5.5.3 the book reads from an appendix table at integer degrees of freedom — its footnote to Table 5.10 spells this out, giving for the first contrast — so rounding the degrees of freedom down reproduces the printed values.
# Exact (non-integer) denominator degrees of freedom.
CV_scheffe_exact <- sqrt(df_between * qf(1 - 0.05, df1 = df_between,
df2 = df_heterogeneous))
round(CV_scheffe_exact^2, 2) Drug - Biofeedback Drug - Diet Biofeedback - Diet
11.62 11.47 12.58
Mean(1, 2, 3) - Combin
10.17
round(do.call(rbind, Map(
function(cw, cv) contrast_ci_heterogeneous(
cw, Summary_5_4$mean, Summary_5_4$s2, Summary_5_4$n, cv),
Contrasts, CV_scheffe_exact
)), 2) psi_hat se lower upper
Drug - Biofeedback 5.83 5.72 -13.67 25.34
Drug - Diet 3.33 4.08 -10.50 17.17
Biofeedback - Diet -2.50 5.28 -21.24 16.24
Mean(1, 2, 3) - Combin 11.94 3.03 2.28 21.61
# Degrees of freedom rounded down, as the book's appendix tables require.
CV_scheffe_table <- sqrt(df_between * qf(1 - 0.05, df1 = df_between,
df2 = floor(df_heterogeneous)))
round(CV_scheffe_table^2, 2) Drug - Biofeedback Drug - Diet Biofeedback - Diet
12.20 11.59 13.04
Mean(1, 2, 3) - Combin
10.23
#> 12.20, 11.59, 13.04, 10.23 — match the 12.21, 11.58, 13.05, 10.23 of
#> Table 5.10, book p. 234
round(do.call(rbind, Map(
function(cw, cv) contrast_ci_heterogeneous(
cw, Summary_5_4$mean, Summary_5_4$s2, Summary_5_4$n, cv),
Contrasts, CV_scheffe_table
)), 2) psi_hat se lower upper
Drug - Biofeedback 5.83 5.72 -14.16 25.82
Drug - Diet 3.33 4.08 -10.57 17.23
Biofeedback - Diet -2.50 5.28 -21.58 16.58
Mean(1, 2, 3) - Combin 11.94 3.03 2.25 21.64
#> -14.16 to 25.82, -10.57 to 17.23, -21.58 to 16.58, 2.25 to 21.64 —
#> the -14.17 to 25.83, -10.56 to 17.23, -21.59 to 16.59, 2.25 to 21.64 of
#> Table 5.10, book p. 234, to within the hundredth that the book's rounded
#> critical values and standard errors move the endpointscv_scheffe() returns the multiplier, and
ci_scheffe() builds the whole set of simultaneous intervals
from the raw data given a matrix whose columns are the -weights.
| term | value | area_less | area_greater |
|---|---|---|---|
| upper_cv | 2.961 | 0.950 | 0.050 |
#> 2.961 — its square, 8.77, is the Scheffé critical value of Table 5.8,
#> book p. 232
Contrast_Matrix <- do.call(cbind, Contrasts)
Contrast_Matrix Drug - Biofeedback Drug - Diet Biofeedback - Diet Mean(1, 2, 3) - Combin
[1,] 1 1 0 0.3333333
[2,] -1 0 1 0.3333333
[3,] 0 -1 -1 0.3333333
[4,] 0 0 0 -1.0000000
| contrast | estimate | se | F_value | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Drug - Biofeedback | 5.833 | 4.668 | 0.521 | -8.397 | 20.064 | 0.6730 |
| Drug - Diet | 3.333 | 4.668 | 0.170 | -10.897 | 17.564 | 0.9154 |
| Biofeedback - Diet | -2.500 | 4.668 | 0.096 | -16.730 | 11.730 | 0.9616 |
| Mean(1, 2, 3) - Combin | 11.944 | 3.811 | 3.274 | 0.325 | 23.564 | 0.0424 |
Confidence level: 95%, simultaneous interval (Scheffé)
When every test of interest compares one group with each of the other groups, Dunnett’s procedure exploits the correlation among those comparisons and so uses a smaller critical value than either Bonferroni or Tukey would.
Here the combination treatment plays the role of the control, and the
three single treatments are each compared with it. glht()
from multcomp
takes the fitted aov() object; its Dunnett contrasts are
formed against the first level of the factor, so the
combination treatment is released to that position first. The adjusted
values and simultaneous limits
are obtained by numerical integration over a multivariate , which involves random sampling, so the
seed is set on the page.
set.seed(113)
blood_pressure_control <- blood_pressure |>
mutate(Treatment = relevel(Treatment, ref = "Combination"))
ANOVA_Control <- aov(sbp ~ Treatment, data = blood_pressure_control)
Results_Dunnett <- glht(ANOVA_Control, linfct = mcp(Treatment = "Dunnett"))
summary(Results_Dunnett)
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Dunnett Contrasts
Fit: aov(formula = sbp ~ Treatment, data = blood_pressure_control)
Linear Hypotheses:
Estimate Std. Error t value Pr(>|t|)
Drug Therapy - Combination == 0 15.000 4.668 3.214 0.0117 *
Biofeedback - Combination == 0 9.167 4.668 1.964 0.1527
Diet - Combination == 0 11.667 4.668 2.500 0.0544 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Adjusted p values reported -- single-step method)
Simultaneous Confidence Intervals
Multiple Comparisons of Means: Dunnett Contrasts
Fit: aov(formula = sbp ~ Treatment, data = blood_pressure_control)
Quantile = 2.5391
95% family-wise confidence level
Linear Hypotheses:
Estimate lwr upr
Drug Therapy - Combination == 0 15.0000 3.1484 26.8516
Biofeedback - Combination == 0 9.1667 -2.6849 21.0183
Diet - Combination == 0 11.6667 -0.1849 23.5183
#> the drug-versus-combination interval runs from about 3 to 27, the
#> "approximately 3 to 27" of book p. 235 for Table 5.11The Dunnett intervals are narrower than the corresponding Tukey intervals of Table 5.7, which is the gain from giving up all comparisons among the three single treatments.
cv_dunnett() gives the critical value, which can be
checked against the book’s appendix. ci_dunnett() builds
the intervals from the raw data with the control named rather than
released, and evaluates the Dunnett quantile deterministically, so its
limits match the book’s SAS output to three decimals rather than to
simulation error.
| term | value | area_less | area_greater |
|---|---|---|---|
| upper_cv | 2.540 | 0.950 | 0.050 |
#> 2.540 — the df = 20, a = 4 entry of Appendix Table A.6 (book p. 990),
#> smaller than the Tukey critical t of 2.799
ci_dunnett(x = blood_pressure$sbp, group = blood_pressure$Treatment,
control = "Combination")| contrast | mean_difference | se | t_value | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Drug Therapy - Combination | 15.000 | 4.668 | 3.214 | 3.143 | 26.857 | 0.0117 |
| Biofeedback - Combination | 9.167 | 4.668 | 1.964 | -2.691 | 21.024 | 0.1528 |
| Diet - Combination | 11.667 | 4.668 | 2.500 | -0.191 | 23.524 | 0.0544 |
Confidence level: 95%, simultaneous interval (Dunnett)
Hsu’s procedure answers a different question: which treatment is best? It reuses the Dunnett critical value, but the group that plays the role of the control is not known before the data are seen — it is the group with the most desirable sample mean. For blood pressure, low is best.
The steps are those in the lower half of Table 5.12. Identify the group with the smallest sample mean, form two-sided Dunnett intervals comparing every other group with it, and then obtain an interval for the best-looking group itself by reversing the signs of the limits of the interval for the group with the second smallest mean.
group_means <- Summary_5_4$mean
names(group_means) <- as.character(Summary_5_4$Treatment)
sort(group_means) Combination Biofeedback Diet Drug Therapy
81.83333 91.00000 93.50000 96.83333
[1] "Combination"
#> Combination, with a mean of 81.83 — matches book p. 242
second_best <- names(sort(group_means))[2]
second_best[1] "Biofeedback"
#> Biofeedback, with a mean of 91.00 — matches book p. 242
Unconstrained <- ci_dunnett(x = blood_pressure$sbp,
group = blood_pressure$Treatment,
control = best_group)
Unconstrained| contrast | mean_difference | se | t_value | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Drug Therapy - Combination | 15.000 | 4.668 | 3.214 | 3.143 | 26.857 | 0.0117 |
| Biofeedback - Combination | 9.167 | 4.668 | 1.964 | -2.691 | 21.024 | 0.1528 |
| Diet - Combination | 11.667 | 4.668 | 2.500 | -0.191 | 23.524 | 0.0544 |
Confidence level: 95%, simultaneous interval (Dunnett)
# Step 5: reverse the signs of the second-best group's limits to obtain an
# interval for the group with the smallest mean.
unconstrained_frame <- as.data.frame(Unconstrained)
second_row <- grep(second_best, unconstrained_frame$contrast)
round(-rev(c(unconstrained_frame$ci_lower[second_row],
unconstrained_frame$ci_upper[second_row])), 3)[1] -21.024 2.691
That interval contains zero, so biofeedback, diet, and the combination treatment all remain candidates for best; only drug therapy is ruled out. The book’s reading of the same numbers is that the combination therapy is at most 2.69 units worse than whichever treatment is truly best, while biofeedback and diet could be as much as 21.02 and 23.52 units worse.
If there is no interest in estimating by how much the best treatment is best, the constrained intervals of Table 5.13 are available instead: one-sided Dunnett upper limits, one-sided lower limits, and then a lower limit of zero substituted wherever the one-sided lower limit came out positive.
Upper_Limits <- ci_dunnett(x = blood_pressure$sbp,
group = blood_pressure$Treatment,
control = best_group, alternative = "less")
Upper_Limits| contrast | mean_difference | se | t_value | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Drug Therapy - Combination | 15.000 | 4.668 | 3.214 | -Inf | 25.233 | 0.9999 |
| Biofeedback - Combination | 9.167 | 4.668 | 1.964 | -Inf | 19.399 | 0.9971 |
| Diet - Combination | 11.667 | 4.668 | 2.500 | -Inf | 21.899 | 0.9994 |
Confidence level: 95%, simultaneous interval (Dunnett)
#> upper limits 25.233 for drug, 19.399 for biofeedback, and 21.899 for diet
#> — match the "Upper Limits" panel of Table 5.15, book p. 243
Lower_Limits <- ci_dunnett(x = blood_pressure$sbp,
group = blood_pressure$Treatment,
control = best_group, alternative = "greater")
Lower_Limits| contrast | mean_difference | se | t_value | ci_lower | ci_upper | p_adjusted |
|---|---|---|---|---|---|---|
| Drug Therapy - Combination | 15.000 | 4.668 | 3.214 | 4.767 | Inf | 0.0059 |
| Biofeedback - Combination | 9.167 | 4.668 | 1.964 | -1.066 | Inf | 0.0765 |
| Diet - Combination | 11.667 | 4.668 | 2.500 | 1.434 | Inf | 0.0272 |
Confidence level: 95%, simultaneous interval (Dunnett)
#> lower limits 4.767, -1.066, and 1.434 in the same order — match the
#> "Lower Limits" panel of Table 5.15, book p. 243upper <- as.data.frame(Upper_Limits)
lower <- as.data.frame(Lower_Limits)
# Step 4: a positive one-sided lower limit becomes a lower limit of zero.
final_limits <- data.frame(
Group = sub(paste0(" - ", best_group), "", upper$contrast),
Lower = pmin(lower$ci_lower, 0),
Upper = upper$ci_upper
)
# Step 5: the interval for the group with the smallest mean, from the
# second-smallest group's reversed limits.
second_row <- grep(second_best, final_limits$Group)
final_limits <- rbind(
final_limits,
data.frame(Group = best_group,
Lower = -final_limits$Upper[second_row],
Upper = -final_limits$Lower[second_row])
)
final_limits[, c("Lower", "Upper")] <- round(final_limits[, c("Lower", "Upper")], 2)
final_limits Group Lower Upper
1 Drug Therapy 0.00 25.23
2 Biofeedback -1.07 19.40
3 Diet 0.00 21.90
4 Combination -19.40 1.07
#> drug 0.00 to 25.23, biofeedback -1.07 to 19.40, diet 0.00 to 21.90, and
#> combination -19.40 to 1.07 — match the final limits of Table 5.15,
#> book p. 243Both the combination and the biofeedback intervals contain zero, so one of those two is the best treatment with 95% confidence. The constrained intervals rule out more treatments than the unconstrained ones did, at the cost of saying nothing about how much better the best treatment is.
Fisher’s LSD tests the omnibus hypothesis first and, if it is rejected, tests individual contrasts at . The book’s objection is that the omnibus test protects only the complete null hypothesis. Its illustration (p. 244) imagines eleven groups of which ten share a common population mean: the omnibus test is then rejected almost always, after which the ten identical groups receive no protection at all, and the probability of at least one spurious difference among them is given as approximately .60 rather than .05.
The companion simulation below puts numbers on that second stage directly: ten groups drawn from one population, all 45 pairwise comparisons tested at against the pooled error term. The book states the approximate value without fixing a sample size, so the figure below is an illustration of the magnitude rather than a reproduction of a printed quantity.
set.seed(113)
n_replications <- 2000
groups_identical <- 10
n_per_group <- 10
df_error_lsd <- groups_identical * (n_per_group - 1)
pairs_lsd <- combn(groups_identical, 2)
critical_t <- qt(1 - 0.05 / 2, df = df_error_lsd)
any_significant <- replicate(n_replications, {
y <- matrix(rnorm(groups_identical * n_per_group), ncol = groups_identical)
mean_j <- colMeans(y)
MS_W_j <- mean(apply(y, 2, var))
t_obs <- abs(mean_j[pairs_lsd[1, ]] - mean_j[pairs_lsd[2, ]]) /
sqrt(MS_W_j * 2 / n_per_group)
any(t_obs > critical_t)
})
c(number_of_pairs = ncol(pairs_lsd), rate = mean(any_significant))number_of_pairs rate
45.0000 0.6175
The rate is an order of magnitude above .05 and in the neighbourhood of the .60 the book reports, which is the point: the second stage of the LSD leaves the true part of a partially true null hypothesis unprotected.
Benjamini and Hochberg’s Linear Step Up (LSU) procedure compares the ordered values with a sliding scale of critical values . The book works an example with and the values .029, .026, .167, .048, and .001 (p. 248).
p_raw <- c(.029, .026, .167, .048, .001)
m <- length(p_raw)
alpha_FDR <- 0.05
p_sorted <- sort(p_raw)
i <- 1:m
critical_value <- (i / m) * alpha_FDR
data.frame(
Rank_i = i,
P_Value = p_sorted,
Critical_Value = critical_value,
Below_Critical = p_sorted < critical_value
) Rank_i P_Value Critical_Value Below_Critical
1 1 0.001 0.01 TRUE
2 2 0.026 0.02 FALSE
3 3 0.029 0.03 TRUE
4 4 0.048 0.04 FALSE
5 5 0.167 0.05 FALSE
# Step 4: k is the largest rank whose p value falls below its critical value.
k <- max(i[p_sorted < critical_value])
k[1] 3
Reading the table from the bottom up, as the procedure prescribes: .167 is not below .05, .048 is not below .040, and .029 is below .030, so and testing stops. Step 5 then rejects every hypothesis of rank 3 or lower — the second-ranked value of .026 is rejected too, even though it is not itself below its own critical value of .020. That is why the last column above is labelled by what it compares rather than by a decision.
p.adjust()The LSU procedure is exactly the Benjamini–Hochberg adjustment, which
base R implements directly. DMAR does not re-wrap it, so
p.adjust() is the route to adjusted values for a reader who wants them
rather than a step-up table.
[1] 0.04833333 0.04833333 0.16700000 0.06000000 0.00500000
[1] 3
Nothing about a contrast’s observed changes when other contrasts are tested alongside it. What changes is the critical value, and therefore the power. Section 5.11 computes that power from first principles, and the book prints the R code that does it (p. 253). The planning scenario is a follow-up to the Kroes et al. electroconvulsive therapy study: three groups with presumed means of 25, 34, and 37, a population standard deviation of 12, and 25 participants per group.
a_power <- 3
n_power <- 25
N_total <- a_power * n_power
sigma <- 12
alpha_EW <- 0.05
mu <- c(A = 25, B = 34, C = 37)
# Equation 4.56 for f-squared, then Equation 4.49 for the noncentrality
# parameter lambda.
noncentrality <- function(psi, sum_c_squared) {
f_squared <- psi^2 / (a_power * sigma^2 * sum_c_squared)
N_total * f_squared
}
planned_contrasts <- list(
"A vs B" = list(psi = mu["A"] - mu["B"], sum_c_squared = 2),
"A vs C" = list(psi = mu["A"] - mu["C"], sum_c_squared = 2),
"B vs C" = list(psi = mu["B"] - mu["C"], sum_c_squared = 2),
"A vs B and C" = list(psi = mu["A"] - mean(mu[c("B", "C")]),
sum_c_squared = 1 + 0.25 + 0.25)
)
lambda <- vapply(planned_contrasts,
function(z) noncentrality(z$psi, z$sum_c_squared),
numeric(1))
round(lambda, 2) A vs B A vs C B vs C A vs B and C
7.03 12.50 0.78 12.76
#> 7.03, 12.50, 0.78, 12.76 — match the Lambda rows of Tables 5.18, 5.19,
#> and 5.20, book pp. 254 and 255The three critical values are the ones developed earlier in the chapter, now evaluated for this design. Only Bonferroni’s depends on .
CV_bonferroni_power <- function(C) qf(1 - alpha_EW / C, df1 = 1,
df2 = N_total - a_power)
CV_tukey_power <- qtukey(1 - alpha_EW, nmeans = a_power,
df = N_total - a_power)^2 / 2
CV_scheffe_power <- (a_power - 1) * qf(1 - alpha_EW, df1 = a_power - 1,
df2 = N_total - a_power)
round(c(Bonferroni_C2 = CV_bonferroni_power(2),
Bonferroni_C3 = CV_bonferroni_power(3),
Bonferroni_C4 = CV_bonferroni_power(4),
Tukey = CV_tukey_power,
Scheffe = CV_scheffe_power), 2)Bonferroni_C2 Bonferroni_C3 Bonferroni_C4 Tukey Scheffe
5.24 6.01 6.56 5.73 6.25
#> 5.24, 6.01, 6.56, 5.73, 6.25 — match the critical values of Tables 5.18,
#> 5.19, and 5.20, book pp. 254 and 255
# Power is the probability that a noncentral F exceeds the critical value.
power_contrast <- function(critical_value, lambda) {
1 - pf(critical_value, df1 = 1, df2 = N_total - a_power, ncp = lambda)
}
power_table <- function(which_contrasts, C, tukey = TRUE) {
l <- lambda[which_contrasts]
cv <- CV_bonferroni_power(C)
out <- rbind(
Lambda = round(l, 2),
"CV for Bonferroni" = round(cv, 2),
"Power for Bonferroni" = round(power_contrast(cv, l), 2),
"CV for Tukey" = if (tukey) round(CV_tukey_power, 2) else NA,
"Power for Tukey" = if (tukey) round(power_contrast(CV_tukey_power, l), 2) else NA,
"CV for Scheffe" = round(CV_scheffe_power, 2),
"Power for Scheffe" = round(power_contrast(CV_scheffe_power, l), 2)
)
colnames(out) <- which_contrasts
out
} A vs B A vs C
Lambda 7.03 12.50
CV for Bonferroni 5.24 5.24
Power for Bonferroni 0.64 0.89
CV for Tukey 5.73 5.73
Power for Tukey 0.60 0.87
CV for Scheffe 6.25 6.25
Power for Scheffe 0.56 0.85
#> Bonferroni power .64 and .89, Tukey .60 and .87, Scheffé .56 and .85 —
#> matches Table 5.18, book p. 254With only two planned pairwise comparisons the Bonferroni critical value is the smallest of the three, so Bonferroni gives the most power. Power for the Group A versus Group C comparison is good; power for Group A versus Group B is marginal at best.
A vs B A vs C B vs C
Lambda 7.03 12.50 0.78
CV for Bonferroni 6.01 6.01 6.01
Power for Bonferroni 0.58 0.86 0.06
CV for Tukey 5.73 5.73 5.73
Power for Tukey 0.60 0.87 0.07
CV for Scheffe 6.25 6.25 6.25
Power for Scheffe 0.56 0.85 0.06
#> Bonferroni power .58, .86, .06, Tukey .60, .87, .07, Scheffé .56, .85, .06
#> — matches Table 5.19, book p. 254Three things change. Power for Groups B versus C is dismal, because their mean difference corresponds to a standardized mean difference of only . Tukey now beats Bonferroni, because has risen to 3 while the Tukey critical value does not depend on . And the Tukey and Scheffé columns are identical to those in Table 5.18 for exactly that reason.
A vs B A vs C B vs C A vs B and C
Lambda 7.03 12.50 0.78 12.76
CV for Bonferroni 6.56 6.56 6.56 6.56
Power for Bonferroni 0.54 0.83 0.05 0.84
CV for Tukey NA NA NA NA
Power for Tukey NA NA NA NA
CV for Scheffe 6.25 6.25 6.25 6.25
Power for Scheffe 0.56 0.85 0.06 0.86
#> Bonferroni power .54, .83, .05, .84 and Scheffé .56, .85, .06, .86 —
#> matches Table 5.20, book p. 255. Tukey is not applicable once a complex
#> contrast is tested, which is why the book prints N/A in those rows.The complex contrast has the largest noncentrality parameter and so the largest power. Bonferroni’s critical value has risen again with , and Scheffé is now the better choice — and it would be the only legitimate choice had these four contrasts been chosen after looking at the data.
Every power value above is individual power: the probability that one particular contrast reaches significance. Section 5.11 also distinguishes complete power (all false null hypotheses rejected, also called all-pairs power), minimal power (at least one rejected, also called any-pairs power), and proportional power (the expected proportion of false null hypotheses rejected). Complete and minimal power have no textbook closed form, so the book obtains them by simulation, and Table 5.21 reports the results of 10,000 replications of a SAS macro.
The scenario is a Solomon four-group design with 30 participants per condition, population means of 54, 54, 46, and 46, a population standard deviation of 10, and Tukey’s method controlling at .05. Two of the six pairwise comparisons are true null hypotheses; power concerns only the other four.
The book does not print code for this table, and no function in base R or in DMAR computes these three quantities, so this is a place where following along means building the calculation. We do it twice: first by simulation, the way the book does, and then exactly, which this particular design turns out to allow. The second route is what makes the first one interpretable.
set.seed(113)
n_replications <- 10000 # the same number of replications the book used
n_per_group <- 30
mu_solomon <- c(54, 54, 46, 46)
sigma_solomon <- 10
group_solomon <- factor(rep(1:4, each = n_per_group))
# The four false null hypotheses are the high-versus-low pairs.
false_nulls <- c("3-1", "4-1", "3-2", "4-2")
simulation <- t(replicate(n_replications, {
y <- rnorm(length(group_solomon),
mean = rep(mu_solomon, each = n_per_group),
sd = sigma_solomon)
p_adjusted <- TukeyHSD(aov(y ~ group_solomon))$group_solomon[, "p adj"]
rejected <- p_adjusted[false_nulls] < 0.05
c(complete = all(rejected), minimal = any(rejected),
proportional = mean(rejected))
}))
estimates <- colMeans(simulation)
round(estimates, 4) complete minimal proportional
0.3620 0.9333 0.6824
#> .3620, .9333, .6824; Table 5.21 prints .35930, .94620, and .68773,
#> book p. 256
# A simulated power is an estimate, so it has a standard error. Report it.
# Complete and minimal power are proportions, so theirs is the binomial
# sqrt(p(1 - p)/reps). Proportional power is not a proportion: each replication
# contributes 0, .25, .5, .75 or 1, so the binomial formula overstates it by
# half. The column standard deviation is right for all three.
round(apply(simulation, 2, sd) / sqrt(n_replications), 4) complete minimal proportional
0.0048 0.0025 0.0030
#> .0048, .0025, .0030 — the Monte Carlo standard errors of the three
#> estimates above. The .0030 is worth noting: it matches the .00296 spread
#> that 2,000 independent runs of this simulation show below, which is the
#> check that the formula is the right one.Table 5.21 reports .35930 for complete power with a simulation interval of .350 to .369, .94620 for minimal power with an interval of .942 to .951, and .68773 for proportional power with an interval of .682 to .694 (book p. 256). Complete power and proportional power from the run above fall inside those intervals. Minimal power does not: it comes out about .013 lower than the book’s figure.
It is tempting to read that as a discrepancy between SAS and R and go looking for a difference in how the Tukey decision is made. The Monte Carlo standard errors printed above suggest a prior question. Both figures are estimates from 10,000 replications, and the standard error of such an estimate is about .0024. How much of the third decimal can one run of this size actually support? The rest of this section answers that, and the answer makes the two published figures easier to understand than any difference in software would.
Answering that question means running the whole study many times over, and the chunk above is too slow for that: it builds 10,000 data sets of 120 observations and fits 10,000 analyses of variance. Almost none of that work is needed. In a balanced one-way design the group means and are sufficient for every pairwise comparison, so the group means can be drawn straight from their sampling distribution, , and straight from its scaled chi-square distribution, independently of them. Tukey’s rule then rejects a pair when the absolute difference of two drawn means exceeds . It is the same experiment, simulated at the level of its sufficient statistics rather than observation by observation, and it runs about a thousand times faster.
# Complete, minimal, and proportional power for a balanced one-way design,
# simulated from the sufficient statistics. The procedure argument supplies
# the critical value on the mean-difference scale, in units of
# sqrt(MS_within / n), so "bonferroni" and "scheffe" are available too.
mcp_power <- function(means, n, sigma, alpha = 0.05,
procedure = c("tukey", "bonferroni", "scheffe", "none"),
reps = 10000) {
procedure <- match.arg(procedure)
a <- length(means)
df_within <- a * (n - 1)
pairs <- combn(a, 2, simplify = FALSE)
false_null <- Filter(function(p) means[p[1]] != means[p[2]], pairs)
true_null <- Filter(function(p) means[p[1]] == means[p[2]], pairs)
critical <- switch(procedure,
tukey = qtukey(1 - alpha, nmeans = a, df = df_within),
bonferroni = sqrt(2) * qt(1 - alpha / (2 * length(pairs)), df = df_within),
scheffe = sqrt(2 * (a - 1) * qf(1 - alpha, df1 = a - 1, df2 = df_within)),
none = sqrt(2) * qt(1 - alpha / 2, df = df_within))
# One row per replication: the group means, plus that run's own MS_within.
means_sim <- matrix(rnorm(reps * a, mean = rep(means, each = reps),
sd = sigma / sqrt(n)),
nrow = reps, ncol = a)
MS_within <- sigma^2 * rchisq(reps, df = df_within) / df_within
threshold <- critical * sqrt(MS_within / n)
n_rejected <- integer(reps)
for (p in false_null)
n_rejected <- n_rejected +
(abs(means_sim[, p[1]] - means_sim[, p[2]]) > threshold)
any_true_rejected <- rep(FALSE, reps)
for (p in true_null)
any_true_rejected <- any_true_rejected |
(abs(means_sim[, p[1]] - means_sim[, p[2]]) > threshold)
estimate <- c(complete = mean(n_rejected == length(false_null)),
minimal = mean(n_rejected > 0),
proportional = mean(n_rejected) / length(false_null),
true_FWE = mean(any_true_rejected))
# If every population mean is the same there is no false null hypothesis to
# reject, so the three power quantities are undefined rather than 1, 0, and
# 0/0. The familywise error rate in the last row is still exactly the
# quantity one wants in that case.
if (length(false_null) == 0)
estimate[c("complete", "minimal", "proportional")] <- NA_real_
# The Monte Carlo standard error of a mean is the standard deviation of the
# quantity being averaged over the square root of the number of replications.
# For complete, minimal and the familywise rate that reduces to the binomial
# formula; for proportional power, which averages 0, .25, .5, .75 and 1, it
# does not, and the binomial formula would overstate it.
mc_se <- c(complete = stats::sd(n_rejected == length(false_null)),
minimal = stats::sd(n_rejected > 0),
proportional = stats::sd(n_rejected / max(1, length(false_null))),
true_FWE = stats::sd(any_true_rejected)) / sqrt(reps)
if (length(false_null) == 0)
mc_se[c("complete", "minimal", "proportional")] <- NA_real_
data.frame(quantity = names(estimate),
estimate = unname(estimate),
MC_SE = unname(mc_se))
}
set.seed(113)
mcp_power(means = mu_solomon, n = n_per_group, sigma = sigma_solomon,
procedure = "tukey", reps = n_replications) quantity estimate MC_SE
1 complete 0.37190 0.004833361
2 minimal 0.93790 0.002413492
3 proportional 0.69005 0.003023700
4 true_FWE 0.02090 0.001430568
Three sets of numbers are now in hand for one scenario: the book’s .35930, .94620, .68773; the raw-data run’s .3620, .9333, .6824; and this run’s .37190, .93790, .69005. They are three estimates of the same three quantities, differing only in the random stream each used. The fourth row is a bonus the book’s table does not report — the proportion of replications in which at least one of the two true null hypotheses was rejected, about .021, which is Tukey’s method being conservative, as it is designed to be.
Complete and minimal power have no general closed form, which is why the book simulates. For this scenario they can nonetheless be computed exactly, because the design is balanced and the four population means take only two values. Work in units of the standard error of a group mean, , and condition on , so that the rejection threshold is a fixed number . Condition also on the two low-group means. A high-group mean then rejects against both of them when a single standard normal variable lands below the smaller or above the larger — or, should the two low means happen to lie more than apart, in the gap between them — and it rejects against neither when it lands in the overlap of the two acceptance windows, which is non-empty exactly when the two low means lie closer than . Each window is a difference of two normal distribution functions. The two high-group means are independent and carry the same two probabilities, so the chance that all four false null hypotheses are rejected is the first probability squared, and one minus the square of the second is minimal power. Averaging over the two low-group means and over leaves a three-fold integral, and because each integrand is smooth and bounded, an equal-probability grid evaluates it to more decimal places than anyone needs.
# Exact complete, minimal, and proportional power by quadrature, for the
# pattern of this scenario: four groups, two at a high mean and two at a low
# one, balanced, Tukey at alpha. No simulation and so no Monte Carlo error;
# the only error is the grid's, which is past the fourth decimal here.
exact_mcp <- function(means, n, sigma, alpha = 0.05,
n_grid_MS = 400, n_grid_mean = 320) {
a <- length(means)
stopifnot(a == 4, length(unique(means)) == 2,
sum(means == max(means)) == 2)
df_within <- a * (n - 1)
SE_mean <- sigma / sqrt(n)
critical <- qtukey(1 - alpha, nmeans = a, df = df_within)
# MS_within / sigma^2 on an equal-probability grid of its chi-square law,
# turned into the Tukey threshold in units of the standard error of a mean.
MS_scaled <- qchisq((seq_len(n_grid_MS) - 0.5) / n_grid_MS,
df = df_within) / df_within
tau <- critical * sqrt(MS_scaled)
delta <- diff(range(means)) / SE_mean # mean separation, same units
# The two low-group means, also on an equal-probability grid.
z <- qnorm((seq_len(n_grid_mean) - 0.5) / n_grid_mean)
upper <- outer(z, z, pmax)
lower <- outer(z, z, pmin)
by_threshold <- vapply(tau, function(t) {
hi <- t - delta # how far a high-group mean must sit above the larger one
lo <- t + delta # and how far below the smaller one, to reject
# The window strictly between the two low means and the window in which
# neither comparison rejects are the two signs of one difference: whichever
# is non-empty, the other is not.
between <- pnorm(upper - lo) - pnorm(lower + hi)
reject_both <- pnorm(lower - lo) + pnorm(upper + hi, lower.tail = FALSE) +
pmax(0, between)
reject_neither <- pmax(0, -between)
c(complete = mean(reject_both^2),
nothing = mean(reject_neither^2),
proportional = pnorm(hi / sqrt(2), lower.tail = FALSE) +
pnorm(-lo / sqrt(2)),
true_FWE = 1 - (1 - 2 * pnorm(t / sqrt(2), lower.tail = FALSE))^2)
}, numeric(4))
c(complete = mean(by_threshold["complete", ]),
minimal = 1 - mean(by_threshold["nothing", ]),
proportional = mean(by_threshold["proportional", ]),
true_FWE = mean(by_threshold["true_FWE", ]))
}
exact_solomon <- exact_mcp(means = mu_solomon, n = n_per_group,
sigma = sigma_solomon)
round(exact_solomon, 4) complete minimal proportional true_FWE
0.3655 0.9405 0.6880 0.0205
#> complete .3655, minimal .9405, proportional .6880, true familywise error
#> rate .0205 — the exact counterparts of the three simulated values in
#> Table 5.21, book p. 256Proportional power needs no grid at all, and it is worth seeing why. It is the expected proportion of the four false null hypotheses rejected, which by linearity of expectation is just the individual power of one such comparison. A single mean difference divided by its estimated standard error follows a noncentral distribution, and Tukey’s rule compares it to , so one line of base R settles it.
# Individual power of one high-versus-low comparison under Tukey's rule, with
# df = 4 * (30 - 1) = 116 and ncp = 8 / sqrt(2 * sigma^2 / n).
1 - diff(pt(c(-1, 1) * qtukey(0.95, nmeans = 4, df = 116) / sqrt(2),
df = 116, ncp = 8 / sqrt(2 * 100 / 30)))[1] 0.6880257
With exact values in hand the earlier numbers can be placed. The exact minimal power is .9405. The book’s run returned .94620, which is 2.4 Monte Carlo standard errors above it — far enough that Table 5.21’s own interval for minimal power, (.942, .951), does not reach down to the value it brackets. That is not a flaw in the table: an interval of that kind misses about one time in twenty, and this is one of those times. The raw-data run at the top of this section returned .9333, which is 3.0 standard errors below the exact value and well out in the other tail — a run lands that low only about once in several hundred tries — but a tail is part of a distribution, not evidence of a different method. The way to see the distribution both figures come from is to run the whole 10,000-replication study over and over, which the sufficient-statistic version makes cheap enough to do on this page.
set.seed(113)
# Two thousand independent repetitions of the book's 10,000-replication study:
# 20 million simulated experiments in a few seconds.
repeat_runs <- t(replicate(2000, {
mcp_power(means = mu_solomon, n = n_per_group, sigma = sigma_solomon,
procedure = "tukey", reps = n_replications)$estimate
}))
colnames(repeat_runs) <- c("complete", "minimal", "proportional", "true_FWE")
round(rbind(mean = colMeans(repeat_runs),
SD = apply(repeat_runs, 2, sd),
min = apply(repeat_runs, 2, min),
max = apply(repeat_runs, 2, max)), 5) complete minimal proportional true_FWE
mean 0.36559 0.94050 0.68808 0.02052
SD 0.00480 0.00233 0.00296 0.00143
min 0.35020 0.93310 0.67672 0.01550
max 0.38190 0.94790 0.69900 0.02480
#> minimal power: mean .94050 against the exact .9405, SD .00233 against the
#> .0024 that sqrt(p (1 - p) / 10000) predicts, and runs ranging from .9331
#> to .9479. Complete power: mean .36559 against the exact .3655. Proportional
#> power: mean .68808 against the exact .6880.The means recover the exact values and the standard deviations are the Monte Carlo standard errors the formula predicts, so the simulation is doing exactly what it should. What it cannot do is pin the third decimal. The 2,000 runs of minimal power range from .9331 to .9479, and that range contains both published figures: the book’s .94620 and this page’s .9333 are both inside the spread of honest runs. Neither is evidence of anything but the random stream behind it.
ggplot(data.frame(minimal = repeat_runs[, "minimal"]), aes(x = minimal)) +
geom_histogram(binwidth = 0.001, fill = "grey80", colour = "white") +
geom_vline(xintercept = exact_solomon[["minimal"]], linewidth = 1,
colour = "#0C2340") +
geom_vline(xintercept = 0.94620, linetype = "dashed", colour = "#0C2340") +
geom_vline(xintercept = estimates[["minimal"]], linetype = "dotted",
colour = "#0C2340") +
annotate("text", x = exact_solomon[["minimal"]], y = 410, hjust = 1.1,
label = "Exact .9405", colour = "#0C2340") +
annotate("text", x = 0.94620, y = 330, hjust = 1.1,
label = "Table 5.21 .94620", colour = "#0C2340") +
annotate("text", x = estimates[["minimal"]], y = 330, hjust = -0.1,
label = "Simulation above .9333", colour = "#0C2340") +
labs(x = "Estimated minimal (any-pairs) power per 10,000-replication run",
y = "Number of runs",
title = "Two thousand runs of the same 10,000-replication simulation")One more number makes the point concrete. To pin minimal power to within .001 with 95% confidence takes about 215,000 replications, not 10,000.
# Replications needed for a half-width of .001 around a power near .9405.
ceiling(qnorm(0.975)^2 * 0.9405 * (1 - 0.9405) / 0.001^2)[1] 214968
Two habits follow. Report a Monte Carlo standard error, or an interval, with any simulated power, as Table 5.21 does and as the first chunk of this section does; a power quoted to five decimals from 10,000 replications states several digits more than the run behind it can support. And where the design admits an exact calculation, prefer it: the quadrature above takes a few seconds, has no standard error at all, and is what tells us that both published figures are ordinary draws.
The practical reading is the book’s. Thirty participants per
condition give a high probability of finding something — a
statistically significant pairwise difference somewhere — and only about
a one-in-three chance of finding everything that is really
there, which is a recipe for apparent failures to replicate. The book
adds that PASS puts the sample size needed for all-pairs power of .80 at
52 per group (p. 257). The exact calculation can check that figure
directly, since exact_mcp() takes as an argument.
all_pairs_by_n <- vapply(50:54, function(n_group) {
exact_mcp(means = mu_solomon, n = n_group, sigma = sigma_solomon,
n_grid_MS = 200, n_grid_mean = 160)[["complete"]]
}, numeric(1))
round(setNames(all_pairs_by_n, 50:54), 3) 50 51 52 53 54
0.771 0.785 0.799 0.812 0.824
#> .771, .785, .799, .812, .824 — exact all-pairs power at n = 52 is .799,
#> which matches the .80 PASS reports, book p. 257A reader who wants the smallest whose exact all-pairs power reaches .80 on the nose would take 53. The difference is immaterial for planning, and it is the same lesson once more: PASS reaches 52 by simulation, so its answer carries a simulation error of its own.
The book. Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Designing Experiments and Analyzing Data: A Model Comparison Perspective (4th ed.). New York, NY: Routledge.
This page. Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Chapter 5: Testing Several Contrasts: The Multiple-Comparisons Problem (R code and instructions). Companion materials for Designing Experiments and Analyzing Data: A Model Comparison Perspective (4th ed.). https://DesigningExperiments.com
These examples use DMAR 1.2.0. The printed book predates DMAR.
Arel-Bundock V (2026). modelsummary: Summary Tables and Plots for Statistical Models and Data: Beautiful, Customizable, and Publication-Ready. doi:10.32614/CRAN.package.modelsummary https://doi.org/10.32614/CRAN.package.modelsummary. R package version 2.6.0, https://CRAN.R-project.org/package=modelsummary.
Hothorn T, Bretz F, Westfall P (2026). multcomp: Simultaneous Inference in General Parametric Models. doi:10.32614/CRAN.package.multcomp https://doi.org/10.32614/CRAN.package.multcomp. R package version 1.4-31, https://CRAN.R-project.org/package=multcomp.
Iannone R, Cheng J, Schloerke B, Haughton S, Hughes E, Lauer A, François R, Seo J, Brevoort K, Roy O (2026). gt: Easily Create Presentation-Ready Display Tables. doi:10.32614/CRAN.package.gt https://doi.org/10.32614/CRAN.package.gt. R package version 1.3.0, https://CRAN.R-project.org/package=gt.
Kelley K (2026). DMAR: Design, Measurement, and Analysis in R (DMAR). R package version 1.2.0, https://kenkelley.org.
Maxwell S, Delaney H, Kelley K (2026). AMCP: Data Sets to Accompany Designing Experiments and Analyzing Data: A Model Comparison Perspective (Maxwell, Delaney, and Kelley, 2027, 4th Edition). doi:10.32614/CRAN.package.AMCP https://doi.org/10.32614/CRAN.package.AMCP. R package version 2.0.0, https://CRAN.R-project.org/package=AMCP.
Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Designing Experiments and Analyzing Data: A Model Comparison Perspective (4th ed.). New York, NY: Routledge.
R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. doi:10.32614/R.manuals https://doi.org/10.32614/R.manuals. https://www.R-project.org/.
Wickham H, Chang W, Henry L, Pedersen T, Takahashi K, Wilke C, Woo K, Yutani H, Dunnington D, van den Brand T (2026). ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. doi:10.32614/CRAN.package.ggplot2 https://doi.org/10.32614/CRAN.package.ggplot2. R package version 4.0.3, https://CRAN.R-project.org/package=ggplot2.
Wickham H, François R, Henry L, Müller K, Vaughan D (2026). dplyr: A Grammar of Data Manipulation. doi:10.32614/CRAN.package.dplyr https://doi.org/10.32614/CRAN.package.dplyr. R package version 1.2.1, https://CRAN.R-project.org/package=dplyr.