Tutorials › Generalized Linear Models › Three-Way Interactions as Changing Two-Way Effects

Factors Contrasts and Interactions · Tutorial 152 of 981

Three-Way Interactions as Changing Two-Way Effects

Learn to build a three-factor reference-coded linear predictor and interpret its highest-order coefficient as a difference between two two-way interactions.

Intermediate 10 min read

What You'll Learn

  • Write the full reference-coded linear predictor for three binary factors
  • Obtain cell-specific two-way interactions from cell linear predictors
  • Derive the three-way coefficient as a difference between two-way interactions
  • Extend the interpretation to factors with multiple levels
  • Interpret a three-way interaction on the log-odds scale without confusing it with a response-scale difference

Why a Three-Way Interaction Is a Changing Two-Way Interaction

Suppose a clinical study compares two treatments across two patient groups, with outcomes recorded before and after an intervention. The treatment contrast may differ between groups, and that difference may itself depend on time. A three-way interaction describes this last change: how a two-factor interaction changes across levels of a third factor.

The interpretation depends on the scale of the model. In a generalized linear model, the linear predictor is \(\eta=g(\mu)\), where \(\mu\) is the conditional mean and \(g\) is the link function. Thus, the three-way coefficient describes a change in a two-way interaction on the linear-predictor scale. For a logit link, for example, that means the log-odds scale.

Definition: For three binary factors \(A\), \(B\), and \(C\), use indicator variables \(A,B,C\in\{0,1\}\), with 0 denoting the reference level of each factor. The reference-coded full factorial linear predictor is $$ \eta=\beta_0+\beta_A A+\beta_B B+\beta_C C+ \beta_{AB}AB+\beta_{AC}AC+\beta_{BC}BC+ \beta_{ABC}ABC. $$ The coefficient \(\beta_{ABC}\) is the change in the \(A\)-by-\(B\) interaction when \(C\) changes from 0 to 1, measured on the linear-predictor scale.

The product terms switch on for particular combinations of factor levels. For example, \(AB=1\) only when both \(A=1\) and \(B=1\), while \(ABC=1\) only in the cell with all three factors at level 1. The intercept is the linear predictor in the reference cell. The main-effect coefficients compare a nonreference level with its reference level while the other factors remain at reference levels. The two-factor coefficients describe departures from additivity on the linear-predictor scale for the corresponding pair, with the third factor at its reference level.

Deriving the Three-Way Coefficient

Let \(\eta_{abc}\) denote the linear predictor in the cell \(A=a\), \(B=b\), \(C=c\). At a fixed level \(c\) of \(C\), define the \(A\)-by-\(B\) interaction as the difference-in-differences $$ \Delta_{AB}(c)=\eta_{11c}-\eta_{10c}-\eta_{01c}+\eta_{00c}. $$ It compares the change in the predictor from \(A=0\) to \(A=1\) when \(B=1\) with that same change when \(B=0\). A zero value means those two changes agree at that level of \(C\).

Theorem: Under the reference-coded predictor above, $$ \Delta_{AB}(0)=\beta_{AB},\qquad \Delta_{AB}(1)=\beta_{AB}+\beta_{ABC}. $$ Consequently, $$ \beta_{ABC}=\Delta_{AB}(1)-\Delta_{AB}(0). $$

Proof. At \(C=0\), the four cell predictors are $$ \begin{aligned} \eta_{000}&=\beta_0,\\ \eta_{100}&=\beta_0+\beta_A,\\ \eta_{010}&=\beta_0+\beta_B,\\ \eta_{110}&=\beta_0+\beta_A+\beta_B+\beta_{AB}. \end{aligned} $$ Substituting into the difference-in-differences gives $$ \Delta_{AB}(0) =(\beta_0+\beta_A+\beta_B+\beta_{AB}) -(\beta_0+\beta_A) -(\beta_0+\beta_B)+\beta_0 =\beta_{AB}. $$ At \(C=1\), the corresponding predictors are $$ \begin{aligned} \eta_{001}&=\beta_0+\beta_C,\\ \eta_{101}&=\beta_0+\beta_A+\beta_C+\beta_{AC},\\ \eta_{011}&=\beta_0+\beta_B+\beta_C+\beta_{BC},\\ \eta_{111}&=\beta_0+\beta_A+\beta_B+\beta_C+ \beta_{AB}+\beta_{AC}+\beta_{BC}+\beta_{ABC}. \end{aligned} $$ Therefore, $$ \begin{aligned} \Delta_{AB}(1) &=\eta_{111}-\eta_{101}-\eta_{011}+\eta_{001}\\ &=\beta_{AB}+\beta_{ABC}. \end{aligned} $$ The intercept, main effects, and the \(AC\) and \(BC\) terms cancel. Subtracting the two interactions gives \(\Delta_{AB}(1)-\Delta_{AB}(0)=\beta_{ABC}\), as claimed. \(\square\)

