Tutorials › Generalized Linear Models › Nested Models for Assessing Interaction Terms

Factors Contrasts and Interactions · Tutorial 154 of 981

Nested Models for Assessing Interaction Terms

Represent factor interactions as nested model spaces, state the corresponding null constraints, and determine the correct number of added parameters.

Intermediate 10 min read

What You'll Learn

  • Express the addition of a factor interaction as an expansion of the linear-predictor model space
  • State the null hypothesis for an interaction as a block of coefficient constraints
  • Count interaction parameters from the numbers of factor levels
  • Explain why full-rank contrast coding changes coefficients but not the interaction test
  • Distinguish nominal coefficient counts from the rank added to a model
  • Interpret a likelihood-ratio comparison and its degrees of freedom

Why Compare Nested Models?

A factor interaction asks whether the effect of one factor varies across levels of another. To assess it in a generalized linear model (GLM), compare a model containing the relevant lower-order terms with one that also contains the interaction. The comparison is meaningful when the models use the same observations, response distribution, and link, and when the smaller model is nested in the larger one.

The key object is the linear-predictor space: the set of possible vectors of linear predictors on the observations. Adding an interaction adds columns to the model matrix and can enlarge this space. The interaction null hypothesis says that the added part is unnecessary. Its degrees of freedom are determined by how many independent dimensions the interaction adds, not merely by how many coefficient labels appear in a software output.

Definition: Two GLMs are nested if they use the same response observations, response distribution, and link, and every linear predictor allowed by the smaller model is also allowed by the larger model. For design matrices \(X_R\) and \(X_F\) of the reduced and full models, respectively, this means \(\operatorname{col}(X_R)\subseteq\operatorname{col}(X_F)\), where \(\operatorname{col}(X)\) is the column space of \(X\).

The same link is important: the linear predictor \(\eta\) is related to the mean \(\mu\) by \(\eta=g(\mu)\). A comparison that changes the link or the response distribution changes more than the interaction structure. Here, “reduced” means the model without the interaction being assessed, and “full” means the model with it.

The Interaction as a Block of Constraints

Let \(A\) have \(a\) levels and \(B\) have \(b\) levels. Assume \(a,b\geq 2\), and first consider a complete factorial structure with an intercept, both main effects, and their interaction. With full-rank contrast bases for the two factors, write the linear predictor as

$$ \eta = \beta_0 + C_A\alpha + C_B\delta + (C_A\otimes C_B)\gamma. $$

Here, \(C_A\) and \(C_B\) describe contrasts among the levels of \(A\) and \(B\); \(\alpha\) and \(\delta\) are the corresponding main-effect coefficients; and \(\gamma\) is the interaction coefficient block. The expression is schematic for the contribution at each factor-level combination; for multiple observations, the corresponding rows are selected and repeated according to each observation’s factor levels. The reduced model omits the last term. Thus, in this parameterization, the null hypothesis of no \(A\)-by-\(B\) interaction is

$$ H_0:\gamma=0. $$

This is a joint hypothesis: all interaction coefficients in the block are zero. It is not generally a test of one coefficient at a time. In a general design-matrix notation, partition the full model as \(X_F=[X_R\ Z]\), where \(Z\) contains the added interaction columns. The reduced model sets the coefficients of that block to zero. If columns are redundant, the relevant number of constraints is the increase in rank, not the number of columns in \(Z\).

Parameter-count result: For two factors with \(a\) and \(b\) levels, a full-rank interaction between their contrast spaces contributes \((a-1)(b-1)\) parameters. The null hypothesis is the joint restriction of that many interaction dimensions to zero. This count assumes the interaction contributes its full rank; the actual increase is \(\operatorname{rank}(X_F)-\operatorname{rank}(X_R)\).

The count follows because the contrast space for \(A\) has dimension \(a-1\), and that for \(B\) has dimension \(b-1\). The interaction combines every independent contrast for \(A\) with every independent contrast for \(B\), giving \((a-1)(b-1)\) independent products. In a full factorial layout with observations in every combination and an identifiable hierarchical model, this is the number added. If the observed design makes some columns dependent, the rank increase can be smaller; a nominal parameter count alone does not settle the matter.

