45.08.12 · mathematical-statistics / 08-learning-methods

Generalized Linear Models

shipped3 tiersLean: none

Anchor (Master): McCullagh & Nelder 1989 Generalized Linear Models 2e (Chapman & Hall) Ch. 2, Ch. 9 (quasi-likelihood) and §2.3 (the deviance and the analysis of deviance); Nelder & Wedderburn 1972 Generalized linear models (J. R. Statist. Soc. A 135) (the unifying framework and the scoring algorithm); Wedderburn 1974 Quasi-likelihood functions, generalized linear models, and the Gauss-Newton method (Biometrika 61)

Intuition Beginner

Ordinary straight-line fitting answers one question: how does the average of some measured number move as you turn a few dials? You pick weights on the dials, add them up, and that sum is your prediction of the average. It works beautifully when the thing you measure is a quantity that can wander up or down freely — a height, a price, a temperature — and when the scatter around the average is the same size everywhere.

But much of what you want to predict is not like that. A count of accidents at an intersection cannot go negative, and a busy intersection scatters more than a quiet one. A yes-or-no outcome, like whether a loan defaults, is a probability trapped between and . A waiting time is positive and skewed. For these, the plain straight-line recipe predicts impossible values and misjudges the scatter.

A generalized linear model keeps the part that works — a weighted sum of the dials — and fixes the two parts that break. First, it runs the weighted sum through a link, a simple transform that bends the unbounded sum onto the right range: through a logarithm so a count stays positive, through an S-curve so a probability stays inside to . Second, it lets the scatter grow or shrink with the average in the way each kind of data actually behaves. One framework, many response types, all fitted by the same procedure.

Visual Beginner

The same skeleton serves every case: build a weighted sum, bend it onto the right range with a link, and read off the average. Only the link and the scatter-pattern change from row to row.

Response type Range of the average Link (the bend) How scatter grows
Free quantity (height, price) any number none — straight line same everywhere
Yes/no outcome (default) between and S-curve (logit) largest near one-half
Count (accidents) and up logarithm grows with the average
Waiting time (positive, skewed) above logarithm or reciprocal grows with the square of the average

The picture to keep: one engine, the weighted sum, feeding a chosen bend, feeding a needle whose wobble matches the kind of measurement. Plain regression is the top row with the bend removed; everything else is the same engine wearing a different link and a different wobble.

Worked example Beginner

A shop counts customers per hour and wants to predict the count from a single dial, the temperature outside. Counts cannot be negative, so we bend the weighted sum through a logarithm: the log of the average count is the straight-line part. Suppose fitting gives the rule

Step 1. Predict at C. The straight-line part is .

Step 2. Undo the logarithm to get the average count. The opposite of a logarithm is the exponential, so the average count is . About customers an hour.

Step 3. Predict at C. The straight-line part is , and the average count is . About customers an hour.

Step 4. Read the effect of the dial. A rise added to the log, and adding to a logarithm multiplies the count by . Check: , matching Step 3.

What this tells us: because the link is a logarithm, a fixed change in the dial does not add a fixed number of customers — it multiplies the count by a fixed factor. The bend turns the additive straight line into a multiplicative effect on the count, which is exactly what keeps the prediction positive.

Check your understanding Beginner

Formal definition Intermediate+

A generalized linear model (GLM) for a response given covariates is specified by three components, following McCullagh & Nelder [McCullagh 1989] Ch. 2.

The random component (the exponential-dispersion family). The response has a density or mass function of exponential-dispersion form

with the canonical parameter, the dispersion parameter, the (smooth, strictly convex) cumulant function, and known functions; commonly for a known prior weight . This is the one-parameter exponential family of 45.01.02 indexed in its mean, carrying the extra scale . Differentiating the identity under the integral sign gives the mean-variance relationship

where the variance function records how the variance depends on the mean through the inverse of the strictly increasing map . The variance function, together with , determines the second-moment structure entirely.

The systematic component. A linear predictor assembles the covariates through unknown coefficients . Stacked over observations this is with design matrix .

The link. A monotone, differentiable link function connects the mean to the linear predictor,

