GLM Fundamentals

This page covers the statistical theory behind the GLM tab. See that page for usage instructions.

Model Formulation

GLM (the generalized linear model) extends the normal linear model to the exponential family of distributions defined in the next section, in order to handle response variables that a normal distribution does not fit—binary outcomes, counts, and positive continuous values—within a regression framework. It was introduced by Nelder & Wedderburn (1972). A GLM is defined by three components:

  1. Distribution family: The response variable YY follows a distribution in the exponential family
  2. Linear predictor: η=Xβ\eta = X\beta (a linear combination of predictors)
  3. Link function: A monotonic function gg such that η=g(μ)\eta = g(\mu), connecting the linear predictor to the mean μ=E[Y]\mu = E[Y]

Exponential Family

The distribution of the response changes with the kind of data: Binomial for binary outcomes, Poisson for counts. GLM avoids rebuilding the estimation theory for each distribution by restricting the choice to the exponential family. Within this family, the differences between distributions reduce to a single function expressing the mean-variance relationship, and replacing that function lets the same estimation algorithm (IRLS) cover every family.

A family of distributions is called an exponential family if its density (or mass) function can be written as:

f(yθ,ϕ)=exp ⁣{yθb(θ)a(ϕ)+c(y,ϕ)}f(y \mid \theta, \phi) = \exp\!\left\{\frac{y\theta - b(\theta)}{a(\phi)} + c(y, \phi)\right\}

Here, θ\theta is called the natural (canonical) parameter, ϕ\phi the dispersion parameter, and b(θ)b(\theta) the log-partition function; a(ϕ)a(\phi) is a known function determined by the family (see the table below). From this definition, the mean and variance follow as derivatives of the log-partition function b(θ)b(\theta):

  • E[Y]=b(θ)=μE[Y] = b'(\theta) = \mu
  • Var(Y)=b(θ)a(ϕ)\operatorname{Var}(Y) = b''(\theta) \cdot a(\phi)

Rewriting b(θ)b''(\theta) as a function of μ\mu gives the variance function V(μ)V(\mu), which expresses the mean-variance relationship Var(Y)=V(μ)a(ϕ)\operatorname{Var}(Y) = V(\mu) \cdot a(\phi) through a single function. The per-family forms of V(μ)V(\mu) are tabulated in Variance Functions and Overdispersion.

Exponential family parameters for each distribution family:

Familyθ\theta (natural parameter)a(ϕ)a(\phi)b(θ)b(\theta)c(y,ϕ)c(y, \phi)
Gaussianμ\muϕ\phiθ2/2\theta^2/2y22ϕlog(2πϕ)2-\dfrac{y^2}{2\phi} - \dfrac{\log(2\pi\phi)}{2}
Binomiallog ⁣(μ/(1μ))\log\!\bigl(\mu/(1-\mu)\bigr)1/ni1/n_ilog(1+eθ)\log(1+e^\theta)log(niki)\log\binom{n_i}{k_i}
Poissonlogμ\log\mu11eθe^\thetalog(y!)-\log(y!)
Gamma1/μ-1/\muϕ\philog(θ)-\log(-\theta)(1/ϕ1)logy+(1/ϕ)log(1/ϕ)logΓ(1/ϕ)(1/\phi - 1)\log y + (1/\phi)\log(1/\phi) - \log\Gamma(1/\phi)
Negative Binomiallog ⁣(μ/(μ+r))\log\!\bigl(\mu/(\mu+r)\bigr)11rlog(1eθ)-r\log(1-e^\theta)logΓ(y+r)logΓ(r)log(y!)\log\Gamma(y+r) - \log\Gamma(r) - \log(y!)
  • In the Binomial row, yiy_i is the proportion of successes (yi=ki/niy_i = k_i/n_i, 0yi10 \le y_i \le 1), kik_i is the number of successes at observation ii, nin_i is the number of trials at observation ii (not the sample size nn but the per-observation trial count), and μ\mu is the success probability. When ni=1n_i=1, it reduces to the Bernoulli distribution
  • The Negative Binomial rr is displayed as θ\theta in the MIDAS UI; on this page we use rr to avoid confusion with the exponential family natural parameter. The Negative Binomial belongs to the exponential family only when rr is known. In MIDAS's automatic estimation mode, rr is estimated by maximizing the profile likelihood Lp(r)=maxβL(β,r)L_p(r) = \max_\beta L(\beta, r) (with β\beta profiled out) in an outer loop (see GLM usage). The standard errors for β^\hat\beta reported in this mode are computed from the information matrix with r=r^r = \hat r treated as known, so uncertainty in rr is not reflected

