Log-Linear Models for Contingency Tables
A log-linear model expresses the expected cell counts of a contingency table as a product of factor effects by working in log space, letting you test not just whether two categorical variables are associated but exactly which higher-order interactions among three or more variables are needed to explain the table.
Prerequisites: Contingency Tables and Tests of Independence
A simple chi-squared test on a contingency table can tell you two categorical variables aren't independent, but it can't easily extend to three or more variables, or tell you which combination of variables is driving the pattern. Log-linear models solve this by treating the expected count in each cell, , the way ordinary regression treats a continuous outcome — except the "outcome" being modeled is , and the "predictors" are indicator terms for each category and each combination of categories, exactly mirroring the main-effect-plus-interaction structure of an ANOVA table.
For a two-way table, the saturated model is : an overall level , a main effect for row category , a main effect for column category , and an interaction term capturing anything beyond independence. Testing whether that interaction term can be dropped (set to zero) without hurting fit is mathematically the same test as an independence chi-squared test on the two-way table — log-linear models are a strict generalization, not a different technique. Once a third variable is added, the model can include a three-way interaction , and dropping just that term while keeping all two-way interactions tests specifically for whether the association between and is the same across every level of — a more precise question than any single chi-squared test can answer.
Model fit is compared using deviance (a likelihood-ratio statistic), and nested models are compared by testing whether the drop in deviance from adding a term is large relative to its degrees of freedom, exactly as with nested regression models.
Log-linear models generalize the chi-squared independence test into a regression-like framework on log cell counts, letting you test which main effects and interactions — including three-way and higher interactions among categorical variables — are actually needed to explain a contingency table.
Related concepts
Practice in interviews
Further reading
- Bishop, Fienberg & Holland, Discrete Multivariate Analysis (1975)