The link is canonical when , equivalently when : the canonical parameter equals the linear predictor. For the canonical link the natural statistic is sufficient for , which is the structural reason the canonical-link fit is the cleanest.

Standard members. Each pair (family, canonical link) is a line of the framework:

  • Gaussian, identity link. , , . This is ordinary linear regression 45.06.01.
  • Bernoulli/binomial, logit link. , , . This is logistic regression 45.08.03.
  • Poisson, log link. , , . This is log-linear regression for counts.
  • Gamma, reciprocal (canonical) or log link. , , (or in practice).

Counterexamples to common slips

  • The link transforms the mean, not the data. Modelling by least squares is not a GLM: the GLM applies to , leaving the response on its own scale and its own variance function. Log-transforming and the log-link Poisson GLM give different estimators with different mean targets ( versus ).
  • Canonical is a choice, not a necessity. The probit and complementary-log-log links are valid for binary data though neither is canonical; only the logit is. Using a non-canonical link costs the sufficiency of and makes observed and expected information differ, but the model is well-posed.
  • The variance function is not a free parameter. Once the family is fixed, is determined by ; one cannot pair Poisson's with a Gaussian likelihood. Postulating without a full family is the separate quasi-likelihood device.
  • Constant dispersion is an assumption. The factor is taken known and common ( for Poisson and binomial). When the data scatter more than allows — overdispersion — the nominal standard errors are too small and must be estimated.

Key theorem with proof Intermediate+

The unifying computational fact is that the maximum-likelihood fit of any GLM is a sequence of weighted least-squares fits: Fisher scoring on the GLM log-likelihood is iteratively reweighted least squares (IRLS), with weights and a working response that the current fitted means supply. This generalises the logistic case of 45.08.03 to every exponential-dispersion family and any monotone link. The result follows McCullagh & Nelder [McCullagh 1989] §2.5 and Nelder & Wedderburn [Nelder 1972].

Theorem (GLM fitting by IRLS). Let be independent with exponential-dispersion density of mean , , linear predictor , and link . Write , , and define the diagonal Fisher weights and working response

where acts entrywise. Then the score has the form , the expected (Fisher) information is , and the Fisher-scoring update equals the weighted least-squares solution

Each step regresses the working response on with weights ; for the canonical link the observed and expected information coincide, so Fisher scoring equals Newton-Raphson and the log-likelihood is concave.

Proof. The log-likelihood contribution of observation is . By the chain rule through ,

Each factor is explicit: since ; so ; because ; and . Multiplying and substituting ,

Define , the -th diagonal of . Then , and summing gives the score

where is the definition of the working response. Setting the score to zero gives the GLM score equation .

For the information, compute the negative expected second derivative. Differentiating the per-observation score in produces two groups of terms: one proportional to and one to . The first group has mean zero because , so taking expectations annihilates it. The surviving term is, using ,

Summing, . The Fisher-scoring step replaces the Hessian by :

Because , the identity holds, so

the weighted normal equation for regressing on with weights . The dispersion cancels from the update, entering only the scale of the information. For the canonical link, gives , whence and the per-observation Hessian is already non-random — the terms vanish identically rather than only in expectation — so observed information equals expected information, Newton equals Fisher scoring, and the Hessian makes concave.

Bridge. The proof's engine is that the score factorises through the chain and the two link-and-variance factors collapse into the single weight , so the Fisher information is the weighted Gram matrix of the linear model 45.06.01 and each scoring step is the generalized-least-squares solve of that unit applied to the working response . This is exactly the IRLS identity of 45.08.03, now freed of the Bernoulli specifics: the foundational reason the logistic update reduced to clean weighted least squares is that the logit is the canonical link of the binomial, and the same canonical-link mechanism — observed information equal to expected information — operates for every family, which is the central insight that one algorithm fits them all. The construction generalises the exponential-family moment identities of 45.01.02, where and are the cumulant derivatives that here become and ; putting these together, the GLM is the exponential family of that unit driven by a linear predictor, and the score equation is its likelihood equation. The result builds toward the deviance and the analysis of deviance below, where the converged fit is compared against the saturated model, and it appears again in the asymptotic theory of 45.04.03, where at the optimum is the asymptotic covariance of .

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib does not host the GLM layer, so no module is wired in (lean_status: none). The intended statements — the mean-variance identities from the cumulant function and the IRLS update from Fisher scoring — would read roughly as follows.

