Learning objectives. Express a comparison of group means as a linear function of regression coefficients, obtain its estimate and interval, and distinguish a meaningful comparison from a coding-dependent coefficient.
6.1 Comparisons of group means
Suppose the conditional means of three groups are \(\mu_A\), \(\mu_B\), and \(\mu_C\). A question such as “Does A differ from the average of B and C?” concerns \(\theta=\mu_A-(\mu_B+\mu_C)/2\).
Definition 6.1 (Contrast of Group Means) A contrast is a linear combination \(\theta=\sum_{j=1}^g c_j\mu_j\) whose weights satisfy \(\sum_{j=1}^g c_j=0\). The zero-sum condition makes the comparison unchanged when the same constant is added to every group mean.
From means to coefficients. With A as the reference group, write \(\boldsymbol{\beta}=(\beta_0,\beta_B,\beta_C)^\top\). Then \(\mu_A=\beta_0\), \(\mu_B=\beta_0+\beta_B\), and \(\mu_C=\beta_0+\beta_C\), so
ImportantThe zero-sum condition applies to mean weights
The weights on \((\mu_A,\mu_B,\mu_C)\) sum to zero. The equivalent weights on treatment-coded regression coefficients need not sum to zero. Always translate the scientific comparison through the chosen parameterization.
A confidence interval is \(\hat\theta\pm t_{1-\alpha/2,n-p}\operatorname{SE}(\hat\theta)\). This is the same procedure as in Chapter 3 — Distribution Theory of OLS and Inference, applied to a different target. Several independent restrictions can be collected into \(C\beta=d\), with \(\operatorname{rank}(C)=r\), and tested jointly using the general F test.
Interpretation. Report the contrast estimate in the units of the response, its interval, and which population means it compares. Equality of two slopes is only a meaningful scientific question when their units and scales make that comparison defensible.
6.2 Coding and estimability
Changing the reference group changes the coefficient labels and values, but not the fitted group means or a fixed comparison of those means. The vector \(\mathbf{a}\) must change with the coding so that it represents the same target.
Example 6.1 (An Intercept and All Group Indicators) In \(Y_{ij}=\mu+\tau_i+\varepsilon_{ij}\), adding a constant to every \(\tau_i\) and subtracting it from \(\mu\) leaves every group mean unchanged. The separate parameters are not identified without a constraint, but \(\tau_A-\tau_B\) is unchanged and is estimable.
The practical lesson is to state the target in terms of observable mean responses before reading coefficients. For the row-space criterion and generalized-inverse formulation, see Linear-Model Extensions (Optional).
NoteOne comparison versus a family of comparisons
A single prespecified contrast and a search through many contrasts are different inferential procedures. Define the family being reported. For all pairwise group comparisons, Tukey intervals are useful; for a specified family of tests, Holm adjustment is another option. An omnibus F test does not automatically justify every unadjusted pairwise test.
6.3 A complete contrast analysis in R
This simulated example separates the known data-generating means from their noisy estimates. Changing the seed changes the sample, not the target comparison.
Show R code
library(ggplot2)theme_set(theme_minimal(base_size =11) +theme(legend.position ="bottom",panel.grid.minor =element_blank()))set.seed(8561)group <-factor(rep(c("A", "B", "C"), each =12))mu <-c(A =10, B =13, C =15)dat <-data.frame(group,y =unname(mu[group]) +rnorm(length(group), sd =2))fit <-lm(y ~ group, data = dat)# A minus the average of B and C, under treatment coding.a <-c(0, -1/2, -1/2)estimate <-sum(a *coef(fit))se <-sqrt(drop(t(a) %*%vcov(fit) %*% a))df <-df.residual(fit)ci <- estimate +c(-1, 1) *qt(0.975, df) * sec(estimate = estimate, SE = se, lower = ci[1], upper = ci[2],p_value =2*pt(-abs(estimate / se), df))
estimate SE lower upper p_value
-3.3388312952 0.9030487544 -5.1760978004 -1.5015647901 0.0007874472
Verify the same question under another coding. A cell-means model directly estimates \((\mu_A,\mu_B,\mu_C)\), so its contrast weights are \((1,-1/2,-1/2)\).
Figure 6.1: The estimated A-minus-average-of-B-and-C contrast and its 95% confidence interval. Zero represents no difference for this particular comparison.
A family of comparisons. For all three pairwise group differences, fit the one-way ANOVA and request simultaneous Tukey intervals:
Show R code
TukeyHSD(aov(y ~ group, data = dat))
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = y ~ group, data = dat)
$group
diff lwr upr p adj
B-A 2.8862540 0.3275576 5.444950 0.0242654
C-A 3.7914086 1.2327122 6.350105 0.0026175
C-B 0.9051546 -1.6535418 3.463851 0.6639004
These intervals answer a different collection of questions from the single contrast above. Do not infer a difference between group means by inspecting whether two separate mean-response intervals overlap.
6.4 Practice
Express \(\mu_B-\mu_C\) under treatment coding with A as reference, then under cell-means coding.
Verify that the estimate and standard error agree under the two codings.
Explain why the coefficients can change after changing the reference group while the scientific comparison remains unchanged.
Specify the comparison family before reporting all pairwise differences, and explain the role of multiplicity adjustment.