Tutorials › Generalized Linear Models › A GLM Model-Selection Workshop

Selection and Predictive Comparison · Tutorial 817 of 981

A GLM Model-Selection Workshop

Follow a complete model-selection workflow for a binary clinical outcome, from constructing candidate transformations and interactions to comparing and reporting the evidence.

Advanced 10 min read

What You'll Learn

  • Specify a small, interpretable candidate set of GLMs using transformations and hierarchical interactions
  • Check that likelihood-based comparisons use compatible fits and identify when a likelihood-ratio test is appropriate
  • Calculate and interpret AIC and BIC rankings, including a case where they disagree
  • Compare cross-validation scores using paired differences and their uncertainty
  • Report selection as evidence with limitations rather than as certainty about a uniquely correct model

From Candidate Models to a Defensible Choice

Model selection is not just the act of choosing the row with the smallest score. A defensible analysis first defines a relevant set of candidate models, checks that the fitted likelihoods are comparable, and then considers what each comparison can and cannot establish. In a clinical regression problem, those steps matter because a change in a transformation or interaction can alter both interpretation and prediction.

Consider a study of \(n=240\) patients in which the response is whether a serious event occurs within 30 days. Let \(Y_i\) be the binary outcome, \(x_i>0\) the treatment dose measured in units of 10 mg, and \(z_i\) a standardized baseline severity score. For this workshop, use logistic regression, with \(Y_i\) conditionally Bernoulli and \(\operatorname{logit}\{P(Y_i=1\mid x_i,z_i)\}=\eta_i\). The question is whether the dose relationship is adequately represented as linear on the logit scale, whether a log-dose transformation helps, and whether dose modifies the severity association.

Construct Candidates Before Ranking Them

A candidate set should correspond to plausible scientific descriptions, not to every formula that software can generate. Define \(g(x)=x\) for a linear dose effect and \(g(x)=\log(x)\) for a log-dose effect. A compact set of four models is:

Candidate specifications: \(M_0\): \(\eta_i=\beta_0+\beta_1x_i+\beta_2z_i\). \(M_1\): \(\eta_i=\beta_0+\beta_1\log(x_i)+\beta_2z_i\). \(M_2\): \(\eta_i=\beta_0+\beta_1x_i+\beta_2z_i+\beta_3x_iz_i\). \(M_3\): \(\eta_i=\beta_0+\beta_1\log(x_i)+\beta_2z_i+\beta_3\log(x_i)z_i\). Each model uses a Bernoulli response with the logit link.

The interaction specifications include both corresponding main effects. This respects the usual hierarchy principle: an interaction is not included while omitting the terms that define its component variables. The candidates also use the same patients and response. That is important: a criterion difference should reflect the models, not a changed analysis sample.

Worked Example: Translating the Clinical Question into Candidates

Suppose dose ranges from \(x=0.5\) to \(x=4\), and severity is standardized so that \(z=0\) is the sample mean. For \(M_0\), the dose contribution to the log odds is \(\beta_1x\); increasing dose by one unit changes the log odds by \(\beta_1\), holding severity fixed. For \(M_1\), the contribution is \(\beta_1\log(x)\), so the dose association is not constrained to be a constant change per unit of dose.

In \(M_2\), the severity slope on the logit scale is \(\beta_2+\beta_3x\), so the severity association can vary with dose. In \(M_3\), it is \(\beta_2+\beta_3\log(x)\). These are alternative interaction structures, not a single model containing both interactions.

All four candidates have an intercept, two main-effect coefficients, and no estimated dispersion parameter because the response is Bernoulli with its variance fixed by its mean. Thus \(M_0\) and \(M_1\) have \(k=3\) estimated parameters, while \(M_2\) and \(M_3\) have \(k=4\). This count must include every estimated model parameter, not merely the slopes.

Check the Likelihood Comparison

Before comparing likelihoods, confirm that each fit uses the same response definition, observations, likelihood convention, and treatment of weights or offsets. Check that the optimizer converged, the design matrix has full column rank, and the fitted model has no separation or other warning that makes its maximum-likelihood estimates unreliable. A numerical log-likelihood is not reassuring merely because software printed it.

For nested models fitted by maximum likelihood to the same data, the likelihood-ratio statistic is twice the difference in maximized log-likelihoods. The reason is direct: if the unrestricted model has log-likelihood \(\ell_U\) and the restricted model has \(\ell_R\), the likelihood-ratio statistic is \(-2\log\{L_R/L_U\}=-2(\ell_R-\ell_U)=2(\ell_U-\ell_R)\). Since the unrestricted parameter space contains the restricted one, its maximum cannot be smaller.