-- Intended shape; not part of the current Babel Bible Lean build.
-- Requires: an exponential-dispersion family with cumulant function b,
-- a design matrix X, a link g, and the matrix/positive-definite API.
variable {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ)

-- cumulant function b, canonical parameter θ, mean μ = b'(θ)
noncomputable def mean (b : ℝ → ℝ) (θ : ℝ) : ℝ := deriv b θ
noncomputable def varFun (b : ℝ → ℝ) (θ : ℝ) : ℝ := deriv (deriv b) θ

-- mean-variance identity: E[Y] = b'(θ), Var(Y) = a(φ) b''(θ)
theorem mean_eq_b' (b : ℝ → ℝ) (θ : ℝ) :
    mean b θ = deriv b θ := rfl

-- Fisher information of a GLM is the weighted Gram matrix XᵀWX
noncomputable def fisherInfo (W : Matrix (Fin n) (Fin n) ℝ) :
    Matrix (Fin p) (Fin p) ℝ := Xᵀ * W * X

-- canonical-link concavity: -XᵀWX ⪯ 0 with W ⪰ 0 diagonal
theorem glm_concave_canonical (W : Matrix (Fin n) (Fin n) ℝ)
    (hW : W.PosSemidef) : (fisherInfo X W).PosSemidef := by
  sorry

the Mathlib gap analysis records what is missing: the exponential-dispersion family object, the mean-variance identities and , the variance function, the canonical link , the IRLS update , the canonical-link concavity, and the deviance with its asymptotic distribution.

Advanced results Master

The framework's coherence rests on the exponential-dispersion structure, and the principal results follow from the cumulant function and its derivatives.

Theorem 1 (mean, variance, and the variance function from the cumulant). For the exponential-dispersion density with and strictly convex on the interior of the canonical parameter set, the mean is and the variance is with . The map is a strictly increasing bijection of the interior onto the mean space, so each family is equivalently parametrised by or by . These are the cumulant identities of 45.01.02 specialised to the one-parameter mean-indexed family carrying a dispersion.

Theorem 2 (Fisher scoring is IRLS; canonical-link concavity). As established in the Key theorem, the GLM score is with and working response , the Fisher information is , and the scoring step is the weighted least-squares fit . For a canonical link the score is , the observed and expected information agree, and the Hessian is negative semidefinite, so the log-likelihood is concave and (under full column rank with ) strictly concave, giving a unique maximiser when one exists. Non-canonical links retain consistency but lose the observed-equals-expected coincidence, so Fisher scoring and Newton-Raphson then differ.

Theorem 3 (the deviance and the analysis of deviance). Define the deviance , where the saturated model fits and is the unit deviance; the scaled deviance is . For two nested GLMs with parameters, the scaled-deviance difference equals the likelihood-ratio statistic for the nested comparison (the saturated terms cancel), so under and regular conditions it is asymptotically by Wilks' theorem 45.04.09. Sequencing such comparisons over a chain of nested models is the analysis of deviance, the GLM analogue of the analysis of variance, which it recovers exactly in the Gaussian-identity case where and is the residual sum of squares.

Theorem 4 (quasi-likelihood and overdispersion). Suppose only the mean-variance relationship , is specified, with no full distribution. The quasi-score coincides with the genuine GLM score [Wedderburn 1974], so the quasi-likelihood estimator solves the same estimating equation and is consistent and asymptotically normal with covariance whenever the mean and variance models are correct, regardless of higher moments. The dispersion is estimated by the Pearson statistic ; when the data are overdispersed ( for nominal Poisson or binomial) this inflates the naive standard errors, restoring honest inference that the nominal would understate.

