A log-linear model is a statistical model where the logarithm of an outcome (usually a count) is expressed as a linear combination of predictor variables. In its simplest form, the equation looks like this: log(count) = constant + B1·X1 + B2·X2 + … where the B values are coefficients and the X values are your predictors. This “log on the left, linear on the right” structure gives the model its name and makes it especially useful for analyzing count data and categorical tables.
The Core Idea
In ordinary linear regression, you model an outcome directly as a straight-line function of predictors. But counts don’t behave like continuous measurements. They can’t go below zero, they tend to be skewed, and their variability often increases with their size. Taking the logarithm of the expected count solves these problems in one step: it maps a quantity that must be positive onto a scale that can range from negative infinity to positive infinity, which is exactly the range a linear equation naturally produces.
So instead of predicting a count directly, you predict its log. If you exponentiate both sides of the equation, you get the count itself expressed as a product of multiplied effects rather than added effects. That distinction matters for interpretation, and we’ll come back to it.
How It Connects to Poisson Regression
The most common version of a log-linear model assumes each count follows a Poisson distribution, which is the standard probability distribution for “how many times does something happen in a fixed window of time or space.” Under this assumption, each observed count Y is modeled as an independent Poisson random variable whose average rate is linked to the predictors through a log function:
log(λ) = B0 + B1·X1 + B2·X2 + … + Bp·Xp
Here, λ is the expected count, and the B values capture how each predictor shifts the log of that expected count. This is called the Poisson log-linear model, or equivalently, Poisson regression. It belongs to the broader family of generalized linear models (GLMs), alongside logistic regression and ordinary linear regression. What distinguishes each GLM is the assumed distribution for the outcome and the “link function” that connects the predictors to it. For Poisson regression, the link function is the natural logarithm.
A real-world example from neuroscience: researchers model the firing rate of a neuron across time windows by treating spike counts as Poisson-distributed and using a log-linear model where the predictors encode whatever stimuli were applied during each window. The model estimates how each stimulus changes the neuron’s firing rate on a multiplicative scale.
Analyzing Categorical Tables
Log-linear models have a second major use case that looks quite different on the surface: analyzing contingency tables, which are cross-tabulations of categorical variables. If you survey people and record their gender, age group, and whether they tested positive for a disease, you can arrange the resulting counts in a multi-way table. A log-linear model lets you ask which variables are associated with each other and which are independent.
For a simple two-way table with variables X and Y, the independence model is:
log(expected count) = λ + λX + λY
This says the expected count in any cell depends only on the row effect and the column effect, with no interaction. If X and Y are actually associated, you need an interaction term:
log(expected count) = λ + λX + λY + λXY
The interaction term captures the degree to which the combination of X and Y produces counts that differ from what you’d expect under independence. Testing whether that term is needed is equivalent to the classic chi-squared test of independence you may have seen in introductory statistics.
Three-Way Tables and Beyond
Things get more interesting with three or more variables. In a three-way table (X, Y, Z), you can fit a hierarchy of models ranging from complete independence (no associations at all) to the saturated model that includes a three-way interaction term and fits the data perfectly. Between those extremes sit models that capture specific patterns. For instance, a model with YZ and XZ interaction terms but no XY term says that X and Y are conditionally independent given Z: once you know Z, knowing X tells you nothing new about Y. The XZ and YZ odds ratios remain the same regardless of the level of the other variable.
This flexibility is what makes log-linear models popular in epidemiology and social science. A study in Lagos, Nigeria, for example, used log-linear modeling to investigate how age and gender jointly influenced hepatitis B prevalence across multiple years. The researchers compared nested models using fit statistics and found that age-by-year and gender-by-year interactions best explained the pattern of infection spread.
How to Interpret the Coefficients
Because the model works on the log scale, each coefficient B represents the change in the log of expected counts when the corresponding predictor increases by one unit (with everything else held constant). That’s not very intuitive on its own. The practical move is to exponentiate the coefficient: eB gives you a multiplicative factor.
Say a coefficient is 2. Then e2 ≈ 7.4, meaning that when that predictor is “on” (equals 1 instead of 0), the expected count is multiplied by 7.4, a 640% increase. If the coefficient is -0.2, then e-0.2 ≈ 0.82, meaning the expected count drops by about 18%.
For interaction terms in a two-way table, the exponentiated coefficient gives you the odds ratio between the row and column variables. If you exponentiate the interaction coefficient B3 in the model log(count) = constant + B1·Row + B2·Column + B3·Row×Column, the result eB3 is exactly the odds ratio measuring the association between the two variables. This is one of the most useful properties of log-linear models: the coefficients translate directly into the familiar language of odds ratios.
Assumptions to Keep in Mind
Log-linear models rest on four key assumptions:
- Poisson-distributed counts. The outcome variable should be a count per unit of time, space, or population.
- Independence of observations. Each count should be unrelated to the others. Repeated measurements on the same subjects, for example, would violate this.
- Mean equals variance. The Poisson distribution has the property that its average and its spread are the same value. When real data show more variability than the mean predicts (called overdispersion), the standard Poisson model can underestimate uncertainty. Alternatives like negative binomial regression handle this.
- Linearity on the log scale. The log of the expected count should be a linear function of the predictors. Non-linear relationships need transformations or additional terms.
Evaluating Model Fit
Since you’re usually comparing several candidate models (independence, partial association, saturated), you need a way to tell which one fits the data well without being unnecessarily complex. Two standard tools exist for this.
The likelihood ratio statistic, often written G², compares how well a simpler model fits relative to a more complex one. Its formula is G² = 2 × Σ(Observed × log(Observed / Expected)), and it follows a chi-squared distribution with degrees of freedom equal to the difference in parameters between the two models. A small G² (or equivalently, a large p-value) means the simpler model fits adequately and you don’t need the extra terms. Pearson’s chi-squared statistic offers a similar test using a slightly different formula but the same chi-squared reference distribution.
When comparing several non-nested models, information criteria like AIC provide a complementary approach. The model with the lowest AIC balances fit against complexity. In the hepatitis B study mentioned earlier, researchers selected the best model based on the lowest AIC value (117.37) combined with the results of likelihood ratio tests.
Fitting Log-Linear Models in Practice
In R, you fit a Poisson log-linear model using the glm function with the family set to “poisson”:
glm(count ~ predictor1 + predictor2, family = "poisson", data = your_data)
The output gives you coefficients on the log scale. To get multiplicative effects, exponentiate them. You can compare nested models using a deviance test with the anova function and a chi-squared test option. For contingency table analysis specifically, R’s loglin function is designed to fit hierarchical log-linear models directly from table objects.
In Python, the statsmodels library provides equivalent functionality through its GLM class with a Poisson family and log link. The workflow is similar: specify your formula, fit the model, and exponentiate the coefficients for interpretation.