Worked Examples

Worked Example: A Two-by-Two Logistic Model

Suppose \(A\) and \(B\) are binary factors, coded \(0\) and \(1\), and the response is Bernoulli with a logit link. Consider

$$ \operatorname{logit}(\mu)=\beta_0+\beta_A A+\beta_B B+\gamma AB. $$

The reduced model removes \(\gamma AB\). The factors each have one contrast dimension, so the interaction adds \((2-1)(2-1)=1\) parameter. Under the reduced model, the four linear predictors are \(\beta_0\), \(\beta_0+\beta_A\), \(\beta_0+\beta_B\), and \(\beta_0+\beta_A+\beta_B\). With the interaction, the last predictor also contains \(\gamma\).

Subtracting the predictors gives the difference-in-differences:

$$ \eta_{11}-\eta_{10}-\eta_{01}+\eta_{00} =(\beta_0+\beta_A+\beta_B+\gamma) -(\beta_0+\beta_A) -(\beta_0+\beta_B)+\beta_0 =\gamma. $$

Therefore, the no-interaction null is \(H_0:\gamma=0\), equivalently, that this contrast of the four logits is zero. It is a one-parameter comparison, not four separate tests of the cell logits.

Worked Example: Counting a Three-by-Four Interaction

Factor \(A\) has three levels and factor \(B\) has four. In a full factorial model with an intercept and both main effects, the main-effect dimensions are \(3-1=2\) and \(4-1=3\). The interaction block therefore has

$$ (3-1)(4-1)=2\cdot 3=6 $$

independent parameters, provided the design supports the full factorial model. The reduced model has \(1+2+3=6\) parameters for the predictor structure; the full model has \(6+6=12\). Thus, the interaction test imposes six joint restrictions. This arithmetic concerns the linear-predictor coefficients and does not include any separate dispersion parameter.

The same count holds whether the levels are represented by reference contrasts, effect contrasts, or another full-rank contrast basis. The coefficient values and their interpretation can change with the basis, but the dimension of the interaction space does not.

Worked Example: Using the Increment in Log Likelihood

Suppose the reduced and full models for a complete three-by-four factorial design are fitted to the same independent Bernoulli observations with the same link. Their maximized log likelihoods are \(-128.4\) and \(-121.1\), respectively. The interaction adds six dimensions, so the likelihood-ratio statistic is

$$ 2\{\ell_F-\ell_R\} =2\{-121.1-(-128.4)\} =2(7.3) =14.6. $$

Under the null and the usual regularity conditions for the likelihood-ratio test—identifiable parameters, an interior null parameter, nonsingular information, and fixed model dimension—the statistic is approximately chi-square with six degrees of freedom. For six degrees of freedom, the upper-tail probability at 14.6 is about \(0.024\). This gives evidence against the joint no-interaction null at the 5% level, under those assumptions. The degrees of freedom come from the six added interaction dimensions, not from the total number of parameters in the full model.

Why Contrast Coding Does Not Change the Comparison