The link function is a monotonic function η=g(μ)\eta = g(\mu) connecting the linear predictor η\eta to the expected value μ\mu of the response. A link function satisfying g(μ)=θg(\mu) = \theta (the natural parameter) is called the canonical link. While the distribution family is mostly determined by the type of the response, the link function leaves room for choice. For how the family is chosen, see Choosing a distribution family.

The first criterion is the effect scale: whether the coefficients are to be read as differences in the response or as ratios. With the Identity link, coefficients directly represent differences in the response. With the Log link, addition on the linear predictor becomes multiplication on the mean, so exp(β)\exp(\beta) reads as a ratio—a rate ratio (IRR) for Poisson and Negative Binomial. With Logit, exp(β)\exp(\beta) is an odds ratio (OR). For Logit and Log, the coefficient table shows the exp(β^)\exp(\hat\beta) column corresponding to this interpretation.

Link FunctionFormulaCoefficient InterpretationCanonical Link For
Identityη=μ\eta = \muβ\beta is a difference in the responseGaussian
Logitη=log ⁣(μ/(1μ))\eta = \log\!\bigl(\mu / (1 - \mu)\bigr)exp(β)\exp(\beta) is an odds ratioBinomial
Logη=log(μ)\eta = \log(\mu)exp(β)\exp(\beta) is a ratio (multiplicative effect)Poisson
Inverseη=1/μ\eta = 1/\muβ\beta is a change on the 1/μ1/\mu scaleGamma
Probitη=Φ1(μ)\eta = \Phi^{-1}(\mu)β\beta is a change in Φ1(μ)\Phi^{-1}(\mu) (the z-value of the probability)

What most strongly supports a particular effect scale is knowledge of how the data arise. If each factor scales the rate by a constant multiple, effects add up on the log scale. If the response can be thought of as an unobserved continuous variable crossing a threshold, coefficients read as effects on the scale of that variable, and assuming a normal distribution for it gives Probit (see the threshold model in GLMM Fundamentals).

The canonical link is the default choice when the effect scale does not settle the question. Since η=θ\eta = \theta, XyX'y becomes a sufficient statistic for β\beta, and the log-likelihood is concave in β\beta. When the design matrix XX has full rank and the MLE exists, the solution is unique and IRLS converges stably1. These are properties of estimation convenience; being canonical does not make the model correct.

Non-canonical links forfeit these properties but may be chosen when the effect scale takes priority. For example, the canonical link for Gamma is Inverse (η=1/μ\eta = 1/\mu), which puts coefficients on a 1/μ1/\mu scale that is hard to interpret. The Log link (exp(β)\exp(\beta) as a multiplicative effect) is more commonly used in practice.

A link chosen for the effect scale is not guaranteed to be compatible with the family's domain. For example, Poisson + Identity, chosen to read rate differences, produces a fitted mean outside the domain (positive values) when the linear predictor goes negative for some observation. Whether this happens is determined by the data, not by the combination itself; when it does, MIDAS does not force the mean into range and aborts the fit with an error (see the notes in GLM usage).

Parameter Estimation (IRLS)

