Quiz: why penalize?
Short conceptual questions to test your grasp of why penalized regression exists. Try each on paper first, then open the answer.
Q1. What does “p ≫ n” mean for a gene-expression dataset, and why is that shape a problem for ordinary least squares?
Count the predictors versus the samples. What does the model need in order to have a unique solution?
\(p\) is the number of predictors (genes) and \(n\) is the number of samples (patients/cells); \(p \gg n\) means far more genes than samples. Each sample is one equation and each coefficient one unknown. With \(p > n\) there are more unknowns than equations, so infinitely many sets of coefficients fit the data perfectly: there is no unique solution — the model is unidentifiable.
Q2. A study measures 25 patients and fits a linear model with an intercept and 40 genes. How many equations and how many unknowns are there? What will lm() report for some of the genes?
One equation per patient, one unknown per coefficient (do not forget the intercept).
25 equations and 41 unknowns (intercept + 40 genes). There are more unknowns than equations, so infinitely many coefficient sets fit perfectly. lm() estimates the intercept and 24 genes and returns NA for the other 16, and it fits all 25 patients exactly.
Q3. (optional) In the matrix form \(\hat{\boldsymbol{\beta}} = (X^\top X)^{-1} X^\top \mathbf{y}\), why exactly does \(p > n\) make \(X^\top X\) non-invertible? Use the word rank.
The rank of \(X^\top X\) cannot exceed the number of samples. When is a \(p\times p\) matrix invertible?
\(\text{rank}(X^\top X) \le n\). A \(p \times p\) matrix is invertible only if its rank equals \(p\). When \(p > n\), the rank is at most \(n < p\), so the matrix is rank-deficient (singular) and has no inverse.
Q4. Suppose \(p < n\), so there are more samples than coefficients. Name a common biological situation that still makes ordinary least squares coefficients huge and unstable, and say why.
Think about genes in the same pathway. Can two genes that always move together be told apart?
Correlated predictors — co-regulated genes move together, so one can stand in for the other. Very different coefficient pairs (say \(1, 1\) or \(100, -98\)) then give almost the same predictions: the data pin down the sum of the two coefficients but not the split. The noise decides which split ordinary least squares returns, so the coefficients become large and unstable (multicollinearity).
Q5. True or false: the model that fits the training data best is the best model. Explain.
What do we actually want the model to do — describe this data, or predict new data?
False. A model flexible enough to fit the training data perfectly usually has learned the noise, not the signal, and predicts new data badly — it overfits. We care about generalisation to the next patient, not a perfect fit to the samples we already have.
Q6. Define bias and variance in one sentence each, and say which one ordinary least squares with many predictors suffers from.
One comes from a model that is too rigid, the other from a model that is too flexible.
Bias is error from a model too rigid to capture the true pattern (underfitting). Variance is error from a model so flexible it chases noise and changes wildly between samples (overfitting). Ordinary least squares with many predictors is low bias, high variance — it overfits.
Q7. In words, what does adding a penalty term \(\lambda\cdot(\text{coefficient size})\) to the least-squares objective do, and what is the role of \(\lambda\)?
The objective now has two competing parts. What does the second part discourage, and what does \(\lambda\) set?
It charges for large coefficients, so the fit must justify every unit of coefficient it uses; this shrinks coefficients toward zero and stabilises them. \(\lambda \ge 0\) sets how strong the penalty is — the bias–variance dial: \(\lambda = 0\) is ordinary least squares (low bias, high variance), large \(\lambda\) heavily shrinks (high bias, low variance).
Q8. (optional) The ridge penalty changes the normal equations to use \(X^\top X + \lambda I\) instead of \(X^\top X\). Why does this matrix have an inverse even when \(p > n\)?
What does adding \(\lambda I\) do to the eigenvalues? When is a matrix invertible?
Adding \(\lambda I\) lifts every eigenvalue of \(X^\top X\) by \(\lambda\). A matrix is invertible exactly when none of its eigenvalues is zero, so any zero eigenvalue (which is what made the \(p > n\) case singular) becomes \(\lambda > 0\). Hence \(X^\top X + \lambda I\) is always invertible for \(\lambda > 0\), and there is again a unique solution.
Q9. Name one bonus a biologist gets from penalization beyond “the model is now computable,” and one price paid for it.
Think about reproducibility of gene signatures and prediction on new patients — and what shrinkage does to the estimates.
Bonus (any one): more stable, reproducible coefficients that don’t flip when you swap a few patients; better prediction on held-out patients; and with some penalties (lasso), most coefficients go exactly to zero, giving a short interpretable gene list. Price: shrinkage introduces bias — the estimates are systematically pulled toward zero, so choosing \(\lambda\) well (later, by cross-validation) matters.