Tutorials › High-Dimensional Genomic Data Analysis › The Penalized Least-Squares Objective

Penalized Regression for p Much Larger Than n · Tutorial 513 of 795

The Penalized Least-Squares Objective

Learn how ridge, lasso, and elastic-net objectives balance squared prediction error against coefficient penalties, and how to calculate and interpret each objective.

Advanced 10 min read

What You'll Learn

  • Write the penalized least-squares objective for ridge, lasso, and elastic net.
  • Distinguish the intercept from the coefficients that receive penalties.
  • Interpret the tuning parameter and elastic-net mixing parameter.
  • Calculate objective values for hypothetical genomic predictor data.
  • Recognize how objective scaling and predictor units affect interpretation.
  • Identify assumptions, diagnostics, and common errors in using the objective.

Why the Objective Has Two Parts

In genomic prediction, the number of measured features can exceed the number of samples. A fitted model may then match the observed responses closely while relying on coefficients that are unstable or unnecessarily large. Penalized least squares formalizes a trade-off: fit the observed responses well, but also limit the size or number of the predictor coefficients.

Let \(n\) be the number of samples and \(p\) the number of predictors. For sample \(i\), let \(y_i\) be the quantitative response and \(x_{ij}\) the value of predictor \(j\), such as an expression measurement, for \(j=1,\ldots,p\). A linear predictor is \(\beta_0+\sum_{j=1}^{p}x_{ij}\beta_j\), where \(\beta_0\) is the intercept and \(\beta_j\) is the coefficient for predictor \(j\). Write \(\boldsymbol{\beta}=(\beta_1,\ldots,\beta_p)\).

A conventional model for describing the response is \(y_i=\beta_0+\sum_{j=1}^{p}x_{ij}\beta_j+\varepsilon_i\). The usual regression interpretation assumes a correctly specified linear conditional mean, with errors having mean zero and independent observations; constant error variance is a common additional assumption. Gaussian errors are not required to define or minimize the squared-error objective. These assumptions matter for statistical interpretation, but the objective itself is a deterministic function of the observed response and predictor values.

Definition: The residual for sample \(i\) at a proposed set of coefficients is \(r_i=y_i-\beta_0-\sum_{j=1}^{p}x_{ij}\beta_j\). The scaled squared-error loss is \(L(\beta_0,\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=1}^{n}r_i^2\). A penalized least-squares fit minimizes this loss plus a penalty on \(\boldsymbol{\beta}\). In the objectives below, the intercept \(\beta_0\) is not penalized.

The factor \(1/n\) makes the loss an average over samples, while \(1/2\) is a convenient constant for differentiation. Neither changes which coefficients minimize ordinary least squares by itself. The penalty, however, is scaled relative to this particular loss, so the numerical value of the tuning parameter depends on the convention used for the objective.

Three Penalized Least-Squares Objectives

The ridge penalty is based on the sum of squared coefficients; the lasso penalty is based on the sum of their absolute values. The elastic-net penalty combines both. In every case, the intercept is excluded from the sums.

Definition: For \(\lambda\geq 0\), the ridge objective is $$ Q_{\mathrm{ridge}}(\beta_0,\boldsymbol{\beta}) = \frac{1}{2n}\sum_{i=1}^{n} \left(y_i-\beta_0-\sum_{j=1}^{p}x_{ij}\beta_j\right)^2 +\frac{\lambda}{2}\sum_{j=1}^{p}\beta_j^2. $$ The lasso objective is $$ Q_{\mathrm{lasso}}(\beta_0,\boldsymbol{\beta}) = \frac{1}{2n}\sum_{i=1}^{n} \left(y_i-\beta_0-\sum_{j=1}^{p}x_{ij}\beta_j\right)^2 +\lambda\sum_{j=1}^{p}|\beta_j|. $$ For elastic net, let \(0\leq\rho\leq1\). Its objective is $$ Q_{\mathrm{EN}}(\beta_0,\boldsymbol{\beta}) = \frac{1}{2n}\sum_{i=1}^{n} \left(y_i-\beta_0-\sum_{j=1}^{p}x_{ij}\beta_j\right)^2 +\lambda\left[ \frac{1-\rho}{2}\sum_{j=1}^{p}\beta_j^2 +\rho\sum_{j=1}^{p}|\beta_j| \right]. $$ Here \(\lambda\) controls the overall penalty strength, while \(\rho\) sets the mixture: \(\rho=0\) gives ridge and \(\rho=1\) gives lasso.