Theorem 5 (asymptotic normality of ). Under the regularity conditions of maximum-likelihood asymptotics 45.04.03 — interior true parameter, full column rank with bounded covariates, finite and non-singular limiting information — the GLM maximum-likelihood estimator satisfies , with the plug-in estimate . Wald, score, and likelihood-ratio tests for then follow the standard trinity of 45.04.09, the score test using the information evaluated under the null and the likelihood-ratio test reading off the analysis of deviance.

Synthesis. The foundational reason the whole framework coheres is the exponential-dispersion family: the cumulant function supplies the mean , the variance function , and — through the canonical link — the identification that makes the natural statistic sufficient for , so the GLM is exactly the exponential family of 45.01.02 driven by a linear predictor. This is exactly why one algorithm fits them all: the chain rule collapses the link and the variance function into the single weight , and Fisher scoring becomes the weighted least squares of the linear model 45.06.01, generalising the logistic IRLS of 45.08.03 from the Bernoulli variance to every variance function at once. The deviance is dual to the likelihood ratio — the scaled-deviance difference is the nested likelihood-ratio statistic, so the analysis of deviance and Wilks' theorem 45.04.09 are one object seen twice, recovering the analysis of variance in the Gaussian corner. Putting these together, the central insight is that quasi-likelihood needs even less than a family: because the score depends on the response only through and , postulating just the mean-variance relationship suffices for consistent estimation, which is the bridge from full-likelihood GLMs to the estimating-equation viewpoint and the practical remedy for overdispersion, while the asymptotic covariance ties the converged fit back to the MLE asymptotics of 45.04.03.

Full proof set Master

The Fisher-scoring/IRLS identity (Theorem 2) and the deviance/likelihood-ratio equality (Theorem 3, Exercise 7) are proved above. The remaining Master claims are recorded here.

Proposition 1 (mean and variance from the cumulant function). For with twice differentiable on the interior of the canonical set, and .

Proof. The score in of a single observation is . A regular likelihood has zero-mean score, so , giving . The second log-derivative is , a constant in . The information identity reads , so . Writing for the inverse map , which is well-defined and increasing because by the strict convexity of , gives .

Proposition 2 (the canonical link makes the likelihood concave). With a canonical link, , the GLM log-likelihood has gradient and Hessian , with ; under full column rank of and the Hessian is negative definite and is strictly concave.

Proof. For the canonical link , so . Then since , and summing gives . Differentiating again, , which is non-random because does not involve ; summing gives with and . For any , , so is concave; equality forces for all , i.e. , which under full column rank forces . Hence and is strictly convex.

Proposition 3 (Fisher scoring = Newton-Raphson for the canonical link). For a canonical link the observed information equals the expected information , so the Fisher-scoring and Newton-Raphson updates coincide.

Proof. Newton-Raphson uses the observed Hessian ; Fisher scoring uses . By Proposition 2 the canonical-link Hessian with contains no , so it equals its own expectation; thus identically and the two updates are the same map . For a non-canonical link the omitted terms in the Hessian have nonzero realisation though zero mean, so observed and expected information differ and the two iterations diverge in their steps (though they share the same fixed point).

Proposition 4 (consistency of the quasi-likelihood estimator). If and the variance model holds, the quasi-score is an unbiased estimating function, and its root is consistent for with asymptotic covariance .

Proof. Unbiasedness: since , using nothing beyond the mean model. An unbiased estimating function with a non-singular sensitivity matrix yields a consistent root by the standard estimating-equation argument 45.04.03: a Taylor expansion of about gives . The variance of the quasi-score is using , so by the central limit theorem and with . Higher moments of never enter.

