Why a Three-Way Interaction Is a Difference in Differences
Suppose a predictive model uses three categorical factors: plan type, service region, and enrollment channel. A two-factor interaction says that the association between two factors varies across the levels of the other; a three-way interaction asks whether that two-factor interaction itself varies across the level of a third factor. It is therefore a difference in differences, rather than simply an extra effect attached to one combination of categories.
This interpretation is useful when a pattern of group differences is not consistent across all combinations of categories. The key is to compare the same two-factor contrast at each level of the third factor. This tutorial is aligned with the SOA Exam PA (Predictive Analytics) syllabus.
Let \(\eta_{abc}\) denote the model’s predicted value for the cell with \(A=a\), \(B=b\), and \(C=c\), where each factor is coded 0 or 1. At a fixed level \(c\), the \(A\)-by-\(B\) interaction contrast is \(\eta_{11c}-\eta_{10c}-\eta_{01c}+\eta_{00c}\). It compares the change associated with \(A\) between the two levels of \(B\), while holding \(C\) fixed. The three-way contrast subtracts this quantity at \(C=0\) from the same quantity at \(C=1\).
The Reference-Coded Model and Its Interpretation
Consider a linear model with an identity link and three binary categorical factors, each coded 0 for its reference level and 1 for its other level. The model includes all main effects, all two-factor interactions, and the three-factor interaction. Here \(\eta_{abc}\) is the predicted conditional mean on the response scale.
The intercept \(\beta_0\) is the predicted mean for the reference cell \((0,0,0)\). With this coding, each main-effect coefficient is a difference from the reference cell when the other factors are at reference levels. Each two-factor coefficient describes a two-factor interaction at the reference level of the remaining factor. The three-way coefficient describes how that two-factor interaction changes when the remaining factor switches from 0 to 1.
The expression in the first parentheses is the \(A\)-by-\(B\) interaction at \(C=1\); the expression in the second is the \(A\)-by-\(B\) interaction at \(C=0\). The sign matters: the contrast is the value at \(C=1\) minus the value at \(C=0\).
Why the Three-Way Coefficient Has This Meaning
The model’s structure gives a short derivation. First, hold \(C=c\) fixed and form the \(A\)-by-\(B\) contrast. Substitution of the model into that contrast cancels the intercept, the main effects, and the terms that do not involve both \(A\) and \(B\).
Use \(\eta_{11c}-\eta_{10c}-\eta_{01c}+\eta_{00c}\), so that the effects of \(A\) and \(B\) are compared jointly while \(C\) is held fixed.
The terms \(\beta_0\), \(\beta_A\), \(\beta_B\), \(\beta_Cc\), \(\beta_{AC}ac\), and \(\beta_{BC}bc\) cancel across the four cells. The terms that remain are \(\beta_{AB}\) and \(\beta_{ABC}c\).
The contrast at \(C=0\) is \(\beta_{AB}\); at \(C=1\) it is \(\beta_{AB}+\beta_{ABC}\). Subtracting gives \((\beta_{AB}+\beta_{ABC})-\beta_{AB}=\beta_{ABC}\).
This also explains the hierarchy of interpretations: \(\beta_{AB}\) is the \(A\)-by-\(B\) interaction at the reference level of \(C\), while \(\beta_{ABC}\) is how much that interaction changes at the other level. In particular, the \(A\)-by-\(B\) interaction at \(C=1\) is \(\beta_{AB}+\beta_{ABC}\), not \(\beta_{ABC}\) alone.
Worked Example: Finding a Three-Way Contrast From Cell Means
A hypothetical service model reports predicted values for combinations of three binary factors. At \(C=0\), the cell means are \(\eta_{000}=10\), \(\eta_{100}=14\), \(\eta_{010}=13\), and \(\eta_{110}=20\). At \(C=1\), they are \(\eta_{001}=12\), \(\eta_{101}=17\), \(\eta_{011}=16\), and \(\eta_{111}=28\). Calculate the three-way interaction contrast and interpret it.
Method. Calculate the \(A\)-by-\(B\) contrast at each level of \(C\), then subtract the \(C=0\) contrast from the \(C=1\) contrast.
At \(C=0\), the contrast is \(\eta_{110}-\eta_{100}-\eta_{010}+\eta_{000} =20-14-13+10=3\). The intermediate arithmetic is \(20-14=6\), \(6-13=-7\), and \(-7+10=3\).
At \(C=1\), it is \(\eta_{111}-\eta_{101}-\eta_{011}+\eta_{001} =28-17-16+12=7\). The intermediate arithmetic is \(28-17=11\), \(11-16=-5\), and \(-5+12=7\).
Therefore the three-way contrast is \(7-3=4\). The \(A\)-by-\(B\) interaction is 4 units larger at \(C=1\) than at \(C=0\). As a check, the model coefficient for the three-way interaction would equal this difference, 4, under the reference coding and identity-link setup. The common mistake to avoid is reporting 6: the two conditional contrasts are 7 and 3, and their difference is 4.
Calculating Cell Predictions From Coefficients
For any cell, substitute its factor codes into the model. A term such as \(\beta_{AB}ab\) contributes only when both \(A=1\) and \(B=1\); the three-way term contributes only in cell \((1,1,1)\). This is a reliable way to avoid adding coefficients that do not apply to the requested combination.
Worked Example: Calculating All Eight Cell Predictions
A hypothetical model for average processing time, measured in minutes, has coefficients \(\beta_0=40\), \(\beta_A=6\), \(\beta_B=-4\), \(\beta_C=3\), \(\beta_{AB}=5\), \(\beta_{AC}=-2\), \(\beta_{BC}=1\), and \(\beta_{ABC}=4\). The three factors are binary and use the 0/1 coding defined above. Calculate all eight cell predictions and verify the three-way coefficient using contrasts.
Method. Insert each cell’s codes into the model. A product such as \(ab\) is 1 only in cells with \(a=b=1\); otherwise it is 0.
For the four cells with \(C=0\), every term containing \(c\) is zero:
- \(\eta_{000}=40\).
- \(\eta_{100}=40+6=46\).
- \(\eta_{010}=40-4=36\).
- \(\eta_{110}=40+6-4+5=47\).
For the four cells with \(C=1\), include \(\beta_C=3\), and include other terms involving \(C\) only when their other factor codes are also 1:
- \(\eta_{001}=40+3=43\).
- \(\eta_{101}=40+6+3-2=47\).
- \(\eta_{011}=40-4+3+1=40\).
- \(\eta_{111}=40+6-4+3+5-2+1+4=53\).
Check the two-factor contrast at \(C=0\): \(47-46-36+40=1-36+40=5\). At \(C=1\), it is \(53-47-40+43=6-40+43=9\). Their difference is \(9-5=4\), which matches \(\beta_{ABC}=4\). This check confirms both the cell arithmetic and the interpretation. A common mistake is to omit \(\beta_{AB}\) from \(\eta_{110}\), or to include the three-way coefficient in a cell other than \((1,1,1)\).
Worked Example: Combining Main, Pairwise, and Three-Way Effects
For another hypothetical identity-link model, the reference-cell prediction is 100. The coefficients are \(\beta_A=12\), \(\beta_B=-5\), \(\beta_C=8\), \(\beta_{AB}=-3\), \(\beta_{AC}=4\), \(\beta_{BC}=2\), and \(\beta_{ABC}=-6\). Calculate \(\eta_{110}\), \(\eta_{101}\), \(\eta_{011}\), and \(\eta_{111}\), then verify the three-way contrast.
Method. Apply the cell codes term by term. The requested cells with exactly two factors at 1 receive the associated two main effects and their pairwise coefficient; the \((1,1,1)\) cell receives all coefficients.
For \((1,1,0)\), the terms involving \(C\) are zero: \(\eta_{110}=100+12-5-3=104\). For \((1,0,1)\), \(\eta_{101}=100+12+8+4=124\). For \((0,1,1)\), \(\eta_{011}=100-5+8+2=105\).
For \((1,1,1)\), every term applies: \(\eta_{111}=100+12-5+8-3+4+2-6=112\). For a check, the remaining reference-level cells are \(\eta_{000}=100\), \(\eta_{100}=100+12=112\), \(\eta_{010}=100-5=95\), and \(\eta_{001}=100+8=108\).
The \(A\)-by-\(B\) contrast at \(C=0\) is \(104-112-95+100=-3\). At \(C=1\), it is \(112-124-105+108=-9\). Subtracting gives \(-9-(-3)=-6\), which matches \(\beta_{ABC}=-6\). Thus the \(A\)-by-\(B\) interaction is 6 units smaller at \(C=1\) than at \(C=0\). The negative sign indicates the direction of this change; it does not mean that every prediction is negative.
Assumptions, Scale, and Common Traps
The coefficient-to-contrast interpretation above assumes binary factors coded 0 and 1, the stated reference-coded model, and an identity link so the modeled values \(\eta_{abc}\) are response-scale predicted means. If a generalized linear model uses a nonlinear link, the same coefficient combination describes a change in interaction on the link scale. It does not, in general, equal the corresponding difference in response-scale predicted means. For example, with a log link, a coefficient is interpreted through the model’s log mean; response-scale contrasts must be calculated from the predicted means after applying the inverse link.
The cell-contrast identity is an algebraic property of the full binary-factor model. For empirical estimates, however, the relevant cell predictions must be estimable from the data and the model must be appropriate for the intended use. Sparse or empty combinations can make an estimated interaction unstable or require predictions that are extrapolations. A numerical contrast alone does not establish that a pattern is reliable or substantively important.
Keep these interpretation checks in mind:
- Do not call the three-way coefficient the \(A\)-by-\(B\) interaction at \(C=1\). That interaction is \(\beta_{AB}+\beta_{ABC}\); \(\beta_{ABC}\) is the change from \(C=0\).
- Keep the subtraction order consistent. The defined contrast is the interaction at \(C=1\) minus the interaction at \(C=0\). Reversing it reverses the sign.
- Do not interpret a coefficient without its coding and reference levels. The individual coefficient values can change when coding or reference levels change, even though fitted cell predictions do not.
- Do not infer that a large three-way coefficient makes every cell prediction large. It contributes only to the \((1,1,1)\) cell in this reference-coded representation; cell predictions also depend on the other terms.
A practical exam-style approach is to calculate the cell predictions needed for the question, form the two-factor contrast separately at each level of the third factor, and then subtract in the stated order. This method both clarifies the meaning and provides an arithmetic check on a coefficient-based answer.
Check Your Understanding
For each problem, use the reference coding and contrast order defined above. Give the requested value or interpretation.
- A hypothetical model has \(A\)-by-\(B\) contrast 5 when \(C=0\) and 8 when \(C=1\). What is the three-way contrast, and how does the two-factor interaction change? (Answer: \(3\); it increases by 3.)
- A reference-coded model has \(\beta_{AB}=-2\) and \(\beta_{ABC}=5\). What is the \(A\)-by-\(B\) interaction at \(C=0\), and what is it at \(C=1\)? (Answer: \(-2\) at \(C=0\), and \(3\) at \(C=1\).)
- A model has \(\beta_0=30\), \(\beta_A=4\), \(\beta_B=-3\), \(\beta_C=2\), \(\beta_{AB}=6\), \(\beta_{AC}=-1\), \(\beta_{BC}=5\), and \(\beta_{ABC}=-4\). Calculate the prediction for \(A=1,B=0,C=1\). (Answer: \(35\).)
- For a hypothetical response, the four means at \(C=0\) are \(\eta_{000}=6\), \(\eta_{100}=10\), \(\eta_{010}=8\), and \(\eta_{110}=14\). At \(C=1\), they are \(\eta_{001}=9\), \(\eta_{101}=15\), \(\eta_{011}=12\), and \(\eta_{111}=23\). Find the three-way contrast. (Answer: \(3\).)