The squared-error part rewards predictions close to the observed responses. The penalty discourages large coefficients, and the lasso penalty can yield coefficients exactly equal to zero. The parameter \(\lambda\) balances these objectives: \(\lambda=0\) removes the penalty, and increasing \(\lambda\) gives the penalty more influence. It is a tuning parameter, not an estimated error variance or a significance level. The mixture parameter \(\rho\) changes the form of the elastic-net penalty rather than its overall strength.

These objectives are convex in the coefficients, so a local minimum is also a global minimum. For \(p>n\), the unpenalized least-squares coefficients need not be uniquely determined. Penalization changes the optimization problem, but does not guarantee that the coefficient vector is uniquely determined in every design, particularly for the lasso. The objective definition alone also does not specify how \(\lambda\) is chosen; in prediction work it is commonly selected using data not used to assess final predictive performance.

Worked Example: Evaluating a Ridge Objective

Consider the following entirely hypothetical data for three samples and two expression predictors. Evaluate the ridge objective at \(\beta_0=2\), \(\beta_1=1\), and \(\beta_2=0.5\), using \(\lambda=0.6\). These are proposed coefficients for evaluating the objective, not a claim that they minimize it.

Sample\(y_i\)\(x_{i1}\)\(x_{i2}\)
1201
2310
3521

The fitted values are \(2+0(1)+1(0.5)=2.5\), \(2+1(1)+0(0.5)=3\), and \(2+2(1)+1(0.5)=4.5\). The residuals are \(-0.5,0,0.5\), so the squared-error part is \( \{(-0.5)^2+0^2+(0.5)^2\}/(2\cdot3)=0.5/6=0.08333\).

The ridge penalty is \((0.6/2)(1^2+0.5^2)=0.3(1.25)=0.375\). Therefore \(Q_{\mathrm{ridge}}=0.08333+0.375=0.4583\). The intercept contributes to the predictions and hence to the residuals, but it does not appear in the penalty.

Worked Example: Evaluating a Lasso Objective

Use the same hypothetical samples and proposed coefficients, but evaluate the lasso objective at \(\lambda=0.2\). The fitted values and residuals are unchanged, so the squared-error part is \(0.08333\).

The lasso penalty is \(0.2(|1|+|0.5|)=0.2(1.5)=0.3000\). Thus \(Q_{\mathrm{lasso}}=0.08333+0.3000=0.3833\).

This calculation evaluates one point in coefficient space. It does not establish that either coefficient will be zero at the minimizing fit. The absolute-value penalty makes zero a possible fitted coefficient, but which coefficients are zero depends on the data and the value of \(\lambda\).

Worked Example: Evaluating an Elastic-Net Objective

Again use the same data and proposed coefficients, now with \(\lambda=0.3\) and \(\rho=0.4\). The squared-error part remains \(0.08333\). The squared-coefficient contribution inside the brackets is \(\{(1-0.4)/2\}(1^2+0.5^2)=0.3(1.25)=0.375\). The absolute-coefficient contribution is \(0.4(|1|+|0.5|)=0.4(1.5)=0.6000\).

The combined penalty is \(0.3(0.375+0.6000)=0.2925\). The full objective is therefore \(Q_{\mathrm{EN}}=0.08333+0.2925=0.3758\). The two penalty components are weighted before they are added; \(\rho\) is not an extra penalty added outside the factor \(\lambda\).

Why the Intercept Is Treated Separately

The intercept represents the baseline response when all predictors equal zero. Penalizing it would shrink that baseline toward zero simply because of its numerical value, rather than because the predictors provide an unnecessarily complex description. The standard objectives therefore penalize the predictor coefficients but leave \(\beta_0\) unpenalized.

One useful check follows by differentiating the objective with respect to the intercept. For any of the three objectives, the penalty has no \(\beta_0\) term. At a minimizing fit, holding \(\boldsymbol{\beta}\) fixed, the derivative with respect to \(\beta_0\) must be zero:

