Section 4.4

Generalized Linear Models

Ordinary regression assumes a continuous outcome with normal, constant-variance errors. Counts, yes/no outcomes, and rates break those rules. Rather than invent a brand-new method for each, generalized linear models (GLMs) stretch one elegant framework to cover them all — and you've already met two members of the family without knowing it.

Two ingredients

Every GLM is built from the same two pieces:

  • A linear predictor: the familiar straight line, η = b₀ + b₁x.
  • A link function that connects that line to the mean of the outcome, g(μ) = η, or equivalently μ = g⁻¹(η).

The link is the clever bit. It keeps the predicted mean in a sensible range, so a straight line on the "link scale" becomes whatever shape the data needs on the response scale.

🎮 One Line, Three Shapes

Pick an outcome type. The model is always a straight line on the link scale, but the link bends it into the right shape (and keeps it in range) for the data.

Family · link
What a +1 change in x does

The family you already know

  • Continuous outcome → identity link → ordinary regression. The link does nothing; the line stays a line.
  • Yes/no outcome → logit link → logistic regression. The line becomes an S-curve trapped between 0 and 1, and the slope is a log-odds (so eb₁ is an odds ratio).
  • Count outcome → log link → Poisson regression. The line becomes an exponential curve that can't go negative, and eb₁ is a multiplicative rate ratio.

The unifying idea: coefficients always act linearly — just on the link scale, not the response scale. That's why interpreting them means undoing the link: exponentiate for logistic and Poisson, read directly for ordinary regression. Learn the pattern once and every GLM follows the same logic.

Fitting and assumptions

GLMs are fit by maximum likelihood rather than least squares, and each family carries its own mean–variance relationship (for Poisson, the variance equals the mean; watch for overdispersion when real counts vary more than that). But the modeling workflow (pick predictors, fit, check, interpret) is exactly the one you've been practicing all along.

Counts are not rates

Poisson regression models a count, and a count only means something once you know how long you watched. Two clinics report falls: clinic A logs 40 over 500 patient-days, clinic B logs 60 over 1,500. Feed those raw counts to the model and it dutifully reports that B has 1.5 times A's rate, because 60/40 = 1.5. Per patient-day, A is running at 0.08 and B at 0.04, so B is half as bad. Same data, opposite finding.

The repair is an offset: a predictor forced into the model with its coefficient nailed to 1. Put log(patient-days) in that slot and the log link does the rest, since log(count) − log(days) is log(rate). The model still predicts counts, but the coefficients now describe rates. Fitted on the two clinics above, the offset version returns b₁ = log(0.5) = −0.693 and a rate ratio of exactly 0.50, while the same model without it returns 0.405 and 1.50. In R it is one argument, offset = log(days); in SPSS it is the Offset variable box in Generalized Linear Models. Skipping it is the single most common way a count model answers a question nobody asked. Offset and deviance both turn up in software output before anyone defines them, so the glossary carries both.

Unequal exposure is also a common hidden source of the overdispersion the section above warns about, because counts collected over wildly different windows vary more than any single Poisson rate can explain. Which raises the practical question: how do you tell?

The standard check runs on the deviance, the number a GLM minimizes in place of the sum of squared residuals. It measures how far your fitted model sits from a hypothetical one that reproduces every observation exactly, and for a well-specified Poisson model it should land near its degrees of freedom. So divide: a deviance/df ratio near 1 is what equidispersion looks like, and anything much above it says the counts are more variable than Poisson allows. The 412.6 on 178 df in the practice problem gives 2.32, comfortably into negative-binomial territory. The counts in the widget above are drawn from a true Poisson, so the ratio sits near 1 by construction: refitting that generator 20,000 times averages 1.07. It is a noisy number at these sample sizes, though, with 90% of those 32-point fits landing anywhere between 0.67 and 1.55, so treat a mild excess as a shrug and a 2 as a finding.

Why it matters: real outcomes are rarely tidy and continuous. GLMs let you bring the entire regression toolkit (multiple predictors, interactions, categorical variables) to bear on binary, count, and rate data, all under one roof. They're the practical backbone of applied statistics.

Problem 35 of the practice problems is a family-and-link drill on five hospital outcomes at once (counts with many zeros, a yes/no readmission, right-skewed euros, a score out of 20, and blood pressure), then asks you to read one fitted Poisson model back on the rate scale.

Common questions

What is a link function in simple terms?

The bridge between a straight line and an outcome that can't follow one. The linear predictor b₀ + b₁x ranges over all numbers, but a probability lives in (0, 1) and a count rate must stay positive — so the link transforms the outcome's mean onto the unlimited scale where the line lives (logit for probabilities, log for counts). One linear machine, different adapters.

What is overdispersion and how do I handle it?

Poisson regression hard-codes variance = mean, and real counts are almost always messier — more zeros, longer tails (event counts cluster within people, days, sites). The symptoms: deviance far exceeding its degrees of freedom, deceptively tiny standard errors. Standard fixes: a quasi-Poisson model (scales the errors) or, more commonly, a negative binomial model with its own dispersion parameter.

My people were followed for different lengths of time. Can I just divide and model the rate?

Dividing first throws away the thing the model needs. A count of 2 events in 2 months and 20 in 20 months are both a rate of 1 per month, but the second carries ten times the information, and a Gaussian model on the ratio treats them as equally certain, allows negative predictions, and inherits a variance that grows as exposure shrinks. Keep the count as the outcome and put log(exposure) in as an offset instead: a predictor whose coefficient is fixed at 1 rather than estimated. The coefficients then read as rate ratios, and the model still knows which people you watched longest. In R it is offset = log(months); in SPSS it is the Offset variable box in Generalized Linear Models.