Tutorials › Regression Analysis (Undergraduate) › Expanding a Three-Way Model Into Group-Specific Lines

Interactions Among Groups · Tutorial 360 of 991

Expanding a Three-Way Model Into Group-Specific Lines

Learn to substitute each binary-group combination into a three-way interaction model and read off its fitted intercept and slope.

Intermediate 10 min read

What You'll Learn

  • Write the full regression model for a quantitative predictor and two binary group indicators.
  • Derive the intercept and slope for each of the four group combinations.
  • Distinguish the three-way interaction coefficient from any one group’s slope.
  • Calculate fitted values from a group-specific line and verify them in the full model.
  • Reconstruct interaction coefficients from four group-specific lines.
  • Avoid omitting lower-order terms when expanding a three-way model.

Why Expand a Three-Way Model?

A regression model with two binary group variables and a three-way interaction can be compact on paper but difficult to interpret coefficient by coefficient. Expanding it into four lines makes the fitted relationship between a quantitative predictor and the outcome explicit for every combination of the two groups. Each line has an intercept and a slope, so the group-specific predictions can be read directly.

The key task is substitution: set each group indicator to 0 or 1, simplify the model, and collect the constant terms and the terms multiplied by the predictor. This tutorial focuses on that algebra. It does not require a test of whether the three-way interaction is present.

The Model and Its Assumptions

Let \(X\) be a quantitative predictor, and let \(A\) and \(B\) be binary indicators, each coded 0 for its reference category and 1 for its other category. For observation \(i\), consider the model

$$ Y_i = \beta_0 + \beta_1 X_i + \beta_2 A_i + \beta_3 B_i + \beta_4 A_iB_i + \beta_5 X_iA_i + \beta_6 X_iB_i + \beta_7 X_iA_iB_i + \varepsilon_i. $$

The model includes the main effects, the two-way interactions, and the three-way interaction. The term \(\beta_7 X_iA_iB_i\) allows the effect of \(X\) to differ across combinations of \(A\) and \(B\), beyond the changes represented by the lower-order terms. The \(\beta\) values are model coefficients, and \(\varepsilon_i\) is the error for observation \(i\).

Model conditions for this expansion: The indicators \(A\) and \(B\) take only the values 0 and 1, and the conditional mean is represented by the stated model. In particular, \(E(\varepsilon_i \mid X_i,A_i,B_i)=0\), so the linear predictor describes the conditional mean of \(Y_i\). Within each of the four group combinations, the conditional mean is linear in \(X\). The substitution and simplification below are algebraic and do not require normally distributed errors.

The intercept in a group-specific line is the model’s fitted conditional mean at \(X=0\) for that group combination. The slope is the change in fitted conditional mean for a one-unit increase in \(X\), holding the group combination fixed. The intercept therefore refers to \(X=0\), which may or may not be a practically meaningful predictor value.

Deriving the Four Group-Specific Lines

To obtain each line, substitute the relevant values of \(A\) and \(B\). Terms containing a zero indicator disappear. Terms with \(X\) are collected into the slope; terms without \(X\) are collected into the intercept.

1
Set \(A=0\) and \(B=0\).
All group terms and interactions vanish, leaving the reference-group intercept and slope.
2
Set \(A=1\) and \(B=0\).
Keep terms containing \(A\), while terms containing \(B\) vanish.
3
Set \(A=0\) and \(B=1\).
Keep terms containing \(B\), while terms containing \(A\) vanish.
4
Set \(A=1\) and \(B=1\).
All terms remain; collect the four constant contributions and the four contributions multiplied by \(X\).

The first combination, \(A=0,B=0\), gives

$$ E(Y\mid X,A=0,B=0) = \beta_0 + \beta_1 X. $$

For \(A=1,B=0\), the terms involving \(B\) are zero, so

$$ E(Y\mid X,A=1,B=0) = (\beta_0+\beta_2) + (\beta_1+\beta_5)X. $$

For \(A=0,B=1\), the terms involving \(A\) are zero:

$$ E(Y\mid X,A=0,B=1) = (\beta_0+\beta_3) + (\beta_1+\beta_6)X. $$

Finally, when \(A=1,B=1\), both indicators and their product equal 1:

$$ E(Y\mid X,A=1,B=1) = (\beta_0+\beta_2+\beta_3+\beta_4) +(\beta_1+\beta_5+\beta_6+\beta_7)X. $$

