Tutorials › Regression Analysis (Undergraduate) › Testing a Three-Way Slope Interaction

Interactions Among Groups · Tutorial 361 of 991

Testing a Three-Way Slope Interaction

Learn to compare full and reduced group-slope models to test whether slope contrasts change across combinations of two categorical factors.

Intermediate 10 min read

What You'll Learn

  • Write the three-way slope-interaction term in a model with a continuous predictor and two categorical factors.
  • Express the null hypothesis as restrictions that remove only the three-way slope interaction.
  • Calculate a partial F statistic from the full and reduced models’ residual sums of squares.
  • Extend the test to factors with more than two levels using a joint test of multiple restrictions.
  • Interpret rejection and non-rejection in terms of whether slope contrasts vary across groups.

Why Test a Three-Way Slope Interaction?

Suppose an outcome is related to a quantitative predictor, such as treatment dose, and the dose–outcome relationship may differ across two categorical factors, such as clinic and treatment type. The key question is not merely whether the groups have different fitted outcomes. It is whether a contrast between slopes for one factor changes across the levels of the other factor.

A three-way slope-interaction test addresses that question by comparing a full model, which allows the slope contrasts to vary across combinations of the factors, with a reduced model that does not. The test concerns the slope structure specifically. It does not, by itself, test whether group intercepts differ or whether any two-way interaction is absent.

Model and Null Hypothesis

Begin with two binary factors, coded as indicators \(A\) and \(B\), and a quantitative predictor \(x\). Let \(A=0\) and \(B=0\) denote the reference categories, and let \(Y\) be the outcome. A hierarchical model containing all terms up to the three-way interaction is

$$ Y_i=\beta_0+\beta_1x_i+\beta_2A_i+\beta_3B_i+\beta_4A_iB_i+\beta_5x_iA_i+\beta_6x_iB_i+\beta_7x_iA_iB_i+\varepsilon_i. $$

The group-specific slopes with respect to \(x\) are \(\beta_1\) for \(A=0,B=0\), \(\beta_1+\beta_5\) for \(A=1,B=0\), \(\beta_1+\beta_6\) for \(A=0,B=1\), and \(\beta_1+\beta_5+\beta_6+\beta_7\) for \(A=1,B=1\). Thus, \(\beta_7\) measures how the slope contrast between the two \(A\) groups changes when moving from \(B=0\) to \(B=1\).

Definition: A three-way slope interaction is the change in a slope contrast for one categorical factor across levels of a second categorical factor. With two binary factors under reference-indicator coding, the three-way slope-interaction coefficient is \(\beta_7\). Testing whether this interaction is absent means testing \(H_0:\beta_7=0\).

The same null can be written directly using the four slopes. It states that the difference between the \(A\)-group slopes is the same at both levels of \(B\):

$$ H_0:\{s_{11}-s_{01}\}-\{s_{10}-s_{00}\}=0, \qquad H_a:\{s_{11}-s_{01}\}-\{s_{10}-s_{00}\}\ne 0. $$

Here \(s_{ab}\) is the slope for the group with \(A=a\) and \(B=b\). Substituting the model’s slopes into the contrast gives \(\beta_7\), so these hypotheses are equivalent to \(H_0:\beta_7=0\) and \(H_a:\beta_7\ne0\).

The reduced model under this null retains the intercept terms, the \(A:B\) term, the main slope for \(x\), and both two-way slope terms \(x:A\) and \(x:B\). It removes only \(x:A:B\). In particular, testing for no three-way slope interaction does not require equal slopes across all four groups.

Joint Tests for Factors With More Levels

When either categorical factor has more than two levels, the three-way slope interaction is represented by multiple coefficients. Suppose \(A\) has \(J\) levels and \(B\) has \(K\) levels. Under ordinary reference-category coding, the model has \((J-1)(K-1)\) three-way slope-interaction coefficients. The null hypothesis sets all of them to zero jointly.

Key result: For factors with \(J\) and \(K\) levels, removing the three-way slope interaction imposes \(q=(J-1)(K-1)\) restrictions. The null says that slope contrasts across levels of one factor do not vary across levels of the other factor. A joint test is needed; testing one coefficient at a time does not test this full null.

The precise coefficient names depend on the coding used for the factors, but the null describes the same fitted-model restriction: the slope contrasts have no additional variation across the two factors beyond the lower-order slope terms. The test must retain those lower-order terms in both models.

The Partial F Test

Fit the full model with the three-way slope interaction and the reduced model without it, using the same observations in both. Let \(SSE_F\) and \(SSE_R\) be their residual sums of squares, respectively, and let \(p_F\) be the number of coefficients estimated in the full model, including the intercept. If the null imposes \(q\) restrictions, the partial F statistic is

$$ F=\frac{(SSE_R-SSE_F)/q}{SSE_F/(n-p_F)}. $$

The numerator measures the reduction in residual sum of squares per restriction when the three-way terms are added. The denominator estimates the error variance using the full model. Under the null hypothesis, the statistic has an \(F\) distribution with \(q\) and \(n-p_F\) degrees of freedom, provided the model assumptions hold. A large value is evidence against the restrictions.

For an exact small-sample F test, assume that the conditional mean is represented by the full linear model, the design values are fixed (or treated as fixed), and the errors are independent with a common variance and normally distributed with mean zero. Equivalently, the errors satisfy \(\varepsilon_i\sim N(0,\sigma^2)\) independently. These assumptions are needed for the stated exact reference distribution. In practice, study design and residual diagnostics inform whether independence, linearity, constant variance, and approximate normality are plausible; a calculated test cannot repair a serious violation.

Why the Partial F Statistic Has This Form