Theorem: If model \(R\) is nested in model \(U\), both are fitted by maximum likelihood to the same observations under the same likelihood, and their maximized log-likelihoods are \(\ell_R\) and \(\ell_U\), then \(\ell_U\geq \ell_R\) and the likelihood-ratio statistic is \(2(\ell_U-\ell_R)\geq0\). Under the null model, if the true parameter is an interior point, the model is identifiable and regular, and the usual smoothness conditions for Wilks' theorem hold, this statistic converges in distribution to a chi-squared variable with degrees of freedom equal to the difference in parameter dimensions.

The algebra establishes the statistic and its nonnegativity; it does not by itself establish the chi-squared approximation. The latter is an asymptotic result and can be unreliable with sparse data, boundary parameters, separation, or other violations of regularity. Also, a likelihood-ratio test is not a general test for comparing any two candidate models: the models must be nested for this standard parameter-difference reference distribution.

Worked Example: Nested Likelihood Checks

Suppose all four candidate fits converge on the same 240 patients, and their maximized log-likelihoods are \(M_0:-118.4\), \(M_1:-115.7\), \(M_2:-113.9\), and \(M_3:-114.3\). The numbers are consistent with the nesting relations: \(M_0\) is nested in \(M_2\), and \(M_1\) is nested in \(M_3\). In each pair, the model with the additional interaction has a larger (less negative) maximized log-likelihood.

For \(M_0\) against \(M_2\), the likelihood-ratio statistic is \(2\{-113.9-(-118.4)\}=2(4.5)=9.0\). The models differ by one parameter, the interaction coefficient. Under the stated regularity conditions, the reference distribution is chi-squared with one degree of freedom; the upper-tail probability is approximately \(0.0027\). This is evidence against the no-interaction restriction within this linear-dose pair.

For \(M_1\) against \(M_3\), the statistic is \(2\{-114.3-(-115.7)\}=2(1.4)=2.8\), again with one degree of freedom. Its approximate upper-tail probability is \(0.094\). This comparison does not provide the same level of evidence against the no-interaction restriction within the log-dose pair. These tests do not directly decide between \(M_2\) and \(M_3\): neither candidate is nested in the other.

Rank Candidates with Information Criteria

AIC and BIC combine fit with a penalty for the number of estimated parameters. With maximized log-likelihood \(\ell\), parameter count \(k\), and sample size \(n\), use \(AIC=-2\ell+2k\) and \(BIC=-2\ell+k\log(n)\). Smaller values rank better under the corresponding criterion. They are comparative scores for a specified candidate set, not tests that a model is true.

For models fitted to the same observations under the same likelihood convention, a common additive constant in the reported likelihood cancels from differences in either criterion. More explicitly, if every reported log-likelihood is shifted by the same constant \(c\), then every AIC shifts by \(-2c\), and every BIC also shifts by \(-2c\). The ordering is therefore unchanged. This does not license comparing scores from different samples or incompatible response likelihoods: in those cases, the changes need not be common constants.

Worked Example: AIC and BIC Can Rank Differently

Using the log-likelihoods above, calculate AIC for \(M_0\) as \(-2(-118.4)+2(3)=236.8+6=242.8\). For \(M_1\), it is \(231.4+6=237.4\). For \(M_2\), it is \(227.8+8=235.8\), and for \(M_3\), it is \(228.6+8=236.6\). Thus the AIC ranking is \(M_2\), \(M_3\), \(M_1\), \(M_0\), from best to worst.

For BIC, \(\log(240)\approx5.4806\). The penalty for three parameters is \(3(5.4806)=16.4418\), and for four parameters it is \(4(5.4806)=21.9224\). The BIC values are therefore \(M_0:236.8+16.4418=253.2418\), \(M_1:231.4+16.4418=247.8418\), \(M_2:227.8+21.9224=249.7224\), and \(M_3:228.6+21.9224=250.5224\). BIC ranks \(M_1\) best, then \(M_2\), \(M_3\), and \(M_0\).

This is not an arithmetic contradiction. BIC applies a larger penalty than AIC for the extra parameter at this sample size: \(5.4806\) rather than \(2\). AIC’s preferred \(M_2\) improves the log-likelihood over \(M_1\) by \(1.8\), while BIC judges that improvement insufficient to offset its larger complexity penalty. The ranking answers depend on the criterion and its aim; neither score proves that its winner is the uniquely correct scientific model.

Use Cross-Validation with Its Uncertainty

Cross-validation assesses predictive performance on held-out observations. Here suppose the reported score is mean negative log predictive density per patient, so smaller is better. The folds and scoring rule must be the same across candidates, and the complete modeling procedure—including transformations and any data-dependent choices—must be repeated using only the training portion of each split. Otherwise information from held-out responses can leak into model construction.