These are conditional-mean lines. For a fitted model, use the estimated coefficients in the same expressions. Thus, for example, the fitted line for \(A=1,B=1\) has intercept \(\hat{\beta}_0+\hat{\beta}_2+\hat{\beta}_3+\hat{\beta}_4\) and slope \(\hat{\beta}_1+\hat{\beta}_5+\hat{\beta}_6+\hat{\beta}_7\).

Group combinationInterceptSlope of \(X\)
\(A=0,B=0\)\(\beta_0\)\(\beta_1\)
\(A=1,B=0\)\(\beta_0+\beta_2\)\(\beta_1+\beta_5\)
\(A=0,B=1\)\(\beta_0+\beta_3\)\(\beta_1+\beta_6\)
\(A=1,B=1\)\(\beta_0+\beta_2+\beta_3+\beta_4\)\(\beta_1+\beta_5+\beta_6+\beta_7\)

Worked Examples

Worked Example: Expanding Coefficients Into Four Lines

Suppose a hypothetical model predicts a laboratory measurement \(Y\), in units, from \(X\), the number of hours since a procedure. Let \(A=1\) indicate Method A rather than the reference method, and let \(B=1\) indicate Setting B rather than the reference setting. Assume the fitted coefficients are \(\hat{\beta}_0=12\), \(\hat{\beta}_1=1.5\), \(\hat{\beta}_2=4\), \(\hat{\beta}_3=-3\), \(\hat{\beta}_4=2\), \(\hat{\beta}_5=0.8\), \(\hat{\beta}_6=-0.4\), and \(\hat{\beta}_7=1.2\). Find all four fitted lines.

For \(A=0,B=0\), the intercept is \(12\) units and the slope is \(1.5\) units per hour:

$$ \widehat{Y}=12+1.5X. $$

For \(A=1,B=0\), add \(\hat{\beta}_2\) to the intercept and \(\hat{\beta}_5\) to the slope:

$$ \widehat{Y}=(12+4)+(1.5+0.8)X=16+2.3X. $$

For \(A=0,B=1\), add \(\hat{\beta}_3\) to the intercept and \(\hat{\beta}_6\) to the slope:

$$ \widehat{Y}=(12-3)+(1.5-0.4)X=9+1.1X. $$

For \(A=1,B=1\), include all relevant terms:

$$ \begin{aligned} \text{Intercept} &= 12+4-3+2=15,\\ \text{Slope} &= 1.5+0.8-0.4+1.2=3.1,\\ \widehat{Y} &= 15+3.1X. \end{aligned} $$

The four slopes are therefore \(1.5\), \(2.3\), \(1.1\), and \(3.1\) units per hour in the listed group combinations. These are fitted changes per hour, not automatically causal effects of changing the method or setting.

Worked Example: Checking a Prediction in Two Ways

Consider a second hypothetical fitted model for an outcome measured in milligrams. Let \(X\) be a dose in milligrams, \(A=1\) denote Program A rather than the reference program, and \(B=1\) denote Clinic B rather than the reference clinic. Suppose the coefficients are \(\hat{\beta}_0=20\), \(\hat{\beta}_1=2\), \(\hat{\beta}_2=-5\), \(\hat{\beta}_3=3\), \(\hat{\beta}_4=1\), \(\hat{\beta}_5=0.5\), \(\hat{\beta}_6=-0.25\), and \(\hat{\beta}_7=-0.75\). Find the fitted outcome at dose \(X=8\) for Program A in Clinic B.

First obtain the line for \(A=1,B=1\). Its intercept is \(20-5+3+1=19\) milligrams. Its slope is \(2+0.5-0.25-0.75=1.5\) milligrams per milligram of dose. Therefore,

$$ \widehat{Y}=19+1.5X, \qquad \widehat{Y}(8)=19+1.5(8)=19+12=31\text{ mg}. $$

Check the same result in the original model by substituting \(X=8,A=1,B=1\):

$$ 20+2(8)-5+3+1+0.5(8)-0.25(8)-0.75(8) =20+16-5+3+1+4-2-6 =31\text{ mg}. $$

The two calculations agree. This is a useful check when expanding a model: each group-specific line should give the same prediction as direct substitution into the full model.

Worked Example: Recovering Coefficients From Four Lines

Suppose four hypothetical fitted lines, with \(A=0,B=0\) as the reference combination, are reported as follows:

$$ \begin{aligned} A=0,B=0 &: \quad \widehat{Y}=50+2X,\\ A=1,B=0 &: \quad \widehat{Y}=56+3X,\\ A=0,B=1 &: \quad \widehat{Y}=47+1X,\\ A=1,B=1 &: \quad \widehat{Y}=60+5X. \end{aligned} $$

