Why Cell Means Matter
When two categorical factors are related to an outcome, the difference between levels of one factor may depend on the level of the other. For example, a training method might be associated with different test scores across experience groups. A single overall difference between methods would hide that variation. Fitted cell means make the outcome for each combination of factor levels explicit, and contrasts between those means describe how group differences change across the other factor.
This tutorial considers two factors, each with more than two levels. The basic idea extends the two-by-two difference-in-differences calculation: compare a difference between levels of one factor in one stratum with the corresponding difference in another stratum. With multiple levels, there are several such comparisons, and the collection of them describes the interaction.
The Model for Two Categorical Factors
Let factor \(A\) have \(a\) levels, indexed by \(i=1,\ldots,a\), and factor \(B\) have \(b\) levels, indexed by \(j=1,\ldots,b\). Let \(Y_{ijk}\) be the outcome for observation \(k\) in the cell formed by levels \(i\) and \(j\). The cell mean \(\mu_{ij}\) is the mean outcome for that combination of factor levels.
For the usual least-squares analysis, the model assumes that observations are independent, that each cell has a well-defined mean, and that the errors have mean zero and a common variance across cells. For procedures that use a normal-theory distribution, the errors are also assumed to be normally distributed. The fitted cell means themselves do not require that additional normality assumption. In practice, independence comes from the study design; residual plots and knowledge of the data-collection process help assess the other assumptions.
If each combination of levels is observed, least squares fits each cell mean by the sample mean in that cell. In particular, if cell \((i,j)\) contains \(n_{ij}\) observations, then \(\hat{\mu}_{ij}=\bar{Y}_{ij}\), the average of those observations. The cell-means model is saturated for these cells: it does not impose a pattern such as equal differences or a straight-line trend across the factor levels.
Reference-Level Coefficients and Fitted Means
The cell-means representation is direct, but regression software often writes the same model using reference levels. Take level 1 of each factor as the reference. Let \(\alpha_i\) describe the difference between level \(i\) of \(A\) and its reference when \(B\) is at its reference; let \(\beta_j\) describe the corresponding difference for \(B\); and let \(\gamma_{ij}\) describe the additional departure for the combination of nonreference levels.
The reference-level terms are set to zero: \(\alpha_1=0\), \(\beta_1=0\), \(\gamma_{i1}=0\), and \(\gamma_{1j}=0\). Thus \(\mu_{11}\) is the reference-cell mean, and the equation reconstructs every other cell mean. A main-effect coefficient such as \(\alpha_i\) is therefore a conditional difference at the reference level of \(B\), not necessarily an overall difference averaged across all levels of \(B\).
The interaction term can be written as a difference-in-differences. For any two levels \(i,i'\) of \(A\) and two levels \(j,j'\) of \(B\), define the rectangular contrast
It compares the difference between \(i\) and \(i'\) at level \(j\) with that same difference at level \(j'\). If the result is zero, that particular pairwise difference is the same in those two strata. If it is nonzero, the difference changes across the two levels.
To justify the equivalence, first suppose the means are additive, so \(\mu_{ij}=\mu+\alpha_i+\beta_j\). Substitution into the contrast gives
Conversely, suppose every rectangular contrast is zero. Choose reference levels 1 and 1, and compare cell \((i,j)\) to the reference row and column. The zero contrast condition gives \(\mu_{ij}-\mu_{1j}=\mu_{i1}-\mu_{11}\). Rearranging,
This is an additive expression with no interaction. Consequently, checking the reference-level interactions \(\gamma_{ij}\) for all nonreference pairs is enough: there are \((a-1)(b-1)\) such terms, and all are zero exactly when the model is additive.
Worked Example: A Three-Level Factor Across Two Clinics
Suppose a hypothetical program compares three approaches to reducing systolic blood pressure at two clinics. The outcome is reduction in mmHg, so larger values indicate greater reductions. The fitted cell means are as follows.
| Approach | Clinic 1 | Clinic 2 |
|---|---|---|
| A | 8 mmHg | 6 mmHg |
| B | 10 mmHg | 8 mmHg |
| C | 7 mmHg | 5 mmHg |
Assume independent observations within the six approach-by-clinic cells, a common error variance, and a mean-zero error in each cell. These are assumptions of the model, not facts proven by the table. If the data came from independent participants and the within-cell residual spreads were reasonably similar, those features would support the assumptions; the means alone cannot assess the residual spreads.
Take approach A and Clinic 1 as reference. The reference mean is \(\hat{\mu}_{11}=8\) mmHg. At Clinic 1, the fitted difference for B versus A is \(10-8=2\) mmHg, so \(\hat{\alpha}_B=2\) mmHg. For C versus A it is \(7-8=-1\) mmHg, so \(\hat{\alpha}_C=-1\) mmHg. For approach A, Clinic 2 versus Clinic 1 is \(6-8=-2\) mmHg, so \(\hat{\beta}_2=-2\) mmHg.
The interaction for B at Clinic 2 is the extra departure from adding those reference differences. The model predicts \(8+2-2=8\) mmHg, which equals the fitted mean for B at Clinic 2; hence \(\hat{\gamma}_{B,2}=8-8=0\). For C at Clinic 2, the additive prediction is \(8-1-2=5\) mmHg, again equal to the fitted mean, so \(\hat{\gamma}_{C,2}=0\).
The cell-mean contrasts tell the same story directly. B exceeds A by \(10-8=2\) mmHg at Clinic 1 and by \(8-6=2\) mmHg at Clinic 2, giving a difference-in-differences of \(2-2=0\) mmHg. C is 1 mmHg below A at both clinics, also giving zero. These fitted means show no interaction pattern for these approaches and clinics: the approach differences are constant across clinics.
More Than One Interaction Contrast
With three or more levels in both factors, a single comparison cannot describe the whole interaction. One convenient approach is to select reference levels and calculate each nonreference interaction coefficient. Another is to choose comparisons that answer a particular question. Both methods use fitted cell means; changing the reference levels changes the coefficient values, but not the fitted means or the underlying pattern of contrasts.
Worked Example: Reading a Three-by-Three Interaction
In a hypothetical study, three teaching methods are compared across three prior-experience groups. The outcome is a test score in points. Consider these fitted cell means.
| Method | Novice | Intermediate | Advanced |
|---|---|---|---|
| A | 50 | 55 | 60 |
| B | 54 | 57 | 61 |
| C | 49 | 53 | 59 |
Use Method A and Novice as references. The reference mean is 50 points. At Novice experience, B differs from A by \(54-50=4\) points and C differs by \(49-50=-1\) point. For Method A, Intermediate differs from Novice by \(55-50=5\) points, and Advanced differs by \(60-50=10\) points.
For B and Intermediate, the additive prediction is \(50+4+5=59\) points. The fitted mean is 57, so the interaction coefficient is \(57-59=-2\) points. In contrast form, B exceeds A by \(57-55=2\) points at Intermediate, compared with \(54-50=4\) points at Novice. The difference-in-differences is \(2-4=-2\) points.
For C and Intermediate, the additive prediction is \(50+(-1)+5=54\) points. The fitted mean is 53, so the interaction is \(53-54=-1\) point. Equivalently, C is \(53-55=-2\) points below A at Intermediate and \(49-50=-1\) point below A at Novice; the change in that difference is \(-2-(-1)=-1\) point.
The other reference-level interactions can be checked in the same way. For B and Advanced, the prediction is \(50+4+10=64\), compared with a fitted mean of 61, giving \(-3\) points. For C and Advanced, the prediction is \(50-1+10=59\), exactly the fitted mean, giving 0 points. Since several interaction coefficients are not zero, the method differences are not constant across experience groups.
Worked Example: Choosing a Contrast to Answer a Specific Question
Consider a different hypothetical comparison of three work schedules across three shifts. The outcome is completed units per worker per hour, and the fitted means are:
| Schedule | Morning | Afternoon | Night |
|---|---|---|---|
| A | 20 | 24 | 22 |
| B | 23 | 25 | 27 |
| C | 19 | 26 | 23 |
Assume workers' observations are independent, the cell means are meaningful for each schedule-shift combination, and the errors have mean zero and a common variance. These assumptions would need support from the hypothetical sampling or assignment process and an assessment of residual variability; the table of means does not establish them.
Suppose the question is whether the difference between schedules B and A changes from Morning to Afternoon. At Morning, the fitted difference is \(23-20=3\) units per worker-hour. At Afternoon it is \(25-24=1\). Therefore the contrast is \(1-3=-2\) units per worker-hour. The B-versus-A difference is 2 units smaller in the Afternoon than in the Morning.
For the same schedule comparison, Night versus Morning gives \((27-22)-(23-20)=5-3=2\) units per worker-hour. Thus the difference is 2 units larger at Night than in the Morning. These two contrasts describe how the B-versus-A difference varies across the shifts; neither alone summarizes every schedule comparison. For example, comparing C with A would require its own contrasts.
What the Interaction Does—and Does Not—Say
An interaction describes variation in conditional differences: it says that a difference between levels of one factor changes across levels of the other factor. It does not by itself identify a cause. A causal interpretation would require a study design and assumptions that justify causal conclusions. Nor does a nonzero fitted contrast by itself establish that the corresponding population contrast differs from zero; uncertainty and an appropriate inferential procedure are needed for that conclusion.
The fitted cell means are often the clearest starting point because they stay interpretable regardless of the coding used for the regression. Coefficients are compact summaries relative to a chosen reference, while rectangular contrasts express comparisons directly in the outcome's units. Report which levels are being compared and the units, rather than describing an interaction only as “positive” or “negative.”
- Use cell means to show the fitted outcome at every factor combination.
- Use a contrast to state how a specified group difference changes between specified levels of the other factor.
- Check all relevant contrasts before concluding that there is no interaction across multi-level factors.
Check Your Understanding
Use fitted cell means and rectangular contrasts to answer these questions.
- For factors with three and four levels, how many reference-level interaction coefficients are there?
- In a two-by-two comparison, the difference between A1 and A2 is 6 points at B1 and 2 points at B2. Calculate the rectangular contrast using the order “difference at B1 minus difference at B2,” and interpret it.
- What does a zero interaction coefficient for one nonreference cell mean under reference-level coding? Does it alone prove there is no interaction across all levels?
- Why can changing reference levels alter individual coefficient values without altering fitted cell means?
- What additional information, beyond a table of fitted cell means, would help assess whether a common error variance assumption is reasonable?