When models are scored on the same folds, their comparison should use paired fold differences. Let \(S_{Ak}\) and \(S_{Bk}\) be the scores for models \(A\) and \(B\) on fold \(k\), and let \(D_k=S_{Ak}-S_{Bk}\). The estimated difference is \(\bar D=K^{-1}\sum_{k=1}^K D_k\). Its variance across the observed fold differences is based on the variance of \(D_k\), not on treating the two models’ scores as unrelated.

Result: For paired fold scores, \(\operatorname{Var}(S_A-S_B)=\operatorname{Var}(S_A)+\operatorname{Var}(S_B)-2\operatorname{Cov}(S_A,S_B)\). This follows by expanding \(\operatorname{Var}(S_A-S_B)=E[((S_A-E[S_A])-(S_B-E[S_B]))^2]\); the cross-product contributes \(-2\operatorname{Cov}(S_A,S_B)\). Consequently, estimating uncertainty from paired differences uses the observed covariance and can be more informative than comparing two separate standard errors. It does not remove dependence among folds, so the chosen uncertainty method must match the cross-validation design.

Worked Example: Report the Predictive Difference, Not Just the Winner

Suppose repeated paired cross-validation gives these mean negative log scores and estimated standard errors: \(M_0:0.505\ (0.031)\), \(M_1:0.482\ (0.029)\), \(M_2:0.476\ (0.030)\), and \(M_3:0.469\ (0.032)\). The smallest mean score belongs to \(M_3\), but its difference from \(M_1\) is only \(0.469-0.482=-0.013\) per patient.

Suppose the standard error of that paired difference, computed from the foldwise differences using the analysis’s stated uncertainty procedure, is \(0.010\). A simple normal-approximation interval is \(-0.013\pm1.96(0.010)\), or approximately \([-0.0326,\ 0.0066]\). Because zero lies in the interval, these results do not clearly distinguish the predictive scores of \(M_3\) and \(M_1\) at this approximate 95% level. The separate standard errors \(0.032\) and \(0.029\) should not be substituted for the paired-difference standard error.

A careful report could say that \(M_3\) had the lowest estimated cross-validation loss, while its paired difference from \(M_1\) was small and uncertain. That statement preserves the observed ranking without claiming a reliable predictive advantage that the uncertainty assessment does not establish.

Putting the Evidence Together

In this example, AIC favors the linear-dose interaction model \(M_2\), BIC favors the log-dose main-effects model \(M_1\), and cross-validation gives \(M_3\) the lowest mean predictive loss but does not clearly separate it from \(M_1\). The likelihood-ratio comparisons add targeted evidence within nested pairs, but they do not settle comparisons between alternative dose transformations. These outputs answer related but distinct questions; agreement is not required for a sound analysis.

A useful report names the candidate set and the shared analysis sample, gives the criterion values or score differences, states the relevant uncertainty, and explains the selection rule. It should also describe any convergence, rank, sparse-data, or separation concerns. If scientific interpretation is central, report the fitted relationship and its uncertainty rather than presenting the selected formula as a discovered truth. If prediction is central, emphasize out-of-sample performance and its uncertainty. Model selection is a decision under limited evidence, not a substitute for checking whether the models are scientifically plausible.

Common Pitfalls

  • Testing nonnested models with a likelihood-ratio reference distribution. A difference in log-likelihood is always calculable, but the standard chi-squared likelihood-ratio test described here requires nesting and regularity conditions.
  • Comparing scores from different analysis samples. AIC or BIC differences can then reflect which patients were included, not only model fit and complexity.
  • Ignoring interaction hierarchy. Including a product term while omitting its component main effects changes the model’s meaning and usually violates the intended hierarchical construction.
  • Declaring a decisive winner from a tiny score gap. Report the size and uncertainty of paired predictive differences, as well as the ranking.
  • Treating an information criterion as a hypothesis test. AIC and BIC rank candidates according to different penalties; neither supplies a p-value or establishes truth.
Key takeaway: A rigorous GLM selection workflow connects scientific candidate construction, likelihood compatibility checks, criterion-based ranking, and uncertainty in predictive comparisons. Report what the evidence supports, including disagreements and limitations, rather than hiding them behind one selected model.

Check Your Understanding

Use the workshop workflow to answer these questions.

  1. Why is \(M_1\) nested in \(M_3\), but \(M_1\) and \(M_2\) are not nested?
  2. What checks should be made before interpreting a difference in maximized log-likelihoods?
  3. For nested models, explain why the likelihood-ratio statistic cannot be negative when both are maximized on the same data.
  4. Why can AIC and BIC prefer different candidates even when calculated from the same fitted models?
  5. When comparing two models by cross-validation on the same folds, what uncertainty quantity should be reported and why?
Clinical Biostats