TL;DR
Linear regression assumes the outcome is a straight-line function of the inputs plus Gaussian noise. Many outcomes break both assumptions: a yes or no answer, a count of events, a strictly positive amount of money. A generalized linear model (GLM) keeps the linear part, a weighted sum of the inputs, and changes two things. It lets the outcome follow any distribution from the Exponential Family, and it passes the mean of that distribution through a link function so the weighted sum can live on an unrestricted scale.
Where you'll see it: logistic regression for yes-or-no outcomes such as whether a part fails, Poisson regression for event counts such as calls to a support desk per day, and gamma regression for positive costs in insurance pricing.
Intuition
Linear regression asks: what is the expected value of , given the inputs? It answers with a line. That works when can be any real number and the scatter around the line is roughly symmetric. It fails in two common cases.
If is a probability-like quantity, a line will eventually predict values below 0 or above 1. If is a count, a line will eventually predict negative counts, and the spread of the counts usually grows with their size, which a constant-noise assumption cannot express.
A GLM fixes both problems with one move. Keep the score , which is unbounded and linear in the coefficients. Then pass it through a function that maps the mean of onto the whole real line. The inverse of that function turns the score back into a valid mean. For a yes-or-no outcome the link is the logit, and its inverse is the Sigmoid Function, which squashes any score into the interval from 0 to 1. For a count the link is the logarithm, and its inverse is the exponential, which is always positive.
- logistic: mean = 1/(1+e^(-η))
The distribution family says how much noise to expect around the mean. The link says how the inputs push the mean. Choosing them separately is the point of the "generalized" in the name.
The math
A GLM has three parts.
-
Random part. Given inputs , the outcome follows an exponential-family distribution with natural parameter and mean . Its density has the form where is a dispersion parameter, and determines the mean through and the variance through .
-
Systematic part. A linear predictor , where is the coefficient vector and includes a constant 1 for the intercept.
-
Link. A monotone, differentiable function with . Equivalently .
Canonical links
The link is called canonical when it sets the natural parameter equal to the linear predictor, . Then . The canonical links for common families are:
| Distribution | Typical outcome | Canonical link | Mean from score |
|---|---|---|---|
| Gaussian | any real number | identity, | |
| Bernoulli | yes or no | logit, | |
| Poisson | counts | log, |
With a canonical link, the log-likelihood for independent observations is
This is concave in , so maximising it has a single optimum when the design is not degenerate. Differentiating gives the score equations
which say that the model's fitted values, weighted by the inputs, must match the observed values on average. For a Poisson model with an intercept, the first component says the fitted total count equals the observed total count.
Fitting by iteratively reweighted least squares
The score equations have no closed form for most links, so software solves them iteratively. The standard method is iteratively reweighted least squares. For the current estimate, compute
then update by weighted least squares of on with weights . Repeat until the coefficients stop changing. Each step is an ordinary regression, which is why GLMs are cheap to fit.
- Choose the family (what the noise looks like) and the link (how the inputs move the mean).
- Start with set to a reasonable value, such as the observed shifted away from the boundary, and compute .
- Compute the working weights and working responses .
- Solve the weighted least-squares problem for , update and .
- Stop when the change in deviance or coefficients is below a tolerance.
- Check the fit with residuals appropriate to the family, not with the raw residuals of linear regression.
Worked examples
Four people. Group A (the input is 1): outcomes 1, 1, 1, 0. Group B (the input is 0): outcomes 0, 1, 0, 0. Model: .
- Group B has success out of , so its fitted probability is . Its score is .
- Group A has successes out of , so and .
- The slope is .
- The odds ratio is . Check: the odds in group A are , the odds in group B are , and .
Interpretation: with one binary input and an intercept, the logistic GLM reproduces the observed group proportions exactly. The coefficient is a log odds ratio, so switching groups multiplies the odds of success by 9. Four people are far too few to trust that number, and the example is only about the arithmetic.
A support desk records the number of calls per day in two teams over three days. Team X: 4, 6, 5 calls. Team Y: 2, 3, 1 calls. Model: , where for team X and for team Y. The outcome is Poisson.
- For Poisson with a log link, the maximum likelihood estimate of each group's mean is its sample mean: and .
- Intercept: .
- Slope: .
- Rate ratio: . Team X handles 2.5 times as many calls per day as team Y, on average.
- Check the score equation: the fitted totals equal the observed totals within each team, and .
Interpretation: the coefficient on the log scale is the log of a rate ratio, which is a natural quantity for counts. The model predicts a positive mean number of calls for every input, unlike a straight line. The spread of counts is tied to their mean, so a day with twice as many calls is expected to be noisier, which the model handles automatically.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Counts vary more than the Poisson mean allows (overdispersion) | Standard errors are too small and effects look significant | Negative binomial, or a quasi-Poisson dispersion correction |
| Logistic model with a predictor that separates the outcomes perfectly | Some coefficients diverge to infinity and the fit does not converge | Penalised (ridge or Firth) logistic regression, or collect more data |
| Outcome is continuous but skewed and positive | A Gaussian GLM can predict negative values | Gamma or log-normal family, or a log link on a transformed outcome |
| Relationship is curved in the inputs | A linear predictor misses the curve | Add transformed inputs or splines to the linear predictor |
| Observations are correlated (repeated measures, clusters) | Independence assumption fails, errors are too small | Mixed-effects GLM or generalised estimating equations |
| Only prediction matters, not interpretation | A GLM may be outperformed by flexible models | Tree ensembles or neural networks, judged on held-out data |
A GLM is only as good as its family and link. Check residuals and dispersion before trusting the coefficients.
History
Probit and logit models for binary dose-response data were developed in biological work in the 1930s and 1940s, and they were used long before there was a general framework. In 1972 John Nelder and Robert Wedderburn showed that a large class of these models could be fitted by one algorithm, iteratively reweighted least squares, and named the class generalised linear models. Their paper made the shared structure visible: linear predictor, link, and exponential-family noise. The method caught on because a single fitting routine covered logistic, Poisson and gamma regression, and software packages could ship one implementation. The book by McCullagh and Nelder (first edition 1983) became the standard reference and set the terminology still used today.
Check yourself
QuestionRecall: what are the three parts of a generalized linear model?Show answer
A random part: the outcome follows an exponential-family distribution with a mean . A systematic part: a linear predictor . A link function with that connects the two. Linear regression is the special case with a Gaussian distribution and the identity link.
QuestionComputation: in a logistic model with an intercept and one binary input, group A has 3 successes out of 4 and group B has 2 successes out of 4. Find , , and the odds ratio.Show answer
Group B has , so . Group A has , so and . The odds ratio is , which matches the odds in group A (3) divided by the odds in group B (1).
QuestionComputation: a Poisson GLM with a log link on a single group has observed counts 3, 5, 4, 8. What is the fitted mean and the intercept?Show answer
The maximum likelihood estimate of the Poisson mean is the sample mean, . The intercept on the log scale is . Every observation gets a fitted value of 5, and the total fitted count, 20, matches the observed total, as the score equation requires.
QuestionWhy: a Poisson model predicts that counts with a mean of 10 have variance 10. Real call-centre counts often show variance well above their mean. What happens if you fit a Poisson GLM anyway, and what does that teach you about choosing a family?Show answer
The point estimates of the coefficients can still be reasonable, but the model's assumed variance is too small. Standard errors, confidence intervals and p-values are then too narrow, so effects look more certain than they are. The lesson is that the family encodes a claim about the noise, and the mean-variance relationship must be checked against the data. An overdispersed family such as the negative binomial makes that claim explicit.
QuestionApplied: a clinic wants to predict whether a patient returns within 30 days, with a yes-or-no outcome recorded for each patient. Why is a linear regression with a 0-or-1 outcome a poor choice, and what would a GLM use instead?Show answer
A linear regression can predict values below 0 or above 1, which cannot be probabilities. A logistic GLM uses a Bernoulli family with the logit link, so the fitted probability always lies between 0 and 1 and the coefficients are log odds ratios. This is an educational example of the model, not a clinical tool, and any real use would need validation on held-out patients.