Connections Master

  • Logistic regression and IRLS 45.08.03 is the canonical example this unit abstracts: the Bernoulli GLM with the logit link has variance function and weight , and its update is the general GLM IRLS step with that single variance function substituted, so everything proved there is the binomial line of the framework here.

  • Sufficiency and exponential families 45.01.02 is the random component: the exponential-dispersion density is the one-parameter exponential family of that unit indexed in its mean and carrying a dispersion, the mean-variance identities and are its cumulant identities, and the canonical link is exactly the natural-parameter map that makes sufficient for .

  • The linear model and least squares 45.06.01 is reused inside every scoring step: the GLM Fisher information is the weighted Gram matrix of that unit, and IRLS is a loop of its generalized-least-squares solves applied to the working response, recovering ordinary least squares exactly in the Gaussian-identity corner where and .

  • The likelihood-ratio, Wald, and score asymptotics 45.04.09 supply the inference: the scaled-deviance difference between nested GLMs is the likelihood-ratio statistic, so the analysis of deviance is Wilks' theorem applied along a chain of models, and the score test uses the information under the null.

  • MLE asymptotic normality and efficiency 45.04.03 governs the converged estimator: under interior-parameter, full-rank, and finite-information regularity the GLM MLE is -consistent and asymptotically normal with covariance , the inverse Fisher information of that unit, and the quasi-likelihood estimator inherits the same sandwich from the estimating-equation theory.

Historical & philosophical context Master

The generalized linear model was named and unified by John Nelder and Robert Wedderburn in their 1972 paper Generalized linear models (J. R. Statist. Soc. A 135) [Nelder 1972], which recognised that ordinary regression, probit and logit analysis of binary data, log-linear models for contingency tables and counts, and gamma models for positive continuous responses are instances of a single class: an exponential-family response, a linear predictor, and a link function joining the mean to that predictor. Their decisive contribution was algorithmic as well as conceptual — a common maximum-likelihood fitting procedure, Fisher scoring expressed as iteratively reweighted least squares, that fits every member with one routine, implemented in the GLIM software that carried the framework into practice.

The statistical antecedents were older and scattered. Fisher's scoring method and the exponential-family theory of sufficiency 45.01.02 supplied the likelihood machinery; probit analysis (Bliss, 1934) and the logit (Berkson, 1944) were the binary-response special cases; log-linear count models grew from contingency-table analysis. Robert Wedderburn's 1974 paper Quasi-likelihood functions, generalized linear models, and the Gauss-Newton method (Biometrika 61) [Wedderburn 1974] then loosened the requirement of a full distribution, observing that the scoring equations depend on the response only through its mean and variance function, so that postulating the mean-variance relationship alone yields consistent estimators and a principled treatment of overdispersion. The definitive synthesis is McCullagh and Nelder's monograph Generalized Linear Models (1989), whose treatment of the exponential-dispersion family, the deviance, and the analysis of deviance remains the standard reference; the quasi-likelihood line was later subsumed into the broader theory of generalized estimating equations by Liang and Zeger (1986) for correlated data.

Bibliography Master

@book{mccullagh1989generalized,
  author    = {McCullagh, Peter and Nelder, John A.},
  title     = {Generalized Linear Models},
  edition   = {2},
  publisher = {Chapman and Hall},
  year      = {1989}
}

@article{nelder1972generalized,
  author  = {Nelder, John A. and Wedderburn, Robert W. M.},
  title   = {Generalized linear models},
  journal = {Journal of the Royal Statistical Society, Series A},
  volume  = {135},
  number  = {3},
  pages   = {370--384},
  year    = {1972}
}

@article{wedderburn1974quasi,
  author  = {Wedderburn, Robert W. M.},
  title   = {Quasi-likelihood functions, generalized linear models, and the Gauss-Newton method},
  journal = {Biometrika},
  volume  = {61},
  number  = {3},
  pages   = {439--447},
  year    = {1974}
}

@book{hastie2009elements,
  author    = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
  title     = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
  edition   = {2},
  publisher = {Springer},
  year      = {2009},
  note      = {Chapter 4, linear methods for classification}
}

@article{berkson1944application,
  author  = {Berkson, Joseph},
  title   = {Application of the logistic function to bio-assay},
  journal = {Journal of the American Statistical Association},
  volume  = {39},
  number  = {227},
  pages   = {357--365},
  year    = {1944}
}

@article{liang1986longitudinal,
  author  = {Liang, Kung-Yee and Zeger, Scott L.},
  title   = {Longitudinal data analysis using generalized linear models},
  journal = {Biometrika},
  volume  = {73},
  number  = {1},
  pages   = {13--22},
  year    = {1986}
}