The two models are nested: every fitted mean allowed by the reduced model is also allowed by the full model. Adding the three-way terms can therefore not increase the residual sum of squares, so \(SSE_R-SSE_F\) is nonnegative. Under the null, the added terms explain only random error, on average. Dividing their extra fit by the number of restrictions gives a quantity on the same variance scale as the full model’s residual mean square.

More formally, under the normal-error assumptions and the null, the extra sum of squares divided by \(\sigma^2\) has a chi-square distribution with \(q\) degrees of freedom. The full-model residual sum of squares divided by \(\sigma^2\) has a chi-square distribution with \(n-p_F\) degrees of freedom, and these quantities are independent because they come from orthogonal components of the fitted linear model. Their ratio, each divided by its degrees of freedom, has the \(F\) distribution shown above. This explains both the numerator and denominator and why the denominator degrees of freedom come from the full model.

Worked Example: Testing One Three-Way Coefficient

Consider hypothetical data on \(n=36\) people. The outcome is symptom score in points, \(x\) is dose in milligrams, and \(A\) and \(B\) are binary group factors. Suppose the full model has \(p_F=8\) coefficients, with \(SSE_F=120\) points squared, while the reduced model without \(x:A:B\) has \(SSE_R=150\) points squared. Assume the hypothetical study has independent observations and that checks support the linear mean, common-variance, and normal-error assumptions.

With two binary factors, removing the three-way slope interaction imposes one restriction, so \(q=1\). The statistic is

$$ F=\frac{(150-120)/1}{120/(36-8)} =\frac{30}{120/28} =\frac{30}{4.2857} =7.000. $$

The degrees of freedom are \(1\) and \(28\). The upper-tail p-value is approximately \(0.013\). At significance level \(\alpha=0.05\), reject \(H_0\). These hypothetical data provide evidence that the dose-slope contrast between the \(A\) groups differs between the two \(B\) groups. The result does not establish that dose causes a change in symptoms, and it does not say which particular group slopes differ without further estimates or contrasts.

Worked Example: A Joint Test With Three Levels in One Factor

Suppose a hypothetical analysis compares three regions (\(A\)) and two program types (\(B\)), with a quantitative predictor \(x\) measured in hours and outcome \(Y\) measured in points. The full model allows a separate intercept and slope for each of the six region-by-program combinations. Assume \(n=48\), \(SSE_F=210\), and \(SSE_R=270\), where the reduced model removes only the three-way slope interaction. The full model uses 12 coefficients: six intercept degrees of freedom across cells and six slope degrees of freedom. Assume the errors are independent and the other linear-model assumptions are plausible.

Here \(J=3\) and \(K=2\), so the number of restrictions is \(q=(3-1)(2-1)=2\). The reduced model has 10 coefficients. The test statistic is

$$ F=\frac{(270-210)/2}{210/(48-12)} =\frac{30}{210/36} =\frac{30}{5.8333} =5.143. $$

This is compared with an \(F\) distribution with \(2\) and \(36\) degrees of freedom. The upper-tail p-value is approximately \(0.011\), so at \(\alpha=0.05\) the joint null is rejected. The data provide evidence that the region-related slope contrasts vary across the two program types. Because the null was joint, this conclusion concerns the set of two restrictions together; it does not identify which region contrast is responsible.

Worked Example: Non-Rejection Is Not Proof of No Interaction

In another hypothetical study, let \(n=40\), with the same two binary factors and an outcome measured in kilograms. Suppose the full model has \(p_F=8\), \(SSE_F=82\) kilograms squared, and the reduced model has \(SSE_R=84\) kilograms squared. Assume independent observations and that checks do not reveal serious departures from the linear-model assumptions.

There is one restriction, and the residual degrees of freedom are \(40-8=32\). Thus,

$$ F=\frac{(84-82)/1}{82/32} =\frac{2}{2.5625} =0.7805. $$

The p-value from an \(F\) distribution with \(1\) and \(32\) degrees of freedom is approximately \(0.384\). Since this exceeds \(0.05\), do not reject \(H_0\). The analysis does not provide strong evidence that the slope contrast varies across \(B\) groups. It does not prove that the true three-way interaction is exactly zero: a small interaction, limited sample size, or noisy outcomes could make the test fail to detect it.

Common Mistakes and Practical Interpretation

  • Removing too many terms. The null removes the three-way slope terms, not all slope interactions and not the \(A:B\) intercept interaction. Keep the lower-order terms in the reduced model.
  • Testing coefficients separately when the null is joint. With factors having more than two levels, the restrictions must be tested together. A collection of individual tests is not the same as the partial F test.
  • Calling a large p-value evidence that the null is true. Non-rejection means the data do not provide sufficient evidence against the specified restrictions at the chosen \(\alpha\); it is not proof of no interaction.
  • Interpreting rejection too broadly. Rejection supports a change in slope contrasts across factor levels. It does not necessarily mean every group slope differs from every other slope.
  • Comparing models fit to different observations. The full and reduced models must use the same response observations for this nested-model comparison.

This test is useful when the scientific question concerns whether group-related changes in a predictor’s association with the outcome depend on another grouping factor. Its conclusion is about the pattern of conditional slopes represented by the model, with interpretation limited to the predictor ranges and groups represented in the data.

Check Your Understanding

Answer each question using the model and test definitions above.

  1. With two binary factors, what slope contrast does the coefficient of \(x:A:B\) represent?
  2. Why does the reduced model retain \(x:A\) and \(x:B\) when testing for the three-way slope interaction?
  3. If \(A\) has four levels and \(B\) has three levels, how many restrictions are imposed by removing their three-way slope interaction?
  4. For a nested-model test, what quantities determine the numerator and denominator degrees of freedom?
  5. In context, what can be concluded when the test fails to reject the null hypothesis?