GLM parameters β\beta are estimated by maximum likelihood. Under regularity conditions (differentiability of the log-likelihood, the true parameter being an interior point of the parameter space, etc.), the estimator is consistent, asymptotically normal, and asymptotically efficient. In general no closed-form solution exists, so IRLS (Iteratively Reweighted Least Squares) is used2.

At each iteration, working weights WW and an adjusted dependent variable zz are computed, then the weighted least squares problem:

β^(t+1)=(XW(t)X)1XW(t)z(t)\hat\beta^{(t+1)} = (X'W^{(t)}X)^{-1}X'W^{(t)}z^{(t)}

is solved to update β\beta. WW is a diagonal matrix, and its ii-th diagonal entry WiiW_{ii} and the ii-th component ziz_i of zz are computed from the current μ^(t)\hat\mu^{(t)} and the link function as:

Wii=1V(μi)(dη/dμ)i2,zi=ηi+(yiμi)(dηdμ)iW_{ii} = \frac{1}{V(\mu_i)\,(d\eta/d\mu)_i^2}, \qquad z_i = \eta_i + (y_i - \mu_i)\,\Bigl(\frac{d\eta}{d\mu}\Bigr)_i

where V(μ)V(\mu) is the variance function and dη/dμd\eta/d\mu is the derivative of the link function. For Grouped Binomial, the variance of observation ii is V(μi)/niV(\mu_i)/n_i, as given by a(ϕ)=1/nia(\phi) = 1/n_i in the exponential family table, so WiiW_{ii} is additionally multiplied by the trial count nin_i. See Nelder & Wedderburn (1972) for the original formulation of IRLS for GLMs. Iteration stops when the maximum absolute change in coefficients falls below the convergence threshold.

With the canonical link, the concavity of the log-likelihood ensures stable convergence. Non-canonical links may lead to slower convergence or convergence failure.

Coefficient Standard Errors and Confidence Intervals

The confidence intervals for the coefficients reported by the GLM tab are Wald intervals β^j±cSE(β^j)\hat\beta_j \pm c \cdot \operatorname{SE}(\hat\beta_j). The standard error SE(β^j)\operatorname{SE}(\hat\beta_j) is the square root of the jj-th diagonal entry of the estimated covariance matrix ϕ^(XW^X)1\hat\phi\,(X'\hat{W}X)^{-1}, where W^\hat W is the IRLS weight matrix WW evaluated at the converged μ^\hat\mu.

The estimated dispersion parameter ϕ^\hat\phi is determined per family. Poisson, Binomial, and Negative Binomial with estimated rr use ϕ^=1\hat\phi = 1. Gaussian uses the residual deviance divided by npn-p; since the Gaussian deviance is i(yiμ^i)2\sum_i (y_i - \hat\mu_i)^2, this value equals Pearson χ2/(np)\text{Pearson }\chi^2/(n-p). Gamma and Negative Binomial with fixed rr use Pearson χ2/(np)\text{Pearson }\chi^2/(n-p). The deviance-based estimator is not used for Gamma because it is not consistent there (McCullagh & Nelder, 1989). What estimating ϕ^\hat\phi with fixed rr means is discussed in Variance Functions and Overdispersion.

The quantile cc is taken from the tt distribution with npn-p degrees of freedom for families whose ϕ^\hat\phi is estimated from the data, and from the standard normal distribution for families with ϕ^=1\hat\phi = 1. For the families that use the tt distribution, cc reflects the uncertainty in estimating ϕ^\hat\phi.

For Gaussian + Identity, the coverage probability of this interval (the probability that the interval contains the true value) matches the nominal level in finite samples. For all other family/link combinations, the interval rests on the asymptotic normality of the maximum likelihood estimator, so its coverage probability matches the nominal level only in large samples.

Variance Functions and Overdispersion

As described in the Exponential Family section, the variance function V(μ)=b(θ)V(\mu) = b''(\theta) is the second derivative of the log-partition function rewritten in terms of μ\mu. Through the relationship Var(Y)=V(μ)a(ϕ)\operatorname{Var}(Y) = V(\mu) \cdot a(\phi), it defines the mean-variance relationship for each family.

FamilyV(μ)V(\mu)a(ϕ)a(\phi)Var(Y)\operatorname{Var}(Y)
Gaussian11ϕ\phiϕ\phi (= σ2\sigma^2)
Binomialμ(1μ)\mu(1 - \mu)1/ni1/n_iμ(1μ)/ni\mu(1-\mu)/n_i
Poissonμ\mu11μ\mu
Gammaμ2\mu^2ϕ\phiμ2ϕ\mu^2 \phi
Negative Binomialμ+μ2/r\mu + \mu^2/r11μ+μ2/r\mu + \mu^2/r

Poisson and Binomial assume a dispersion parameter ϕ=1\phi = 1. When the actual data variance exceeds this assumption, the condition is called overdispersion. Overdispersion leads to underestimated standard errors and confidence intervals that are too narrow. To diagnose overdispersion, use the Deviance/df ratio shown in the Deviance Goodness-of-Fit section of the GLM Diagnostics tab, opened via View Diagnostics. Under the assumption, this ratio should be close to 1, so a value far from 1 suggests overdispersion. Note that the ratio fluctuates more around 1 when npn - p is small.

When overdispersion is detected with Poisson data, switching to Negative Binomial adds a μ2/r\mu^2/r term to the variance, explicitly modeling the extra dispersion. When rr is estimated, overdispersion is absorbed into rr, so ϕ=1\phi = 1. When rr is fixed, residual overdispersion beyond the fixed rr is estimated as ϕ^=Pearson χ2/(np)\hat\phi = \text{Pearson }\chi^2/(n-p) and reflected in standard errors and confidence intervals.

However, for binary data with ni=1n_i = 1 (logistic regression), each observation follows Bernoulli(μi)(\mu_i), and once the mean μi\mu_i is fixed the marginal variance μi(1μi)\mu_i(1-\mu_i) is determined as well. There is no degree of freedom in the per-observation variance, so there is simply nothing to compare against to say "the data variance exceeds the theoretical variance." This is why Pearson χ2\chi^2 and deviance cannot detect overdispersion at the individual level. This does not mean overdispersion is absent — only that it cannot be detected from the same data; extra dispersion arising from clusters or repeated measurements (e.g., treating multiple patients from the same hospital as independent) can still exist and must be handled separately (see the glossary). Classical overdispersion diagnostics and remedies are meaningful only for grouped Binomial data with ni>1n_i > 1.

For grouped Binomial overdispersion, MIDAS does not currently support quasi-binomial or Beta-Binomial alternatives. If the extra dispersion arises from cluster structure, introducing random effects via GLMM is an option. When overdispersion is suspected, check the estimated dispersion parameter and consider that standard errors and confidence intervals may be underestimated.

Confidence Intervals for the Mean Response and Prediction Intervals

Mathematical background for the confidence intervals for the mean response and the prediction intervals for new observations computed by the GLM prediction feature.

In the formulas below, ϕ^\hat\phi is the estimated dispersion parameter defined in Coefficient Standard Errors and Confidence Intervals, and the quantile cc follows the rule in that section. hi=xnew(XW^X)1xnewh_i = x_\text{new}' (X'\hat W X)^{-1} x_\text{new} is the leverage of the prediction point, measuring how far its predictor values are from the center of the training data.

The confidence interval for the mean response is the Wald interval on the link scale, η^±cϕ^hi\hat\eta \pm c\sqrt{\hat\phi\, h_i}, transformed to the response scale via g1g^{-1}. Because gg is monotonic, the transformation does not change the coverage probability of the interval. With a non-linear link, the transformed interval is not symmetric around μ^\hat\mu. The accuracy of this interval is the same as for the coefficient confidence intervals.

The prediction interval covers the variability of a new observation YnewY_\text{new}. This variability cannot be captured by transforming a link-scale interval, so the computation depends on the family. All families except Gaussian + Identity use a plug-in method. A plug-in method treats the estimated parameters as if they were the true values and computes the interval from those values. Unlike a confidence interval, it does not account for parameter estimation uncertainty.

  • Gaussian + Identity: The analytical formula μ^±tnpϕ^(1+hi)\hat\mu \pm t_{n-p} \sqrt{\hat\phi(1 + h_i)} accounts for both the variance of a new observation (ϕ^\hat\phi) and the estimation uncertainty of the mean (ϕ^hi\hat\phi \cdot h_i)
  • Gaussian + non-Identity link: A plug-in method is used: μ^±tnpϕ^\hat\mu \pm t_{n-p} \sqrt{\hat\phi}. The non-linear link transformation prevents exact incorporation of estimation uncertainty on the μ\mu scale in closed form. As a result, prediction intervals for this combination are a simplified form that does not reflect estimation uncertainty, meaning predictions at the center of the data and at extrapolation points receive the same interval width. Building the interval on the link scale and back-transforming, as well as a first-order delta-method approximation, both weaken coverage guarantees under non-linear links or in small samples, so MIDAS uses neither
  • Poisson, Binomial, Gamma, Negative Binomial: A plug-in quantile method computes the quantiles of the fitted distribution directly:
    • Poisson: quantiles of Poisson(μ^)(\hat\mu)
    • Binomial: quantiles of Binomial(nnew,μ^)(n_\text{new}, \hat\mu) with success probability μ^\hat\mu and trial count nnewn_\text{new} (for grouped Binomial, each row's value of the training Trials column in the prediction dataset; 11 for binary data), divided by nnewn_\text{new} so the interval is reported on the success-proportion scale
    • Gamma: quantiles of the Gamma distribution with mean μ^\hat\mu, shape α=1/ϕ^\alpha = 1/\hat\phi, and scale ϕ^μ^\hat\phi \cdot \hat\mu
    • Negative Binomial: quantiles of the Negative Binomial distribution with mean μ^\hat\mu and rr (r^\hat r in automatic estimation mode, the specified value in fixed mode)

For discrete distributions (Poisson, Binomial, Negative Binomial), quantiles are rounded conservatively to the smallest integer kk satisfying P(Xk)αP(X \le k) \ge \alpha. Under the plug-in distribution, the coverage probability therefore meets or exceeds the nominal level. For individual Binomial data (ni=1n_i = 1), the only quantile candidates are {0,1}\{0, 1\}, limiting the informativeness of the interval.

The plug-in methods do not account for parameter estimation uncertainty, so the actual coverage probability may fall below the stated confidence level, particularly in small samples or for predictions far from the observed data range.

See also

References

  • Nelder, J. A., & Wedderburn, R. W. M. (1972). Generalized linear models. Journal of the Royal Statistical Society: Series A, 135(3), 370-384. https://www.jstor.org/stable/2344614
  • McCullagh, P., & Nelder, J. A. (1989). Generalized Linear Models (2nd ed.). Chapman and Hall.

Footnotes

  1. The exception where the MLE does not exist is complete separation—when a linear combination of predictors perfectly separates the response—where the log-likelihood remains concave and XX full-rank but has no finite maximum. Binary logistic regression is the canonical example, and similar cases arise in other discrete-response models such as multinomial logit. MIDAS detects separation and reports a warning (see the convergence issues section in GLM usage).

  2. The exception is Gaussian + Identity: V(μ)=1V(\mu)=1 and dη/dμ=1d\eta/d\mu=1 make W=IW=I and z=yz=y in the formulas in the main text, so the weights do not depend on the data and IRLS reaches the OLS solution β^=(XX)1Xy\hat\beta = (X'X)^{-1}X'y in a single iteration from any starting point.