How are several categories related? (log-linear models)
In brief
Are school type, gender and qualification related, and which pairs of them? A log-linear model explains the frequency of each cell of a table from main effects and interactions. Statable tests a model you choose; there is no automatic model search.
How it works in Statable
- "New analysis", then choose the card "How are several categories related?".
- "Which categories?": two to five columns that name groups. Optionally a column with the frequency per cell.
- The result shows G² and X²: a large p here means that the model does not contradict the data.
- Another model: "More options: choose the model", then "Recalculate with this model".
What the table looks like
Two to five columns with categories (2 to 12 values each). Either every row counts as one case, or a column with whole numbers gives the frequency per cell. Statable counts every cell of the table, including the empty ones; their number is shown in the result. Nothing is calculated for frequencies that are not whole numbers or are negative, and for more than 20,000 cells.
Choosing the model
- Independence: main effects only, the categories are not related.
- All two-way interactions: every pair may be related.
- Saturated: all interactions. The model reproduces the cell frequencies exactly (G² = 0, df = 0); there is no test.
- Tick single interactions: the model is hierarchical. An interaction includes its main effects and lower interactions.
Reading the result
- G² (the deviance) and X² (Pearson) measure how far the cell frequencies differ from the model; df are the degrees of freedom. A large p means here: the model does not contradict the data. It does not prove that the model is right. The direction is the reverse of most tests, where a small p speaks for an effect.
- A small p means: the cell frequencies differ from the model more than chance would lead us to expect; the model is missing something.
- Comparison with simpler models: the difference in G² and df between a simpler and the chosen model shows whether the additional terms improve the fit. A small p speaks for them. This works only for nested models.
- AIC: when comparing several models, the smaller value speaks for the model.
Difference from SPSS
G² and df are the same as in SPSS. Statable does not pick a model by rules; the choice stays with you.
Requirements and limits
- Expected frequencies: if fewer than 5 are expected in more than 20% of the cells or a value is below 1, p is unreliable. Statable gives the share of cells below 5.
- Empty cells are counted and enter the degrees of freedom.
- Each case is in exactly one cell; the cases must be independent of each other (no repeated measures).
Reporting the result
G²(9) = 6.76, p = .662; X²(9) = 6.87
Typical examples
- Are school type, gender and qualification related?
- Which pairs of features of a survey (subject, semester, satisfaction in levels) are related?
For specialists
R (stats): glm(frequency ~ terms, family = poisson) on the full table (expand.grid, otherwise df is wrong). G² = deviance, X² by Pearson, AIC from the model. Checked on HairEyeColor against MASS::loglm and SPSS.