What an Interaction Test Asks
An interaction allows the association of one predictor with the response to vary according to another predictor. Testing an interaction therefore asks whether that variation improves the model’s fit, given the main effects already included. The comparison is between a model containing those main effects and an otherwise corresponding model that also contains the interaction block.
For example, a treatment effect might differ by patient subgroup. A model with treatment and subgroup main effects allows each to be associated with the response, but assumes a common treatment effect across subgroups on the model’s linear-predictor scale. Adding their interaction relaxes that assumption. The scale matters: in a logistic GLM, this is variation in log odds, not necessarily variation in risk differences.
The null hypothesis is about a block of coefficients, not one coefficient chosen in isolation. For a two-factor interaction between categorical predictors, the block usually has several coefficients, and the test asks whether they are jointly zero. The main-effects terms remain in both models.
Interaction Coefficients Depend on the Main Effects
Consider a binary response with two binary predictors \(A\) and \(B\), each coded 0 or 1. A logistic regression with an interaction is
When \(B=0\), the change in log odds for a one-unit change in \(A\) is \(\beta_A\). When \(B=1\), it is \(\beta_A+\gamma\). Thus \(\gamma\) measures how the \(A\) effect on the log-odds scale changes as \(B\) changes. The no-interaction null is \(H_0:\gamma=0\).
Worked Example: Interpreting a Binary-Predictor Interaction
Suppose the fitted model is \(\operatorname{logit}\{P(Y=1\mid A,B)\}=-2+0.8A+0.5B+0.6AB\). Compare the effect of \(A\) at the two levels of \(B\).
At \(B=0\), the coefficient of \(A\) in the linear predictor is \(0.8\). The corresponding conditional odds ratio for changing \(A\) from 0 to 1 is \(\exp(0.8)\approx 2.226\).
At \(B=1\), the \(A\) terms are \(0.8A+0.6A=1.4A\). The conditional odds ratio is therefore \(\exp(1.4)\approx 4.055\). The interaction coefficient is the difference between these log odds ratios, \(1.4-0.8=0.6\), or equivalently the log of their ratio: \(\log\{4.055/2.226\}\approx 0.6\). The ratio of odds ratios is \(\exp(0.6)\approx 1.822\).
The coefficient \(0.6\) does not give the overall effect of \(A\); it gives the change in that effect across \(B\). Testing for interaction means testing whether that change is zero while retaining the \(A\) and \(B\) main effects.
With treatment-reference coding, a main-effect coefficient is typically the effect at the reference level of the other factor. Changing the reference level changes the individual coefficient values, but it does not change the fitted model or the joint hypothesis that the entire interaction block is zero, provided the same model spaces are represented. A sound interpretation describes the comparison and its scale rather than assigning a universal meaning to one coded coefficient.
Degrees of Freedom for Categorical Interactions
Suppose \(A\) has \(p\) levels and \(B\) has \(q\) levels, and every combination of levels is represented so that all cell means are estimable. A model with an intercept and both main effects has \(1+(p-1)+(q-1)\) parameters for these factors. A model allowing a separate linear-predictor value for each of the \(pq\) cells has \(pq\) parameters. The added interaction block therefore has
degrees of freedom. This count assumes a full-rank design for the cells; empty or otherwise nonestimable combinations can reduce the rank. More generally, the relevant degrees of freedom are the difference in the ranks of the two model design matrices, not simply the number of columns typed into a formula.
Worked Example: Counting a Factorial Interaction Block
A study models a response using a three-level treatment factor and a four-level site factor. Assume all 12 treatment-by-site combinations are represented and estimable. The reduced model contains an intercept and both main effects; the larger model adds their interaction.
The treatment main effect contributes \(3-1=2\) parameters, and the site main effect contributes \(4-1=3\). With the intercept, the reduced model has \(1+2+3=6\) parameters for these terms. The full cell-means model has \(3\times4=12\) parameters. The interaction adds \(12-6=6\) parameters, also given directly by \((3-1)(4-1)=2\times3=6\).
The joint null hypothesis thus imposes six restrictions. Under the regularity conditions for the large-sample likelihood-ratio test, the reference distribution is chi-square with six degrees of freedom, not one degree of freedom merely because the formula displays one interaction symbol.
Deviance Difference and Likelihood-Ratio Test
Let \(\ell_0(\hat\theta_0)\) and \(\ell_1(\hat\theta_1)\) be the maximized log-likelihoods under the reduced and larger models, respectively. For a likelihood-ratio deviance defined on this same likelihood scale, the test statistic is
The larger model contains the reduced model, so its maximized likelihood cannot be smaller. Hence \(G^2\geq0\). If \(D_0\) and \(D_1\) denote the deviances from the same saturated model, then \(D_j=2\{\ell_{\mathrm{sat}}-\ell_j(\hat\theta_j)\}\). Subtracting gives the following identity.
To verify the identity, substitute the two deviance definitions:
The saturated-model terms cancel, which proves the result. The identity is exact under the stated deviance definition; the chi-square calibration is an asymptotic claim, not an exact consequence of the subtraction.
If the null model is true, the interaction restrictions are identifiable and regular, the true parameter is an interior point, and the Fisher information is nonsingular, Wilks’ theorem gives an asymptotic chi-square reference distribution. For \(r\) independent restrictions, \(G^2\xrightarrow{d}\chi^2_r\). In GLM applications this requires an appropriate large-sample regime, such as independent observations with regular, identifiable models and information increasing in the tested directions. The degrees of freedom \(r\) are the rank difference between the larger and reduced model. Sparse data, boundary parameters, or nonidentifiability can invalidate this standard calibration.
Worked Deviance Test for a Two-Factor Interaction
For a concrete calculation, consider independent Poisson counts in four cells. A loglinear model with both factor main effects but no interaction asserts that the expected count in each cell is determined by an overall level and the two separate factor effects. Adding the interaction permits a general mean for each cell.
Worked Example: Testing Independence in a Two-by-Two Poisson Table
Suppose the observed counts are
| Column 1 | Column 2 | Row total | |
|---|---|---|---|
| Row 1 | 12 | 8 | 20 |
| Row 2 | 6 | 14 | 20 |
| Column total | 18 | 22 | 40 |
The reduced loglinear model has an intercept and row and column main effects. Its fitted counts are the products of the corresponding row and column totals divided by the grand total. The four fitted counts are \(20(18)/40=9\), \(20(22)/40=11\), \(20(18)/40=9\), and \(20(22)/40=11\).
The larger model adds the row-by-column interaction. With all four cells estimable, it is saturated for these four means, so its fitted counts equal the observations. The interaction block has \((2-1)(2-1)=1\) degree of freedom.
Using the Poisson likelihood-ratio deviance, the difference is
For example, the four contributions inside the braces are approximately \(3.4522\), \(-2.5476\), \(-2.4328\), and \(3.3763\), which sum to \(1.8480\); doubling gives \(3.6961\). Under the regular chi-square approximation, this is compared with a \(\chi^2_1\) distribution, giving a two-sided upper-tail \(p\)-value of approximately \(0.055\). At a 5% significance level, this result does not reject the no-interaction model. It is evidence about whether row and column effects combine additively on the log-mean scale, not a proof that the interaction is exactly zero.
Why Main Effects Stay in the Comparison
The interaction test is conditional on the main-effects structure. If a treatment-by-subgroup interaction is added while treatment and subgroup main effects remain, the test asks whether the treatment association varies by subgroup beyond their separate contributions. Removing a main effect at the same time changes the comparison: the larger and reduced models no longer differ only by the interaction block.
This matters especially for reference-coded factors. An interaction coefficient can depend on which levels are used as references, and a model that includes an interaction but omits a corresponding main effect can impose restrictions that change under a recoding. Keeping the relevant main effects gives the usual hierarchical comparison and makes the joint no-interaction hypothesis a comparison of the same substantive model spaces under different full-rank codings.
Common Pitfall
Incorrect reasoning: “The formula has one interaction term, so the test has one degree of freedom.” This is generally false for factors with more than two levels: one factor interaction can represent a whole block of parameters.
Correction: Determine the rank added by the interaction design columns. With full crossing of factors having \(p\) and \(q\) levels, the interaction contributes \((p-1)(q-1)\) degrees of freedom. For other designs, compare the ranks of the fitted model matrices. Also verify that the reduced model retains the main effects whose interaction is being tested.
Check Your Understanding
Answer each question by identifying the model comparison and the scale of the claim.
- In a logistic model with binary \(A\) and \(B\), what does the coefficient of \(AB\) measure when both main effects are included?
- A factor with four levels interacts with a factor with two levels. Under full crossing and full estimability, how many degrees of freedom does their interaction add?
- Why is the difference between the reduced-model deviance and the larger-model deviance nonnegative?
- In the Poisson table example, what null hypothesis is represented by the model with row and column main effects but no interaction?
- Why can dropping a main effect while adding an interaction make the resulting test difficult to interpret as a test of interaction alone?