This calculation also shows why the highest-order coefficient is not simply “the \(A\)-by-\(B\) interaction.” The \(A\)-by-\(B\) interaction at the reference level of \(C\) is \(\beta_{AB}\). At the nonreference level, it is \(\beta_{AB}+\beta_{ABC}\). The three-way coefficient is the difference between those two interactions.

Worked Example: Finding the Three-Way Coefficient From Model Terms

Consider the predictor $$ \eta=20+4A+2B+5C+3AB-AC+2BC-3ABC. $$ The coefficient of the three-way product is \(\beta_{ABC}=-3\). Verify what that value says by calculating the two \(A\)-by-\(B\) interactions.

At \(C=0\), the relevant cell predictors are \(\eta_{000}=20\), \(\eta_{100}=24\), \(\eta_{010}=22\), and \(\eta_{110}=29\). Thus, $$ \Delta_{AB}(0)=29-24-22+20=3. $$

At \(C=1\), the cell predictors are \(\eta_{001}=25\), \(\eta_{101}=28\), \(\eta_{011}=29\), and \(\eta_{111}=32\). Thus, $$ \Delta_{AB}(1)=32-28-29+25=0. $$

The interaction changes by \(0-3=-3\), exactly the value of \(\beta_{ABC}\). In this model, the \(A\)-by-\(B\) interaction is positive at \(C=0\) and absent at \(C=1\), on the linear-predictor scale.

Reading Cell Values and Extending to Multiple Levels

The coefficient can also be recovered directly from cell predictors. This is useful when a model is presented as a table of cell means or fitted linear predictors rather than as a list of coefficients. First calculate the \(A\)-by-\(B\) difference-in-differences at each level of \(C\); then subtract the reference-level interaction from the other-level interaction.

Worked Example: Recovering the Coefficient From Cell Predictors

Suppose the cell predictors are given in the table below. The rows distinguish \(A\), the columns distinguish \(B\), and the two panels give the levels of \(C\).

\(C=0\) \(B=0\) \(B=1\)
\(A=0\)1012
\(A=1\)1318
\(C=1\) \(B=0\) \(B=1\)
\(A=0\)1415
\(A=1\)1622

At \(C=0\), the interaction is $$ \Delta_{AB}(0)=18-13-12+10=3. $$ At \(C=1\), it is $$ \Delta_{AB}(1)=22-16-15+14=5. $$ Therefore, the three-way coefficient is $$ \beta_{ABC}=5-3=2. $$ As a check, the reference cell gives \(\beta_0=\eta_{000}=10\). The main-effect coefficients are \(\beta_A=13-10=3\), \(\beta_B=12-10=2\), and \(\beta_C=14-10=4\). The two-factor terms are \(\beta_{AB}=3\), \(\beta_{AC}=16-13-14+10=-1\), and \(\beta_{BC}=15-12-14+10=-1\). The predictor for cell \(111\) is therefore \(10+3+2+4+3-1-1+2=22\), matching the table.

The same idea applies when factors have more than two levels. Let level 0 be the reference level for each factor, and let \(j,k,l\) denote nonreference levels of \(A,B,C\). In reference coding, the full factorial predictor includes an indicator for each nonreference level, each pair of nonreference levels, and each triple of nonreference levels. Write \(\eta_{jkl}\) for the predictor in the corresponding cell. The coefficient \(\beta_{ABC,jkl}\) for the triple of levels \(j,k,l\) is $$ \beta_{ABC,jkl} = \bigl(\eta_{jkl}-\eta_{j0l}-\eta_{0kl}+\eta_{00l}\bigr) - \bigl(\eta_{jk0}-\eta_{j00}-\eta_{0k0}+\eta_{000}\bigr). $$

