Tutorials › Generalized Linear Models › Odds Ratios as Loglinear Interactions

Poisson Loglinear Models · Tutorial 457 of 981

Odds Ratios as Loglinear Interactions

See how loglinear interaction contrasts encode cross-product odds ratios, and practise calculating and interpreting them in two-way tables.

Intermediate 10 min read

What You'll Learn

  • Define the cross-product odds ratio for a two-by-two subtable of positive cell means.
  • Derive why its logarithm is a difference of log means that cancels row and column effects.
  • Interpret the reference-cell interaction parameter in a two-by-two loglinear model.
  • Form odds ratios by comparing selected row and column levels in a larger table.
  • Calculate interaction contrasts from expected counts, observed counts, or reference-cell interaction parameters.
  • Recognize how reversing a comparison changes the sign of the log odds ratio and reciprocates the odds ratio.

Why an Interaction Can Be an Odds Ratio

In a two-way table, a row effect changes the mean count across a row and a column effect changes it across a column. An interaction describes what remains when those separate effects do not account for the joint pattern. For a two-by-two table, that remainder has a direct interpretation: it is the logarithm of the cross-product odds ratio.

This connection is useful because the odds ratio is unchanged by multiplying an entire row or column by a positive constant. It isolates association between the two table variables from their separate overall levels. In a loglinear model, the corresponding interaction contrast removes the row and column contributions by subtraction.

Definition: For a two-by-two table with positive cell means \(\mu_{ij}\), where \(i\) indexes rows and \(j\) indexes columns, define the cross-product odds ratio as $$ \operatorname{OR}=\frac{\mu_{11}\mu_{22}}{\mu_{12}\mu_{21}}. $$ Its logarithm is the log odds ratio. The same definition applies to positive observed cell counts by replacing each \(\mu_{ij}\) with its observed count.

When the table records two binary outcomes, this cross-product ratio is the ratio of the odds in one row to the odds in the other. More generally, it is called the odds ratio for the two-by-two table even when the row and column categories are not themselves outcomes. The cell order matters: exchanging the two rows or the two columns changes the odds ratio to its reciprocal.

The Two-by-Two Loglinear Interaction

Let \(\mu_{ij}>0\) be the mean count in cell \((i,j)\), and write \(\eta_{ij}=\log\mu_{ij}\). A saturated two-by-two loglinear model can be written using reference-cell coding:

$$ \eta_{ij}=\lambda+\alpha_i+\beta_j+\gamma_{ij}, \qquad \alpha_1=\beta_1=0,\quad \gamma_{i1}=\gamma_{1j}=0. $$

Here \(\lambda\) is the log mean in the reference cell \((1,1)\); \(\alpha_i\) and \(\beta_j\) are row and column effects relative to that cell. The interaction parameter \(\gamma_{22}\) is the part specific to the combination of row 2 and column 2. It is a contrast, not simply the log mean of cell \((2,2)\).

Theorem: In a two-by-two table with positive cell means, the reference-cell interaction parameter equals the log odds ratio: $$ \gamma_{22} =\eta_{11}+\eta_{22}-\eta_{12}-\eta_{21} =\log\left(\frac{\mu_{11}\mu_{22}}{\mu_{12}\mu_{21}}\right). $$

Proof. Under the stated coding, \(\eta_{11}=\lambda\), \(\eta_{21}=\lambda+\alpha_2\), \(\eta_{12}=\lambda+\beta_2\), and \(\eta_{22}=\lambda+\alpha_2+\beta_2+\gamma_{22}\). Therefore,

$$ \begin{aligned} \eta_{11}+\eta_{22}-\eta_{12}-\eta_{21} &=\lambda+(\lambda+\alpha_2+\beta_2+\gamma_{22})\\ &\quad-(\lambda+\beta_2)-(\lambda+\alpha_2)\\ &=\gamma_{22}. \end{aligned} $$

Since every mean is positive, its logarithm is defined. The logarithm of a product is the sum of the logarithms, and the logarithm of a quotient is the difference of logarithms. Thus \(\eta_{11}+\eta_{22}-\eta_{12}-\eta_{21} =\log(\mu_{11}\mu_{22}/(\mu_{12}\mu_{21}))\), proving the claim. \(\square\)

