Model Selection
every fitted model so far has been judged on the data it was fitted to, and that judge is bribed: least squares chose \(\hat\beta\) to make the training error small, so the training error flatters it. this page is about the two honest questions that follow — which of several candidate models to use, and how wrong the chosen one will be on new data — and the three families of answer: resample the data (cross-validation, the bootstrap), correct the training error analytically (\(C_p\), AIC, BIC), or search over subsets of predictors with one of those scores as the objective. 𐃏
the bias-variance decomposition explains why test error is U-shaped in model flexibility and the cross-validation notebook tunes \(\lambda\) empirically; neither is repeated here. what this page adds is the regression statistician’s bookkeeping: precise definitions of the errors being estimated, the optimism identity that makes \(C_p\) and AIC inevitable, the leave-one-out shortcut that makes LOOCV free for linear smoothers, and one running data set — thirty cheddar cheeses — on which every method is made to give a number.
selection versus assessment
model selection estimates the performance of competing models in order to pick one. model assessment takes the final model and estimates its test error on new data. both need an estimate of performance on data the model has not seen.
the training error cannot supply that estimate. in the course’s polynomial example, twenty points are drawn from \(Y = X + \varepsilon\) with \(\varepsilon \sim N(0, 0.25^2)\) and polynomials of degree 5, 10 and 15 are fitted. every degree \(k \ge 1\) contains the truth, and the training MSE can only fall as \(k\) grows, since the larger model nests the smaller. yet the degree-15 fit (16 coefficients, 4 residual degrees of freedom) threads every point and leaves the plotting window three times; its test MSE is far above the noise floor \(\sigma^2 = 1/16 = 0.0625\) that no model can beat. small training error with large test error is overfitting, and the rest of the page is about measuring the gap instead of eyeballing it.
the cheddar data (faraway package) record a subjective taste score for \(N = 30\) mature cheddars (mean 24.5, range 0.7–57.2) with three chemical covariates: Acetic and H2S (log concentrations) and Lactic. the candidates are the seven non-empty subsets, labelled ace, h2s, lac, ace_h2s, ace_lac, h2s_lac and 3 (all three). each method below ranks them.
statistical decision theory
let \((X, Y)\) have joint density \(p(x, y)\), \(X \in \mathbb{R}^p\). a loss \(L(Y, f(X))\) prices a prediction error; the expected prediction error of a predictor \(f\) is \[ \mathrm{EPE}(f) = \mathbb{E}_{(X,Y)}\big[L(Y, f(X))\big] = \iint L(y, f(x))\, p(x, y)\, dx\, dy. \] standard losses: squared error \((Y - f(X))^2\); deviance loss \(-\ell(\beta; X, Y)\), which for a normal linear model is squared error up to scale and constant; 0–1 loss \(I\{Y \ne f(X)\}\) for classifiers; exponential loss \(e^{-Y f(X)}\) for \(Y \in \{-1, +1\}\), the loss behind boosting.
the marginal \(p(x)\) is a modelling decision in disguise: it says which regions of input space the predictor must serve well (uniform on \([-1, 1]\) if all inputs matter equally, \(N(0,1)\) if those near zero matter more).
under squared error the EPE is minimised pointwise by the regression function \(f(x) = \mathbb{E}(Y \mid X = x)\), and the minimum is \(\mathbb{E}_X[\operatorname{Var}(Y \mid X)]\). under 0–1 loss it is minimised by the Bayes classifier \(f(x) = \arg\max_j \Pr(Y = j \mid X = x)\), with minimum (the Bayes error rate) \(1 - \mathbb{E}_X[\max_j \Pr(Y = j \mid X)]\).
this is what regression is: the linear model and the GLM are parametric guesses at \(\mathbb{E}(Y \mid X = x)\), and logistic regression and discriminant analysis are parametric guesses at \(\Pr(Y = j \mid X = x)\).
three errors, and the optimism
fix a training set \(\mathcal{T} = \{(x_i, y_i)\}_{i=1}^N\) drawn from \(p(x, y)\) and a fit \(\hat f\) built from it.
- training error \(\overline{\mathrm{err}}(\mathcal{T}) = \frac1N \sum_i L(y_i, \hat f(x_i))\).
- test (generalisation) error \(\mathrm{Err}(\mathcal{T}) = \mathbb{E}[L(Y, \hat f(X)) \mid \mathcal{T}]\): new pairs from \(p(x,y)\), this fit held fixed.
- expected error \(\mathrm{Err} = \mathbb{E}_{\mathcal{T}}[\mathrm{Err}(\mathcal{T})]\): averaged over training sets of size \(N\) as well.
- in-sample error \(\mathrm{Err}_{\mathrm{in}}(\mathcal{T}) = \frac1N \sum_i \mathbb{E}_{Y^0}[L(Y_i^0, \hat f(x_i))]\): fresh responses \(Y_i^0\) at the old inputs.
- the optimism is \(\mathrm{op} = \mathrm{Err}_{\mathrm{in}} - \overline{\mathrm{err}}\).
\(\mathrm{Err}(\mathcal{T})\) is the quantity one wants — the quality of this fit — but resampling methods end up estimating its average \(\mathrm{Err}\), and \(\overline{\mathrm{err}}\) estimates neither: the fit was chosen to minimise loss at the training responses, so redrawing those responses can only hurt it on average. the optimism has an exact form.
with inputs fixed, \(y_i = f(x_i) + \varepsilon_i\), independent errors of variance \(\sigma^2\), and squared error loss, \[ \mathbb{E}_y[\mathrm{op}] = \frac2N \sum_{i=1}^N \operatorname{Cov}(\hat y_i, y_i). \] for a linear smoother \(\hat{\mathbf y} = \mathbf{H}\mathbf{y}\) this is \(2\sigma^2 \operatorname{tr}(\mathbf H)/N\); for least squares with \(d\) coefficients, \(\operatorname{tr}\mathbf H = d\) and \[ \mathbb{E}_y[\mathrm{Err}_{\mathrm{in}}] = \mathbb{E}_y[\overline{\mathrm{err}}] + \frac{2 d \sigma^2}{N}. \]
the optimism is the covariance of a fitted value with its own response: how hard the fit chases the noise. it grows linearly in the number of coefficients, and for a shrinkage smoother such as ridge \(\operatorname{tr}\mathbf H\) is the effective degrees of freedom. every information criterion below is this identity with \(\sigma^2\) estimated.
proofs
condition on \(X\): \(\mathrm{EPE}(f) = \mathbb{E}_X\, \mathbb{E}_{Y \mid X}[L(Y, f(X)) \mid X]\), with a non-negative inner term, so it suffices to minimise it for each \(x\) over the single number \(c = f(x)\). for squared error, with \(m = \mathbb{E}(Y \mid X = x)\) and \(v = \operatorname{Var}(Y \mid X = x)\),
\begin{align*} \mathbb{E}_x[(Y - c)^2] &= \mathbb{E}_x[(Y - m)^2] + (m - c)^2 + 2(m - c)\,\mathbb{E}_x[Y - m] && \text{add and subtract } m \\ &= v + (m - c)^2, && \mathbb{E}_x[Y - m] = 0 \end{align*}
minimised at \(c = m\) with value \(v\). for 0–1 loss the inner term is \[ \sum_j I(j \ne c) \Pr(Y = j \mid X = x) = 1 - \Pr(Y = c \mid X = x)\,, \] smallest when \(c\) is the most probable class.
write \(f_i = f(x_i)\). with \(\hat y_i\) fixed given \(\mathcal T\) and \(Y_i^0 = f_i + \varepsilon_i^0\) independent,
\begin{align*} \mathbb{E}_y[\mathrm{Err}_{\mathrm{in}}] &= \sigma^2 + \tfrac1N \textstyle\sum_i \mathbb{E}(f_i - \hat y_i)^2, \\ \mathbb{E}_y[(y_i - \hat y_i)^2] &= \mathbb{E}[(\varepsilon_i + f_i - \hat y_i)^2] && y_i = f_i + \varepsilon_i \\ &= \sigma^2 + \mathbb{E}(f_i - \hat y_i)^2 - 2\,\mathbb{E}[\varepsilon_i \hat y_i] && \mathbb{E}[\varepsilon_i f_i] = 0 \\ &= \sigma^2 + \mathbb{E}(f_i - \hat y_i)^2 - 2 \operatorname{Cov}(\hat y_i, y_i). && \mathbb{E}\varepsilon_i = 0 \end{align*}
average over \(i\) and subtract. for \(\hat y_i = \sum_j h_{ij} y_j\), independence gives \(\operatorname{Cov}(\hat y_i, y_i) = h_{ii}\sigma^2\), summing to \(\sigma^2 \operatorname{tr}\mathbf H\); and \[ \operatorname{tr}(\mathbf X(\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top) = \operatorname{tr}((\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf X) = \operatorname{tr}\mathbf I_d = d\,. \]
cross-validation
the validation-set approach splits the data once at random, fits on one part and scores on the other. it is simple and has two flaws: the estimate depends heavily on the split, and the model is trained on far fewer points than the final model, so it overestimates that model’s error. cross-validation repairs both by letting every observation take a turn as test data.
LOOCV fits the model \(N\) times, each time on all observations but one, and averages the squared errors of the held-out predictions: \[ \mathrm{CV}_{(N)} = \frac1N \sum_{i=1}^N \big(y_i - \hat y_{(-i)}\big)^2, \qquad \hat y_{(-i)} = x_i^\top \hat\beta_{(-i)}. \] \(m\)-fold CV splits the data at random into \(m\) folds of sizes \(n_1, \dots, n_m\), fits on all folds but the \(k\)-th, and averages the fold MSEs: \(\mathrm{CV}_{(m)} = \frac1m \sum_k \frac{1}{n_k} \sum_{j \in \text{fold } k} (y_j - \hat y_{-k}(x_j))^2\). LOOCV is \(m = N\).
for least squares, with \(\hat y_i\) the full-data fitted value and \(h_i\) the leverage (the \(i\)-th diagonal entry of \(\mathbf H = \mathbf X(\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\)), \[ y_i - \hat y_{(-i)} = \frac{y_i - \hat y_i}{1 - h_i}, \qquad \mathrm{CV}_{(N)} = \frac1N \sum_{i=1}^N \Big(\frac{y_i - \hat y_i}{1 - h_i}\Big)^2. \]
one fit replaces \(N\). the leave-one-out residual is the ordinary residual inflated by \(1/(1 - h_i)\): barely for typical points (leverages average \(d/N\)), enormously for high-leverage ones, which are precisely the points whose removal moves the fit — see regression diagnostics, where the same quantity is the PRESS residual. the proof uses only that \(\hat{\mathbf y} = \mathbf H \mathbf y\) is linear in \(\mathbf y\) and that refitting to a response with \(y_i\) replaced by its own leave-one-out prediction reproduces \(\hat\beta_{(-i)}\), so the identity holds for any linear smoother with that self-consistency property (ridge, smoothing splines, kernel smoothers). in R: mean(((y - predict(fit)) / (1 - hatvalues(fit)))^2).
LOOCV is nearly unbiased for the test error of the full-data model, since each fit uses \(N - 1\) points; \(m\)-fold CV fits on \((m-1)N/m\) points and overestimates it. but the \(N\) leave-one-out fits share \(N - 2\) of every \(N - 1\) observations, so their errors are highly correlated, and for \(m\) quantities with variance \(v\) and pairwise correlation \(\rho\), \(\operatorname{Var}(\text{mean}) = \frac{v}{m}(1 + (m-1)\rho) \to \rho v\). \(m\)-fold CV trades a little bias for less variance; \(m = 5\) or \(10\) is the usual compromise.
the validation split is 15/15 (set.seed(123)); 5-fold CV is repeated ten times with seeds 123–132; the training MSE is \(\mathrm{RSS}/30\).
| model | validation MSE | LOOCV | 5-fold, range |
|---|---|---|---|
ace | 181.2 | 203.7 | 186–254 |
h2s | 100.3 | 122.9 | 117–132 |
lac | 127.7 | 145.9 | 136–170 |
ace_h2s | 97.6 | 129.3 | 117–157 |
ace_lac | 114.5 | 151.2 | 136–188 |
h2s_lac | 81.8 | 104.5 | 96–121 |
3 | 89.2 | 113.4 | 105–135 |
| model | 5-fold, mean of 10 | training MSE |
|---|---|---|
ace | 208.7 | 178.3 |
h2s | 122.8 | 109.5 |
lac | 149.4 | 128.8 |
ace_h2s | 131.1 | 106.7 |
ace_lac | 154.5 | 122.5 |
h2s_lac | 108.2 | 89.0 |
3 | 116.0 | 88.9 |
every resampling method picks h2s_lac; the training MSE alone would pick the full model. adding Acetic to h2s_lac lowers the training MSE by 0.02 and raises the LOOCV error by 8.9. for the full model LOOCV is 28% above the training MSE (113.4 against 88.9): the optimism, made visible. a single 5-fold run can put ace_h2s anywhere from 117 to 157 — the split variability LOOCV removes — and the 5-fold means sit a little above LOOCV because each fold trains on 24 cheeses, not 29. the shortcut reproduces the LOOCV column with 7 fits instead of 210.
predicting mpg from polynomials in horsepower (ISLR Auto, \(N = 392\)), the shortcut gives LOOCV errors 24.23, 19.25, 19.33, 19.42, 19.03, 18.98, 18.83 for degrees 1–7: a drop of 5 from linear to quadratic, then a plateau within 0.6 of 19. ten random validation splits scatter by about 6 units at each degree; ten repetitions of 10-fold CV by only 0.3–0.5. all three methods say quadratic; the further decrease to degree 7 is within the noise of the estimates.
proofs
assume \(\mathbf X\) and \(\mathbf X\) without row \(i\) have full column rank. let \(\tilde{\mathbf y}\) be \(\mathbf y\) with \(y_i\) replaced by \(\tilde y_i = x_i^\top\hat\beta_{(-i)}\). for any \(\beta\),
\begin{align*} \textstyle\sum_j (\tilde y_j - x_j^\top\beta)^2 &\ge \textstyle\sum_{j \ne i} (y_j - x_j^\top\beta)^2 && \text{drop the } i\text{-th square} \\ &\ge \textstyle\sum_{j \ne i} (y_j - x_j^\top\hat\beta_{(-i)})^2 && \hat\beta_{(-i)} \text{ minimises this} \\ &= \textstyle\sum_j (\tilde y_j - x_j^\top\hat\beta_{(-i)})^2, && i\text{-th term is } 0 \end{align*}
so \(\hat\beta_{(-i)}\) is the full-design least-squares fit to \(\tilde{\mathbf y}\), and \(\tilde y_i = (\mathbf H\tilde{\mathbf y})_i\). since \(\tilde{\mathbf y} = \mathbf y + (\tilde y_i - y_i)\mathbf e_i\),
\begin{align*} \tilde y_i &= \hat y_i + h_i(\tilde y_i - y_i) && \text{linearity}, (\mathbf H \mathbf e_i)_i = h_i \\ y_i - \tilde y_i &= \frac{y_i - \hat y_i}{1 - h_i}. && \text{solve for } \tilde y_i \text{, subtract from } y_i \end{align*}
the bootstrap
draw \(B\) data sets of size \(N\) with replacement from the training pairs and refit on each. for a statistic \(S\), the bootstrap variance estimate is the sample variance of the \(B\) replicates, \(\frac{1}{B-1}\sum_b (S_b - \bar S^*)^2\): a Monte Carlo estimate of \(\operatorname{Var}(S)\) under sampling from the empirical distribution.
for taste ~ H2S + Lactic with \(B = 500\), the bootstrap standard errors are 0.73 (H2S) and 6.52 (Lactic) against the model-based 1.14 and 7.96 — the bootstrap assumes neither normality nor constant variance, and here judges the fit a little more stable than normal theory does. as a prediction-error estimator the bootstrap needs more care.
with \(\hat f^{\,b}\) the fit to the \(b\)-th bootstrap sample and \(C^{-i}\) the set of samples not containing observation \(i\):
\begin{align*} \widehat{\mathrm{Err}}_{\mathrm{boot}} &= \frac{1}{BN}\sum_b \sum_i (y_i - \hat f^{\,b}(x_i))^2 && \text{naive} \\ \widehat{\mathrm{Err}}_{\mathrm{boot}^*} &= \frac1N \sum_i \frac{1}{|C^{-i}|} \sum_{b \in C^{-i}} (y_i - \hat f^{\,b}(x_i))^2 && \text{leave-one-out bootstrap} \\ \widehat{\mathrm{Err}}^{0.632} &= 0.368\,\overline{\mathrm{err}} + 0.632\,\widehat{\mathrm{Err}}_{\mathrm{boot}^*} \\ \widehat{\mathrm{Err}}^{0.632+} &= (1 - \hat w)\,\overline{\mathrm{err}} + \hat w\,\widehat{\mathrm{Err}}_{\mathrm{boot}^*}, && \hat w = \frac{0.632}{1 - 0.368\hat R} \end{align*}
where \(\hat\gamma = N^{-2}\sum_i\sum_{i’} (y_i - \hat f(x_{i’}))^2\) is the no-information error rate (every response paired with every fitted value) and \[ \hat R = (\widehat{\mathrm{Err}}_{\mathrm{boot}^*} - \overline{\mathrm{err}})/(\hat\gamma - \overline{\mathrm{err}}) \in [0,1] \] the relative overfitting rate.
the naive estimate is too optimistic because training and test sets overlap; the leave-one-out bootstrap predicts each point only from fits that never saw it, but is pessimistic for a reason the next result makes precise.
\[ \Pr(\text{observation } i \in \text{bootstrap sample}) = 1 - (1 - 1/N)^N \to 1 - e^{-1} \approx 0.632\,, \] so each bootstrap fit sees about 63% of the distinct observations and \(\widehat{\mathrm{Err}}_{\mathrm{boot}^*}\) is biased upward roughly like 2-fold CV. the 0.632+ weight runs from \(0.632\) (\(\hat R = 0\)) to \(1\) (\(\hat R = 1\)), so whenever \(\widehat{\mathrm{Err}}_{\mathrm{boot}^*} \ge \overline{\mathrm{err}}\), \[ \widehat{\mathrm{Err}}^{0.632} \le \widehat{\mathrm{Err}}^{0.632+} \le \widehat{\mathrm{Err}}_{\mathrm{boot}^*}. \]
the convergence is fast: \(1 - (1 - 1/N)^N\) is 0.750 at \(N = 2\), 0.651 at \(N = 10\), 0.638 at \(N = 30\) (19.2 distinct cheeses per sample on average).
with \(B = 500\) (set.seed(1)): \(\overline{\mathrm{err}} = 2669.0/30 = 88.97\), \(\widehat{\mathrm{Err}}_{\mathrm{boot}} = 96.93\), \(\widehat{\mathrm{Err}}_{\mathrm{boot}^*} = 114.28\) (\(|C^{-i}|\) between 156 and 205). for a linear model with intercept \(\hat\gamma\) has the closed form
\[ (2\,\mathrm{TSS} - \mathrm{RSS})/N = (2 \times 7662.9 - 2669.0)/30 = 421.89\,. \]
then
\begin{align*} \hat R &= \frac{114.28 - 88.97}{421.89 - 88.97} = 0.076, \qquad \hat w = \frac{0.632}{1 - 0.368 \times 0.076} = 0.650, \\ \widehat{\mathrm{Err}}^{0.632} &= 0.368 \times 88.97 + 0.632 \times 114.28 = 104.97, \\ \widehat{\mathrm{Err}}^{0.632+} &= 0.350 \times 88.97 + 0.650 \times 114.28 = 105.43. \end{align*}
the ordering
\[ 89.0 < 96.9 < 105.0 < 105.4 < 114.3 \]
is the whole story: training error optimistic, naive bootstrap dragged towards it, leave-one-out bootstrap pessimistic, and the two corrected estimators landing beside LOOCV’s 104.5. for the full model \(\hat R = 0.128\), \(\hat w = 0.663\) and \(\widehat{\mathrm{Err}}^{0.632+} = 117.1\): more overfitting, more weight on the pessimistic end, and h2s_lac is again preferred.
proofs
the number of times \(i\) is drawn is \(\mathrm{Bin}(N, 1/N)\), so \(\Pr(i \in b) = 1 - (1 - 1/N)^N \to 1 - e^{-1}\); by linearity the expected number of distinct observations is \(N(1 - (1 - 1/N)^N)\). \(\hat w\) is increasing in \(\hat R\), equal to \(0.632\) at \(0\) and \(0.632/0.632 = 1\) at \(1\). with \(E^* = \widehat{\mathrm{Err}}_{\mathrm{boot}^*}\) and \(D = E^* - \overline{\mathrm{err}} \ge 0\),
\begin{align*} \widehat{\mathrm{Err}}^{0.632+} - \widehat{\mathrm{Err}}^{0.632} &= (\hat w - 0.632)\, D \ge 0, \\ E^* - \widehat{\mathrm{Err}}^{0.632+} &= (1 - \hat w)\, D \ge 0. \end{align*}
information criteria
instead of resampling, estimate the optimism and add it back. by the optimism identity, every criterion has the shape training error + penalty growing with model size.
for a model with \(p\) predictors (\(d\) estimated parameters) and maximised log-likelihood \(\ell(\hat\beta)\):
\begin{align*} C_p &= \overline{\mathrm{err}} + \frac{2p\hat\sigma^2}{N}, && \hat\sigma^2 \text{ from the largest candidate model} \\ \mathrm{AIC} &= -2\ell(\hat\beta) + 2d, \qquad \mathrm{AIC}_c = \mathrm{AIC} + \frac{2d(d+1)}{N - d - 1}, \\ \mathrm{BIC} &= -2\ell(\hat\beta) + d\log N, \\ R^2_{\mathrm{adj}} &= 1 - (1 - R^2)\frac{n-1}{n-p-1} = 1 - \frac{\mathrm{RSS}/(n-p-1)}{\mathrm{TSS}/(n-1)}. \end{align*}
minimise \(C_p\), AIC, AICc, BIC; maximise \(R^2_{\mathrm{adj}}\).
for \(y_i \sim N(x_i^\top\beta, \sigma^2)\) with \(\sigma^2\) known, \(\mathrm{AIC} = \mathrm{RSS}/\sigma^2 + 2d + N\log(2\pi\sigma^2)\), so \(\frac{\sigma^2}{N}\mathrm{AIC} = \overline{\mathrm{err}} + 2d\sigma^2/N + \text{const}\) — exactly \(\overline{\mathrm{err}}\) plus the average optimism. with \(\sigma^2\) estimated by \(\mathrm{RSS}/N\), \(-2\ell = N\log(\mathrm{RSS}/N) + N(\log 2\pi + 1)\), and R’s extractAIC, drop1 and add1 report \(N\log(\mathrm{RSS}/N) + 2d\).
- \(C_p\) estimates \(\mathrm{Err}_{\mathrm{in}}\) directly; whether \(p\) counts the intercept shifts every model by the same \(2\hat\sigma^2/N\) and never changes the choice.
- AIC aims at prediction error asymptotically. its comparison of nested models behaves like a test with fixed type I error, so it keeps a fixed positive probability of choosing a too-large model however big \(N\) is: AIC is not consistent. AICc corrects its small-sample bias; Burnham and Anderson recommend it unless \(N/d > 40\).
- BIC’s per-parameter price \(\log N\) exceeds AIC’s 2 from \(N = 8\) on (\(\log 7 = 1.95\), \(\log 8 = 2.08\)), so BIC picks smaller models. the lowest-BIC model has the highest approximate posterior probability under a uniform prior over models, and BIC is consistent: it selects the true model, if among the candidates, with probability tending to one.
- \(R^2\) never decreases when a predictor is added (the larger model can set the new coefficient to zero), so it always prefers the biggest model. \(R^2_{\mathrm{adj}}\) compares variance estimates on their own degrees of freedom and falls when a useless predictor enters, but it still tends to overfit.
\(N = 30\), \(\mathrm{TSS} = 7662.9\), \(C_p\) uses \(\hat\sigma^2 = 2668.4/26 = 102.6\) from the full model. R’s AIC() counts \(\sigma^2\) as a parameter (\(d = p + 2\)) and keeps the constants, so it equals extractAIC \(+ 87.14\).
| model | \(p\) | RSS | \(R^2\) | \(R^2_{\mathrm{adj}}\) |
|---|---|---|---|---|
ace | 1 | 5348.7 | 0.3020 | 0.2771 |
h2s | 1 | 3286.1 | 0.5712 | 0.5559 |
lac | 1 | 3862.5 | 0.4959 | 0.4779 |
ace_h2s | 2 | 3201.7 | 0.5822 | 0.5512 |
ace_lac | 2 | 3676.1 | 0.5203 | 0.4847 |
h2s_lac | 2 | 2669.0 | 0.6517 | 0.6259 |
3 | 3 | 2668.4 | 0.6518 | 0.6116 |
| model | AIC() | BIC() | extractAIC | \(C_p\) |
|---|---|---|---|---|
ace | 246.64 | 250.84 | 159.50 | 185.1 |
h2s | 232.02 | 236.23 | 144.89 | 116.4 |
lac | 236.87 | 241.08 | 149.74 | 135.6 |
ace_h2s | 233.24 | 238.85 | 146.11 | 120.4 |
ace_lac | 237.39 | 242.99 | 150.25 | 136.2 |
h2s_lac | 227.78 | 233.39 | 140.65 | 102.7 |
3 | 229.78 | 236.78 | 142.64 | 109.5 |
for h2s_lac: \(30\log(2669.0/30) = 134.65\), so extractAIC \(= 134.65 + 6 = 140.65\) and BIC() \(= 134.65 + 85.14 + 4\log 30 = 233.39\). adding Acetic raises \(R^2\) by 0.0001 and is rejected by every adjusted criterion (AICc too: 229.4 against 232.3). the selected model, the one LOOCV also chose, is
\[
\widehat{\texttt{taste}} = -27.59 + 3.95\,\texttt{H2S} + 19.89\,\texttt{Lactic}.
\]
proofs
the normal log-likelihood at \(\hat\beta\) is
\begin{align*} \ell(\hat\beta) &= -\tfrac N2 \log(2\pi\sigma^2) - \tfrac{1}{2\sigma^2}\textstyle\sum_i (y_i - x_i^\top\hat\beta)^2, \\ -2\ell(\hat\beta) &= N\log(2\pi\sigma^2) + \mathrm{RSS}/\sigma^2; && \text{add } 2d \text{, multiply by } \sigma^2/N \end{align*}
maximising over \(\sigma^2\) as well gives \(\hat\sigma^2 = \mathrm{RSS}/N\) and \(-2\ell = N\log(\mathrm{RSS}/N) + N\log 2\pi + N\). for adjusted \(R^2\), substitute \(1 - R^2 = \mathrm{RSS}/\mathrm{TSS}\) and regroup the two ratios.
AIC. under deviance loss the optimism identity generalises: for a correctly specified model and large \(N\), the expected optimism of \(-\frac{2}{N}\ell\) is \(2d/N\) (ESL section 7.5), and AIC is \(-2\ell\) plus \(N\) times that. for gaussian errors this is the linear-smoother calculation above. BIC. with prior \(\pi(\theta)\) on a model’s \(d\) parameters, the marginal likelihood is \(\int L(\theta)\pi(\theta)\,d\theta\). a Laplace expansion around \(\hat\theta\), where the log-likelihood has curvature \(N\mathcal I_1(\hat\theta)\) with \(\mathcal I_1\) the per-observation information, gives \[ -2\log \int L(\theta)\pi(\theta)\,d\theta = -2\ell(\hat\theta) + d\log N + O(1), \] since \(|N\mathcal I_1|^{-1/2} = N^{-d/2}|\mathcal I_1|^{-1/2}\) and the remaining terms do not grow with \(N\). with equal prior model probabilities, minimising BIC maximises the approximate posterior model probability. (this sketch is the standard argument, not one worked in the course notes.)
variable selection
best subset selection fits all \(2^p\) models and, for each size, keeps the one optimising a criterion. backward elimination starts from the full model and repeatedly deletes the predictor whose removal most lowers the criterion, stopping when no deletion helps; forward selection starts from the intercept and adds the predictor that most lowers it.
two facts organise the search. at a fixed size \(R^2_{\mathrm{adj}}\), AIC, AICc and BIC all agree — the penalty is the same for every subset of that size, so each is a monotone function of RSS — and within one stepwise step the AIC ranking is the ranking by single-term \(F\)-test \(p\)-value. only across sizes do the penalties disagree. and the shortcut has a price:
neither stepwise method need find the subset minimising the criterion over all \(2^p\), and the two need not agree with each other. each sees only the models along its own path and never revisits a decision; a pair of predictors useless alone but strong together is invisible to forward selection.
backward, from the full model (AIC on the extractAIC scale):
> drop1(lm(taste ~ ., data = cheddar))
Df Sum of Sq RSS AIC
<none> 2668.4 142.64
Acetic 1 0.55 2669.0 140.65
H2S 1 1007.66 3676.1 150.25
Lactic 1 533.32 3201.7 146.11
dropping Acetic saves a parameter worth 2 at a cost of \(30\log(2669.0/2668.4) = 0.006\); from H2S + Lactic both further deletions raise AIC (to 149.74 and 144.89), so backward stops. forward from the intercept (AIC 168.29): H2S enters first (144.89), then Lactic (140.65); adding Acetic would raise AIC to 142.64. both paths reach taste ~ H2S + Lactic — a fact about these data, not the methods.
best subset selection for Salary on 19 predictors (ISLR Hitters, \(N = 263\) after dropping 59 missing salaries; \(2^{19} = 524\,288\) subsets) with regsubsets from leaps. RSS falls monotonically with size, as it must. \(R^2_{\mathrm{adj}}\) peaks at 11 variables (0.5226), \(C_p\) bottoms at 10 (5.0, then rising about 2 per useless variable), BIC at 6 (\(-147.9\); \(\log 263 = 5.57\) per parameter). the heavier the penalty, the smaller the model. the best subsets are not nested: CRBI is in the best models of sizes 1–6 but not 7, which no stepwise path can reproduce. the BIC choice is
\[
\widehat{\texttt{Salary}} = 91.51 - 1.87\,\texttt{AtBat} + 7.60\,\texttt{Hits} + 3.70\,\texttt{Walks} + 0.64\,\texttt{CRBI} - 122.95\,\texttt{DivisionW} + 0.26\,\texttt{PutOuts}.
\]
proofs
at fixed \(p\), \(R^2_{\mathrm{adj}} = 1 - \frac{n-1}{n-p-1}\frac{\mathrm{RSS}}{\mathrm{TSS}}\), \(\mathrm{AIC} = N\log(\mathrm{RSS}/N) + c_p\) and \(\mathrm{BIC} = N\log(\mathrm{RSS}/N) + c’_p\), each a strictly monotone function of RSS alone, so all pick the smallest-RSS subset. for nested \(M_0 \subset M_1\), every coefficient vector of \(M_0\) is one of \(M_1\) with extra zeros, so \(\min_{M_1} \mathrm{RSS} \le \min_{M_0}\mathrm{RSS}\) and \(R^2(M_1) \ge R^2(M_0)\).
beyond selection
subset selection is discrete: a coefficient is fitted freely or forced to zero, so small changes in the data can flip the chosen model, and the search is exponential in \(p\). two continuous alternatives use all \(p\) predictors while controlling the effective model size. shrinkage — ridge, lasso, elastic net — penalises coefficients (regularised regression), and its effective degrees of freedom \(\operatorname{tr}\mathbf H_\lambda\) slot straight into \(C_p\) via the optimism identity. dimension reduction — principal components regression — regresses on \(M < p\) linear combinations of the predictors. in both, the tuning parameter (\(\lambda\) or \(M\)) is chosen by the cross-validation of this page.
see also
- the bias-variance decomposition — why test error is U-shaped; the derivation is there, not here
- cross-validation — a worked notebook tuning ridge and lasso by LOOCV
- regularised regression — shrinkage as the continuous alternative to subset selection
- regression diagnostics — leverage and the deleted residuals the LOOCV shortcut is built from
- linear regression — the hat matrix and RSS every criterion here consumes
- generalised linear models — deviance loss, and AIC/BIC for non-gaussian likelihoods
- analysis of variance — the \(F\)-tests that stepwise \(p\)-value rules reduce to
- performance metrics — error rates, sensitivity and ROC for classifiers
Comments