To see the cancellation, the first parenthesis is the \(A\)-by-\(B\) interaction at \(C=l\). In the reference-coded predictor, its terms include the \(AB\) coefficient for levels \(j,k\) and the \(ABC\) coefficient for levels \(j,k,l\). The second parenthesis is the same \(A\)-by-\(B\) interaction at \(C=0\); it includes the same \(AB\) coefficient but no triple term. Subtraction leaves precisely \(\beta_{ABC,jkl}\). Thus each triple coefficient compares a particular nonreference-level \(A\)-by-\(B\) interaction with that interaction at the reference level of \(C\).

Derived result: For any nonreference levels \(j,k,l\), the reference-coded three-way coefficient is the change, from \(C=0\) to \(C=l\), in the \(A\)-by-\(B\) difference-in-differences. This follows because all terms involving fewer than all three factors cancel when the two interaction contrasts are subtracted.

What the Coefficient Means in a Logistic GLM

For a logit link, \(\eta_{abc}=\log\{p_{abc}/(1-p_{abc})\}\), where \(p_{abc}\) is the event probability in cell \(abc\). A difference in linear predictors is a log odds ratio. Accordingly, \(\Delta_{AB}(c)\) is the log of the ratio of two odds ratios comparing \(A\) across the levels of \(B\), at fixed \(C=c\). The three-way coefficient is the difference between those log interaction contrasts across \(C\), or equivalently the log of their ratio.

Worked Example: Interpreting a Logit-Scale Three-Way Interaction

Suppose a logistic model gives the following cell odds of an outcome for three binary factors: $$ \begin{array}{c|rrrr} & (A,B)=(0,0)&(1,0)&(0,1)&(1,1)\\ C=0&1/4&1/2&3/4&3\\ C=1&1/2&1&3/2&24 \end{array} $$ For \(C=0\), the odds ratio for changing \(A\) from 0 to 1 when \(B=0\) is \((1/2)/(1/4)=2\). When \(B=1\), it is \(3/(3/4)=4\). The ratio of these odds ratios is \(4/2=2\), so \(\Delta_{AB}(0)=\log 2\).

For \(C=1\), the corresponding odds ratios are \(1/(1/2)=2\) when \(B=0\), and \(24/(3/2)=16\) when \(B=1\). Their ratio is \(16/2=8\), so \(\Delta_{AB}(1)=\log 8\). The three-way coefficient is therefore $$ \beta_{ABC}=\log 8-\log 2=\log 4. $$

This result says that the \(A\)-by-\(B\) interaction, expressed as a ratio of odds ratios, is four times as large at \(C=1\) as at \(C=0\): \(8/2=4\). It does not say that the difference in event probabilities is four times as large. Probabilities are obtained by applying the inverse-logit transformation to the linear predictors, and their differences need not follow this multiplicative relationship.

Common Pitfall: Switching Scales Mid-Interpretation

A frequent error is to describe \(\beta_{ABC}\) as the change in a raw outcome difference, without checking the link. The coefficient is a difference of two-factor interactions on the scale of \(\eta\), not automatically on the scale of \(\mu\). With an identity link, \(\eta=\mu\), so the interpretation is in mean differences. With a logit link, it is in log odds and odds-ratio contrasts. With another link, it is on that link’s scale.

A second error is to report \(\beta_{ABC}\) as the \(A\)-by-\(B\) interaction at every level of \(C\). Under reference coding, \(\beta_{ABC}\) alone is the change in that interaction from the reference level of \(C\). The interaction at the reference level is \(\beta_{AB}\); at the nonreference level it is \(\beta_{AB}+\beta_{ABC}\). Keeping those quantities distinct makes the coefficient interpretable.

Key takeaway: Calculate the \(A\)-by-\(B\) difference-in-differences at each level of \(C\), using the model’s linear predictors. Their difference is the reference-coded three-way coefficient. Interpret that result on the linear-predictor scale, then translate the scale into the context of the link function.

Check Your Understanding

Use the reference level 0 for each factor, and keep the interpretation on the linear-predictor scale unless a link is specified.

  1. In the binary three-factor predictor, what is the \(A\)-by-\(B\) interaction when \(C=0\), and what is it when \(C=1\)?
  2. If \(\Delta_{AB}(0)=1.4\) and \(\Delta_{AB}(1)=0.6\), what is \(\beta_{ABC}\)? Interpret its sign.
  3. For a logit link, what type of contrast does \(\Delta_{AB}(c)\) represent?
  4. Why is \(\beta_{ABC}\) not generally a change in a difference of event probabilities?
  5. For factors with multiple levels, what two interactions are subtracted to obtain a particular triple coefficient \(\beta_{ABC,jkl}\)?
Clinical Biostats