This result also explains the phrase “no interaction” in a two-by-two loglinear model: \(\gamma_{22}=0\) exactly when \(\operatorname{OR}=1\). It does not mean that all four cell means are equal. Row and column effects can still make them quite different; the condition says that their cross-product ratio is one.

Worked Example: A Two-by-Two Table

Suppose a two-by-two table has positive expected counts \(\mu_{11}=30,\ \mu_{12}=10,\ \mu_{21}=12,\ \mu_{22}=24\). Calculate the odds ratio and the loglinear interaction.

First calculate the cross-product odds ratio:

$$ \operatorname{OR} =\frac{30(24)}{10(12)} =\frac{720}{120} =6. $$

Now take its logarithm. The reference-cell interaction is \[ \gamma_{22}=\log(6)\approx 1.7918. \] The same answer follows from the log-mean contrast: \[ \log(30)+\log(24)-\log(10)-\log(12) =\log\left(\frac{30(24)}{10(12)}\right) =\log(6). \] Thus the interaction is positive, corresponding to an odds ratio greater than one. Reversing either the row comparison or the column comparison would give \(1/6\), with log odds ratio \(-\log(6)\).

Interaction Contrasts in Larger Tables

A table need not have only two rows and two columns for this relationship to apply. Choose any two distinct rows \(i,i'\) and any two distinct columns \(j,j'\). Those levels form a two-by-two subtable. Its odds ratio, using row order \(i,i'\) and column order \(j,j'\), is \(\mu_{ij}\mu_{i'j'}/(\mu_{ij'}\mu_{i'j})\). The corresponding log-mean contrast is the log odds ratio.

Theorem: For positive cell means in any two-way table, the odds ratio for rows \(i,i'\) and columns \(j,j'\) satisfies $$ \log\left(\frac{\mu_{ij}\mu_{i'j'}}{\mu_{ij'}\mu_{i'j}}\right) =\eta_{ij}+\eta_{i'j'}-\eta_{ij'}-\eta_{i'j}. $$ In a reference-cell loglinear parameterization, the same contrast is $$ \gamma_{ij}+\gamma_{i'j'}-\gamma_{ij'}-\gamma_{i'j}, $$ where interaction terms involving the reference row or column are zero.

Proof. Because \(\eta_{ab}=\log\mu_{ab}\), the contrast on the right is

$$ \eta_{ij}+\eta_{i'j'}-\eta_{ij'}-\eta_{i'j} =\log\left(\frac{\mu_{ij}\mu_{i'j'}}{\mu_{ij'}\mu_{i'j}}\right). $$

For the second equality, substitute \(\eta_{ab}=\lambda+\alpha_a+\beta_b+\gamma_{ab}\) into the four terms. The intercept occurs twice with a plus sign and twice with a minus sign. Each row effect and each column effect also occurs once with each sign. They all cancel, leaving \(\gamma_{ij}+\gamma_{i'j'}-\gamma_{ij'}-\gamma_{i'j}\). This proves both equalities. \(\square\)

With reference row 1 and reference column 1, the contrast comparing row \(i\) with row 1 and column \(j\) with column 1 reduces to \(\gamma_{ij}\). But if neither selected level is the reference, the log odds ratio generally involves a difference of two interaction parameters, or the full four-term contrast above. A single interaction coefficient is not automatically the log odds ratio for every pair of levels.

Worked Example: Selecting Two Columns in a Two-by-Three Table

Consider expected counts in a table with two rows and three columns:

Column 1Column 2Column 3
Row 120105
Row 2121212

Compare row 1 with row 2 using columns 1 and 3, in that order. The selected subtable has cells 20 and 5 in row 1, and 12 and 12 in row 2. Its odds ratio is

$$ \operatorname{OR}_{(1,2),(1,3)} =\frac{\mu_{11}\mu_{23}}{\mu_{13}\mu_{21}} =\frac{20(12)}{5(12)} =4. $$

The log-mean contrast gives the same result: \[ \eta_{11}+\eta_{23}-\eta_{13}-\eta_{21} =\log(20)+\log(12)-\log(5)-\log(12) =\log(4). \] With column 1 as the reference, this contrast is the interaction parameter \(\gamma_{23}\). The comparison concerns columns 1 and 3, not columns 1 and 2; using the wrong pair of columns would calculate a different odds ratio.

