Log-linear models

Log-linear models for multi-way tables with the loglm conventions

A log-linear model explains the counts in a multi-way table of categorical variables, and the way to read it is the opposite of almost every other test in the app: here a large p is good. Magic Stat fits the model by iterative proportional fitting and reports the same quantities as R's loglm.

The honest part

Modelling counts, and reading p backwards

There is no response variable in a log-linear model. Every variable is categorical, the numbers being modelled are the cell counts of their cross-table, and the model describes how those counts depend on the margins. A model containing the right interaction terms reproduces the table closely; the test compares your chosen model against the saturated model, so a non-significant result — a large p — means the terms you specified are enough. A small p means the counts need a higher-order interaction.

Magic Stat fits the model by iterative proportional fitting, the same algorithm as stats::loglin, and reports G² (likelihood ratio) and Pearson's X² against the saturated model, with the degrees of freedom and both p-values. Coefficients follow the sum-to-zero convention of MASS::loglm, and the fitted values with their deviance residuals are shown cell by cell.

This is the right tool for counts in a table of three or more categorical variables. If one variable is really a response and the others are predictors, a Poisson GLM is the honest framing; if you have only two variables, the contingency-table analysis already answers the independence question.

What it does

What Magic Stat gives you for log-linear models

How it works

From a multi-way table to a fitted model

  1. Select two or more categorical variables. three or more is the classic multi-way case; continuous variables do not belong here.
  2. Choose the count column or count rows. if your table is already aggregated, point at the counts column.
  3. Pick the model. start from independence, add two-way terms, or build the terms yourself.
  4. Run. the iterative proportional fitting returns G² and Pearson X² with df and p, coefficients and fitted values.
  5. Read p backwards. a large p means the chosen terms suffice; a small p means you are missing a higher-order interaction. Export the tables and the report.
Options

The settings, out in the open

Input: categorical factors only, plus an optional count column (or one row per observation).

Model presets: independence · all two-way · all three-way · saturated · custom terms by checkbox.

Fit: iterative proportional fitting; the convergence tolerance and iteration limit follow the loglm defaults.

Reported: G² and Pearson X² with df and p · sum-to-zero coefficients · fitted values and deviance residuals.

Frequently asked

Log-linear model questions, answered honestly

Why is a large p good here?

Because the test compares your model against the saturated one. A large p means the simpler model is not significantly worse — the terms you chose already reproduce the table. This is the opposite of an ANOVA or a t-test, and it is the single most common way to misread a log-linear result.

Why can't I include a continuous variable?

The model explains counts of a categorical cross-table, so the factors must be categorical. A continuous predictor changes the question into a Poisson regression, which is a different model with a response. The app keeps the two separate.

How does this differ from the contingency table analysis?

The contingency-table analysis tests independence between two variables. A log-linear model generalises that to three or more variables and lets you specify which interactions to include, rather than only testing the all-independent model.

How are the coefficients scaled?

They follow MASS::loglm: sum-to-zero constraints per index, on the log scale, with the intercept the mean of the log expected counts. exp(coefficient) is the multiplicative effect on the expected count. A Poisson GLM would fit the same cells but parameterise the coefficients differently (treatment contrasts), so the coefficients are not directly comparable to a GLM summary.

Does the fit run here or on a server?

Here, locally, by iterative proportional fitting. The only automatic signal is an anonymous installation counter.

Contingency tables → Goodness-of-fit test → Poisson regression →