$$ \frac{\partial Q}{\partial\beta_0} = -\frac{1}{n}\sum_{i=1}^{n} \left(y_i-\beta_0-\sum_{j=1}^{p}x_{ij}\beta_j\right) =0 \quad\Longrightarrow\quad \sum_{i=1}^{n}r_i=0. $$

Thus, when the intercept is freely optimized, the residuals sum to zero at a minimizing fit. This does not say that every residual is zero, nor that the predictors explain every response. It is a consequence of fitting an unpenalized intercept under squared error.

Comparing the Penalties and Checking a Fit

ObjectivePenalty on predictor coefficientsPractical distinction
Ridge\(\frac{\lambda}{2}\sum_j\beta_j^2\)Discourages large coefficients; coefficients are generally shrunk rather than set exactly to zero.
Lasso\(\lambda\sum_j|\beta_j|\)Can set some fitted coefficients exactly to zero.
Elastic net\(\lambda\{(1-\rho)\sum_j\beta_j^2/2+\rho\sum_j|\beta_j|\}\)Combines squared and absolute coefficient penalties; the endpoints are ridge and lasso.

A calculation or fitted model should be checked against the definition actually used. First confirm the loss scaling, penalty form, and whether the intercept is excluded. Then calculate the residual loss and penalty separately; this makes arithmetic or implementation errors easier to locate. Check that the objective decreases when moving from a proposed coefficient vector to a reported minimizing vector, up to numerical tolerance. The residual pattern and predictive performance should also be examined: a small training loss alone does not show that predictions will generalize to new samples.

The penalty depends on coefficient magnitudes, so predictor measurement units matter. If one expression measurement is recorded on a much larger numerical scale than another, equal coefficient magnitudes need not represent equal changes in predicted response. The objective remains mathematically defined, but its penalty can treat predictors differently as a result of their units. This is a limitation to consider when interpreting or comparing penalized fits.

Common Mistakes and Limitations

  • Penalizing the intercept by default. The intercept belongs in the prediction equation, but standard ridge, lasso, and elastic-net objectives exclude it from the penalty.
  • Calling \(\lambda\) a significance level. It controls the strength of the coefficient penalty; it is not \(\alpha\), a p-value, or the probability that a hypothesis is true.
  • Assuming the same numerical \(\lambda\) means the same fit under every convention. Multiplying the loss or penalty by a constant changes the scale of the tuning parameter required to obtain the same balance.
  • Assuming a lasso penalty guarantees a unique coefficient vector. The objective is convex, but different coefficient vectors can sometimes attain the same minimum.
  • Interpreting a low training objective as proof of good prediction. The objective is optimized on the observed data; performance on new samples must be assessed separately.

The objective specifies what is optimized, not every part of an analysis. It does not by itself justify a linear conditional mean, resolve dependence among samples, choose a tuning parameter, or establish causal effects. Its main contribution is precise: it makes the trade-off between squared error and coefficient penalty explicit.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. For the ridge objective defined here, what is penalized, and what happens to the penalty term when \(\lambda=0\)?
  2. At a proposed fit with coefficients \((\beta_1,\beta_2)=(-2,1)\), calculate the lasso penalty when \(\lambda=0.1\).
  3. What values of \(\rho\) make the elastic-net objective equal to ridge and lasso, respectively?
  4. Why does the intercept affect the squared-error loss but not the standard ridge penalty?
  5. A researcher reports a small training loss and concludes that the model will predict well in new samples. What is missing from this conclusion?

Solutions. (1) The predictor coefficients \(\beta_1,\ldots,\beta_p\) are penalized; at \(\lambda=0\), the penalty is zero and the objective is ordinary scaled squared error. (2) The penalty is \(0.1(|-2|+|1|)=0.1(3)=0.3000\). (3) \(\rho=0\) gives ridge, and \(\rho=1\) gives lasso. (4) The intercept enters every fitted value and residual, but the standard penalty is defined only over predictor coefficients. (5) Training loss does not establish performance on new samples; predictive performance needs assessment on data not used to fit the model.

Clinical Biostats