Worked Example: Comparing Two Nonreference Rows

Suppose a three-by-three table has positive expected counts:

Column 1Column 2Column 3
Row 11263
Row 2888
Row 34816

Compare rows 2 and 3 across columns 1 and 3, in that order. The odds ratio is

$$ \operatorname{OR}_{(2,3),(1,3)} =\frac{\mu_{21}\mu_{33}}{\mu_{23}\mu_{31}} =\frac{8(16)}{8(4)} =4. $$

To express this using reference-cell interactions, take row 1 and column 1 as the references. The row-and-column terms cancel in each baseline interaction: \[ \gamma_{23}=\log\left(\frac{\mu_{23}\mu_{11}}{\mu_{21}\mu_{13}}\right) =\log\left(\frac{8(12)}{8(3)}\right)=\log(4), \] and \[ \gamma_{33}=\log\left(\frac{\mu_{33}\mu_{11}}{\mu_{31}\mu_{13}}\right) =\log\left(\frac{16(12)}{4(3)}\right)=\log(16). \] The selected comparison uses two nonreference rows, so its log odds ratio is their interaction-parameter difference: \[ \gamma_{33}-\gamma_{23}=\log(16)-\log(4)=\log(4). \] This agrees with the direct calculation. The check matters: \(\gamma_{33}\) alone compares row 3 with the reference row, not row 3 with row 2.

Means, Observed Counts, and Interpretation

The defining loglinear relationship is a statement about positive cell means. In an observed table, the sample cross-product ratio is calculated from the four observed counts. If the table has independent Poisson cell counts and a saturated model is fitted, the fitted means equal the observed counts when all cells have positive counts; in that case the observed log odds ratio is also the fitted interaction contrast. If an observed cell is zero, the sample cross-product ratio may be zero, infinite, or undefined, and its logarithm need not be finite. Do not treat that as a finite interaction estimate without additional modeling choices.

The odds ratio describes a multiplicative comparison. An odds ratio of 4 says that the cross-product in the numerator is four times the cross-product in the denominator; its log, \(\log(4)\), is the additive contrast on the log-mean scale. Neither value by itself establishes a causal effect. Interpretation depends on what the rows and columns represent and how the table was obtained.

Common Mistake: Reading One Cell as the Interaction

A common error is to call \(\log(\mu_{22})\) the interaction in a two-by-two table, or to identify an interaction parameter with the odds ratio itself. But \(\log(\mu_{22})\) includes the intercept and both main effects, while the loglinear interaction is a log contrast. In the reference-cell coding above, \(\gamma_{22}\) is the log odds ratio; exponentiating it gives the odds ratio.

Another source of error is reversing only part of a comparison. The numerator must pair one selected row with one selected column and the other selected row with the other selected column. For the stated order, use \(\mu_{ij}\mu_{i'j'}/(\mu_{ij'}\mu_{i'j})\). Swapping exactly one pair of levels reverses the ratio and changes the sign of its logarithm; swapping both pairs leaves it unchanged.

Key takeaway: In any two-way table, choose two rows and two columns. The log odds ratio of that subtable is the four-cell log-mean contrast with alternating signs. Main effects cancel, leaving the interaction contrast for precisely those selected levels.

Check Your Understanding

Work through these questions using the stated row and column order.

  1. A two-by-two table has means \(\mu_{11}=15,\ \mu_{12}=5,\ \mu_{21}=9,\ \mu_{22}=9\). Calculate the odds ratio and loglinear interaction.
  2. For rows \(i,i'\) and columns \(j,j'\), write the log-mean contrast that equals the log odds ratio.
  3. In a reference-cell model, why is \(\gamma_{ij}\) the log odds ratio for row \(i\) versus row 1 and column \(j\) versus column 1?
  4. If an odds ratio is 5, what are the odds ratio and log odds ratio when exactly one of the row or column comparisons is reversed?
  5. Why can a zero observed count make the sample log odds ratio nonfinite even though the loglinear identity is defined for positive means?
Clinical Biostats