A contrast basis is a coordinate system for representing differences among factor levels. If \(C_A'\) is another full-rank basis for the same contrast space as \(C_A\), there is an invertible matrix \(R_A\) such that \(C_A'=C_A R_A\). Likewise, \(C_B'=C_B R_B\), with \(R_B\) invertible. The interaction basis then satisfies

$$ C_A'\otimes C_B' =(C_A\otimes C_B)(R_A\otimes R_B). $$

Since \(R_A\otimes R_B\) is invertible, the columns of the new interaction basis span the same space as the old ones. A change of coordinates can alter the coefficient vector, but it cannot alter the set of interaction contributions allowed by the model. Consequently, the fitted linear-predictor space, the nested-model comparison, and the full-rank interaction dimension are unchanged.

Result: Replacing full-rank contrast bases by other bases for the same factor contrast spaces preserves the interaction model space and its dimension. The hypothesis of no interaction is the same restriction on the fitted model space, even though its coefficient coordinates may differ.

This invariance applies when the bases genuinely span the same factor contrast spaces and the model includes the corresponding main effects. It does not mean that every individual coefficient has the same scientific interpretation under every coding. The joint interaction test concerns the block; interpreting a particular coefficient requires knowing the chosen contrasts.

Proving the Nested-Space and Degrees-of-Freedom Claims

The reduced model is obtained from the full model by setting the added interaction coefficients to zero. Every reduced-model predictor is therefore a full-model predictor, which proves \(\operatorname{col}(X_R)\subseteq\operatorname{col}(X_F)\). To find how many dimensions are added, extend a basis of \(\operatorname{col}(X_R)\) to a basis of \(\operatorname{col}(X_F)\). The number of added basis vectors is the difference in the dimensions of these spaces:

$$ \dim\{\operatorname{col}(X_F)\} -\dim\{\operatorname{col}(X_R)\} =\operatorname{rank}(X_F)-\operatorname{rank}(X_R). $$

That difference is the number of independent predictor directions supplied by the interaction. In a full-rank factorial model, the product contrast basis has \((a-1)(b-1)\) independent columns, so the rank increases by exactly that amount. If some added columns lie in the reduced space or are linearly dependent on other added columns, they add no new dimension; the rank difference automatically accounts for this. This establishes why the degrees of freedom for a regular nested-model test equal the rank increment. \(\square\)

1
Specify the reduced model.
Include the intercept and the main effects required by the interaction structure.
2
Add the interaction block.
Keep the observations, response distribution, and link the same, and include the interaction columns in the full model.
3
State the joint null.
Set the added interaction coefficient block to zero, or express the equivalent restriction in the chosen parameterization.
4
Determine the dimension added.
For a full-rank two-factor interaction use \((a-1)(b-1)\); otherwise use \(\operatorname{rank}(X_F)-\operatorname{rank}(X_R)\).
5
Compare the models.
Use a suitable nested-model statistic and its corresponding degrees of freedom, checking that the test’s regularity assumptions apply.

Common Mistakes and Practical Interpretation

  • Testing interaction coefficients one at a time. A no-interaction hypothesis is a joint restriction on the whole block. Individual coefficient tests do not replace the block comparison.
  • Counting factor levels instead of contrasts. A factor with \(a\) levels contributes \(a-1\) main-effect dimensions when an intercept is present. The two-factor interaction count is the product of the contrast dimensions, not \(ab\).
  • Assuming the printed number of columns equals the degrees of freedom. Redundant columns do not increase the model-space dimension. Use the rank increment when the design is not full rank.
  • Assuming a coefficient has a coding-free interpretation. Coefficients depend on the contrast basis. The interaction block test is invariant under a valid change of basis, but the meaning of an individual coordinate can change.
  • Comparing models that differ in more than the interaction. A likelihood-ratio comparison of this kind requires the same response data and distributional specification; otherwise the change in fit cannot be attributed solely to the interaction.

Assessing an interaction is therefore both a modeling and a dimension-counting task. The test asks whether the larger predictor space is needed, while its degrees of freedom count the new independent directions. In a full factorial model, contrast coding provides convenient coordinates for those directions; the underlying model-space comparison is the same.

Check Your Understanding

For each question, distinguish the coefficient coordinates from the model-space dimensions.

  1. Factors \(A\) and \(B\) have five and two levels. How many interaction parameters are added in a full-rank factorial model?
  2. For a two-by-two logistic model with reference coding, what coefficient restriction represents no interaction?
  3. Why can two contrast codings produce different interaction coefficient values but the same nested-model comparison?
  4. A design matrix has four nominal interaction columns, but adding them increases the full-model rank by only three. What degrees of freedom does the interaction add?
  5. Name two conditions that should be held fixed when comparing reduced and full GLMs to assess an interaction.
Clinical Biostats