Find the coefficients in the full binary-indicator model. The reference line gives \(\hat{\beta}_0=50\) and \(\hat{\beta}_1=2\). Comparing the \(A=1,B=0\) line with the reference line gives \(\hat{\beta}_2=56-50=6\) and \(\hat{\beta}_5=3-2=1\). Comparing the \(A=0,B=1\) line with the reference gives \(\hat{\beta}_3=47-50=-3\) and \(\hat{\beta}_6=1-2=-1\).

For the \(A=1,B=1\) line, the intercept formula is \(60=\hat{\beta}_0+\hat{\beta}_2+\hat{\beta}_3+\hat{\beta}_4\). Thus,

$$ \hat{\beta}_4=60-50-6-(-3)=7. $$

Its slope formula is \(5=\hat{\beta}_1+\hat{\beta}_5+\hat{\beta}_6+\hat{\beta}_7\). Therefore,

$$ \hat{\beta}_7=5-2-1-(-1)=3. $$

The recovered coefficients are \(\hat{\beta}_0=50\), \(\hat{\beta}_1=2\), \(\hat{\beta}_2=6\), \(\hat{\beta}_3=-3\), \(\hat{\beta}_4=7\), \(\hat{\beta}_5=1\), \(\hat{\beta}_6=-1\), and \(\hat{\beta}_7=3\). Substitution into the four formulas reproduces each supplied line.

What the Three-Way Term Contributes

The three-way coefficient \(\beta_7\) appears only in the slope for \(A=1,B=1\). It is not, by itself, that group’s slope: the full slope is \(\beta_1+\beta_5+\beta_6+\beta_7\). Nor is \(\beta_7\) the slope difference between the \(A=1,B=1\) group and the reference group; that difference is \(\beta_5+\beta_6+\beta_7\).

To see why \(\beta_7\) is a higher-order adjustment, compare the change in slope associated with \(A\) across the two values of \(B\). When \(B=0\), changing \(A\) changes the slope by \(\beta_5\). When \(B=1\), it changes the slope by \(\beta_5+\beta_7\). The difference between those two slope changes is \(\beta_7\). This follows directly from the four slopes:

$$ \big[(\beta_1+\beta_5+\beta_6+\beta_7)-(\beta_1+\beta_6)\big] -\big[(\beta_1+\beta_5)-\beta_1\big] =\beta_7. $$

This algebraic interpretation depends on the stated 0/1 coding. Changing which category is coded 0 changes the coefficient interpretation and the displayed formulas, while the fitted predictions for the observations remain the relevant quantities.

Common Mistakes and Why the Expansion Matters

  • Reading a coefficient as a whole group-specific slope. The coefficient \(\beta_5\), for example, is only an adjustment to the reference slope for \(A=1,B=0\). That group’s slope is \(\beta_1+\beta_5\).
  • Forgetting the two-way interaction in the \(A=1,B=1\) intercept. The intercept includes \(\beta_4\), because \(AB=1\) in that cell. The slope does not include \(\beta_4\), because it is not multiplied by \(X\).
  • Leaving out lower-order terms. The three-way term is part of a model that also includes the corresponding main effects and two-way interactions. Omitting any of them changes the four line formulas.
  • Interpreting the intercept at the wrong predictor value. Each intercept is the fitted mean at \(X=0\), not at the sample mean of \(X\), unless \(X\) was centered so that zero represents that mean.

Expanding the model matters because the coefficients alone can be easy to misread, while the four lines reveal the actual fitted intercept and slope in every cell. They also make it possible to calculate and check predictions transparently. Keep the coding of \(A\) and \(B\) explicit, collect constant and \(X\)-multiplied terms separately, and verify at least one prediction by substituting into the original model.

Check Your Understanding

Use the full model and the 0/1 coding defined above.

  1. Write the intercept and slope for the group combination \(A=0,B=1\).
  2. In the \(A=1,B=1\) line, which coefficient contributes through the product \(AB\) to the intercept?
  3. If \(\beta_1=3\), \(\beta_5=2\), \(\beta_6=-1\), and \(\beta_7=0.5\), what is the slope for \(A=1,B=1\)?
  4. Explain why \(\beta_7\) is not generally equal to the slope for \(A=1,B=1\).
  5. For the model in the first worked example, verify the \(A=1,B=1\) prediction at \(X=2\) by using its fitted line.