When a Slope Difference Depends on Another Group
Suppose an outcome is related to a quantitative predictor, such as a treatment dose, and the relationship may differ across two categorical factors, such as treatment protocol and age group. It may not be enough to ask whether the dose slope differs by protocol. The protocol-related slope difference might itself be different for younger and older participants. A model needs a term that represents this extra change.
This is the role of a three-way interaction between a quantitative predictor and two categorical factors. It describes whether the difference in slopes across one factor changes across levels of the other factor. It does not, by itself, describe the slope for a particular group or establish that one variable causes another.
Model and Reference Coding
For a clear starting point, let \(x\) be a quantitative predictor and let \(A\) and \(B\) be binary indicators for two categorical factors. Code the chosen reference category of each factor as 0 and its comparison category as 1. For example, \(A=1\) might indicate a new protocol rather than a standard protocol, while \(B=1\) indicates an older rather than younger age group.
The full conditional-mean model is
Equivalently, an individual outcome can be written as this conditional mean plus an error term \(\varepsilon\). For interpreting the model, assume that the mean outcome is represented adequately by the stated equation: within each combination of \(A\) and \(B\), the conditional mean is linear in \(x\). The usual regression conditions for inference also include independent errors with mean zero and constant variance given the predictors; normal errors are used for exact small-sample inference. This tutorial focuses on interpreting the model, not carrying out an inferential test.
Including all lower-order terms matters. The \(xA\) and \(xB\) terms allow the slope to vary with either factor, while \(xAB\) allows the change in slope associated with one factor to vary across the other. The \(A\), \(B\), and \(AB\) terms allow group differences in the conditional mean that do not depend on \(x\). These terms have different roles: the three-way coefficient concerns slopes, not just group mean differences.
How the Three-Way Coefficient Enters the Slope Difference
For fixed values of \(A\) and \(B\), the conditional mean is linear in \(x\). Its slope is the coefficient multiplying \(x\), after accounting for the indicator values. Differentiating the conditional mean with respect to \(x\) gives
To compare the slope for \(A=1\) with the slope for \(A=0\), hold \(B=b\) fixed and subtract. When \(A=0\), the slope is \(\beta_x+\beta_{xB}b\). When \(A=1\), it is \(\beta_x+\beta_{xA}+\beta_{xB}b+\beta_{xAB}b\). Therefore,
This shows precisely how the difference depends on the second factor. At the reference level \(B=0\), the slope difference is \(\beta_{xA}\). At \(B=1\), it is \(\beta_{xA}+\beta_{xAB}\). The difference between these two slope differences is
This subtraction is the key interpretation. The coefficient \(\beta_{xAB}\) is a difference between slope differences—a change in how the slope varies across \(A\), comparing the two levels of \(B\). It is not the slope for any one of the four \(A,B\) combinations.
Worked Example: A Protocol-Related Slope Difference by Age Group
Consider a clearly hypothetical analysis of outcome score \(Y\) in relation to dose \(x\), measured in milligrams. Let \(A=1\) indicate a new protocol and \(A=0\) a standard protocol; let \(B=1\) indicate the older age group and \(B=0\) the younger group. Suppose the fitted coefficients for the model above are \(\hat{\beta}_x=1.8\), \(\hat{\beta}_{xA}=-0.5\), \(\hat{\beta}_{xB}=0.4\), and \(\hat{\beta}_{xAB}=0.9\). The other coefficients are also included in the fitted model, but are not needed for these slope comparisons.
For the younger group, \(B=0\), the protocol-related slope difference is
outcome-score points per milligram. In this hypothetical model, the dose slope for the new protocol is 0.5 points per milligram lower than the slope for the standard protocol among younger participants.
For the older group, \(B=1\), the corresponding difference is
outcome-score points per milligram. Thus, among older participants, the new-protocol slope is 0.4 points per milligram higher than the standard-protocol slope. Comparing the two stratum-specific differences gives \(0.4-(-0.5)=0.9\), equal to \(\hat{\beta}_{xAB}\). These are model-based associations; they do not by themselves show that changing the protocol or dose causes a change in outcome.
Worked Interpretations of the Three-Way Term
Worked Example: Reading the Sign and Units
Suppose a hypothetical model relates weekly practice time \(x\), measured in hours, to a performance score \(Y\). Factor \(A\) indicates coaching type (1 for specialist coaching, 0 for usual coaching), and factor \(B\) indicates experience group (1 for experienced, 0 for beginners). Suppose the fitted three-way coefficient is \(\hat{\beta}_{xAB}=0.6\) score points per practice hour.
By definition, this coefficient is the protocol-related slope difference at \(B=1\) minus the same slope difference at \(B=0\). Substituting the estimate gives
The interpretation is that the specialist-versus-usual coaching difference in the practice-time slope is 0.6 score points per hour more positive among experienced participants than among beginners. This statement does not reveal either slope difference on its own. To find either one, the relevant \(\hat{\beta}_{xA}\) estimate is also needed.
Worked Example: A Negative Three-Way Coefficient
In another hypothetical model, \(x\) is daily exposure in units per day, \(A\) indicates product type, and \(B\) indicates a low- versus high-risk category, with \(B=1\) for high risk. Suppose \(\hat{\beta}_{xA}=1.1\) outcome units per exposure unit and \(\hat{\beta}_{xAB}=-0.7\) outcome units per exposure unit.
At \(B=0\), the estimated product-related slope difference is
outcome units per exposure unit. At \(B=1\), it is
outcome units per exposure unit. The negative three-way coefficient means the product-related slope difference is 0.7 outcome units per exposure unit less positive in the high-risk category than in the reference category. It does not mean that the exposure slope itself is necessarily negative for either product or risk category.
A Short Derivation: Why This Is a Difference of Differences
Let \(D_A(b)\) denote the slope for \(A=1\) minus the slope for \(A=0\) at \(B=b\). The slope expression derived above gives \(D_A(b)=\beta_{xA}+\beta_{xAB}b\). Evaluate this once at each value of \(B\):
Thus, the three-way coefficient is a difference of two slope differences. The same coefficient can be interpreted in the reverse order: it is the change across \(A\) in the slope difference for \(B\). These are two descriptions of the same contrast because both compare the four predictor slopes using the same alternating subtraction.
Common Mistakes and Why the Model Matters
The three-way term is useful when a single summary of the slope difference across \(A\) would conceal meaningful variation across \(B\). Reporting only \(\beta_{xA}\) as “the slope difference between the \(A\) groups” is incomplete when \(xAB\) is in the model: \(\beta_{xA}\) describes that difference specifically at the reference category \(B=0\). At \(B=1\), the difference includes both coefficients.
- Wrong: “The three-way coefficient is the slope for the \(A=1,B=1\) group.” Correction: It is a difference between slope differences; a group’s slope also depends on the other predictor-slope coefficients.
- Wrong: “\(\beta_{xA}\) is the \(A\)-group slope difference for everyone.” Correction: It is the difference at \(B=0\); at \(B=1\), the difference is \(\beta_{xA}+\beta_{xAB}\).
- Wrong: “A positive three-way coefficient means all slopes are positive.” Correction: Its sign indicates how a slope difference changes across strata, not the signs of the individual slopes.
- Wrong: “The model proves that the factor changes the effect of dose.” Correction: Regression describes conditional associations unless the study design and assumptions support a causal interpretation.
Reference coding determines which stratum-specific slope difference is represented directly by \(\beta_{xA}\), but it does not change fitted predictions. If the reference category changes, the coefficient interpretation changes accordingly; the conditional comparisons can still be calculated from the appropriately coded model.
Check Your Understanding
Use the reference coding and model defined above.
- At which level of \(B\) does \(\beta_{xA}\) alone give the slope difference across \(A\)?
- If \(\beta_{xA}=0.3\) and \(\beta_{xAB}=-0.8\), what is the slope difference across \(A\) at \(B=1\)?
- In words, what does \(\beta_{xAB}\) compare?
- Why is it incorrect to describe the three-way coefficient as the slope for the \(A=1,B=1\) group?
- If a slope difference across \(A\) is positive at \(B=0\) and negative at \(B=1\), what does that say about how the group slopes compare across strata?