Tutorials › High-Dimensional Genomic Data Analysis › Coordinate Descent Updates for Lasso and Elastic Net

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

Coordinate Descent Updates for Lasso and Elastic Net

Derive and apply coordinatewise lasso and elastic-net updates, including residual calculations and optimality checks for standardized genomic predictors.

Advanced 10 min read

What You'll Learn

  • Write the squared-error lasso and elastic-net objectives using a consistent penalty parameterization.
  • Derive the soft-thresholding coordinate update from a one-dimensional minimization.
  • Apply cyclic updates to a small, correlated, standardized design matrix.
  • Identify when a coordinate update sets a coefficient to zero.
  • Check coordinatewise optimality and recognize common implementation and interpretation errors.
  • Compare coordinate descent with orthogonal-design updates and full-system optimization.

Why Update One Coefficient at a Time?

In genomic regression, the number of predictors can exceed the number of samples, so fitting a model by inverting the full predictor cross-product matrix is generally not an option. Lasso and elastic net avoid that requirement: with all coefficients but one held fixed, each coefficient has a simple one-dimensional minimization. Repeatedly minimizing over coordinates gives cyclic coordinate descent, a practical way to fit these penalized models even when \(p>n\).

The update depends on the predictor's association with the response after accounting for the other current coefficients. It is not, in general, the same as applying the orthogonal-predictor lasso formula to each predictor separately. Correlation between predictors enters through the partial residual.

Model, Scaling, and Objective

Let \(y\) be a response vector of length \(n\), and let \(X\) contain \(p\) predictor columns \(x_1,\ldots,x_p\). Assume the predictors have been centered and standardized so that \(\sum_{i=1}^{n}x_{ij}=0\) and \(x_j^\top x_j/n=1\) for each \(j\). An intercept is left unpenalized; with centered predictors, it is estimated by \(\bar y\). Equivalently, the formulas below apply to a centered response after the intercept has been removed.

Use the following parameterization, with \(\lambda\geq 0\) and \(0\leq\alpha\leq 1\):

$$ Q(\beta)=\frac{1}{2n}\lVert y-X\beta\rVert_2^2+ \lambda\left(\alpha\sum_{j=1}^{p}|\beta_j|+ \frac{1-\alpha}{2}\sum_{j=1}^{p}\beta_j^2\right). $$

Here \(\beta=(\beta_1,\ldots,\beta_p)^\top\) is the coefficient vector. The lasso is the special case \(\alpha=1\). For \(0\leq\alpha<1\), the objective includes an elastic-net ridge component as well as the lasso component. It is convenient to write \(\lambda_1=\lambda\alpha\) and \(\lambda_2=\lambda(1-\alpha)\), so the penalty is \(\lambda_1\sum_j|\beta_j|+\lambda_2\sum_j\beta_j^2/2\). This convention fixes the factors of two in the updates.

Definition: For a real number \(z\) and threshold \(t\geq 0\), the soft-thresholding function is \(S(z,t)=\operatorname{sign}(z)(|z|-t)_+\), where \((u)_+=\max(u,0)\). It is zero when \(|z|\leq t\), and otherwise has the sign of \(z\) with magnitude \(|z|-t\).

The updates assume squared-error loss, a common set of observed responses, and the stated predictor scaling. The penalty is separable across coefficients, which is essential to the simple coordinatewise minimization. In practice, if predictors were standardized using a different convention, such as a sum of squares of \(n-1\), the coordinate denominator must reflect the actual column sum of squares. The earlier material on predictor scaling before penalization explains why scaling matters when penalties are applied.

Deriving the Coordinate Update

Hold every coefficient except \(\beta_j\) fixed. Define the partial residual that excludes predictor \(j\) as \(r_{-j}=y-\sum_{k\ne j}x_k\beta_k\). The parts of the objective that depend on a candidate value \(b\) for \(\beta_j\) are

$$ \frac{1}{2n}\lVert r_{-j}-x_jb\rVert_2^2+ \lambda_1|b|+\frac{\lambda_2}{2}b^2. $$

Expanding the squared norm and dropping terms that do not depend on \(b\) gives a scalar objective. Define \(z_j=x_j^\top r_{-j}/n\) and \(a_j=x_j^\top x_j/n+\lambda_2\). Then the scalar objective is \(a_jb^2/2-z_jb+\lambda_1|b|\). For standardized predictors, \(a_j=1+\lambda_2\).

$$ \begin{aligned} \frac{1}{2n}\lVert r_{-j}-x_jb\rVert_2^2+ \frac{\lambda_2}{2}b^2+\lambda_1|b| &=\frac{a_j}{2}b^2-z_jb+\lambda_1|b|+\text{constant}. \end{aligned} $$

For \(b>0\), differentiating the scalar objective gives \(a_jb-z_j+\lambda_1=0\), hence \(b=(z_j-\lambda_1)/a_j\), which is positive only if \(z_j>\lambda_1\). For \(b<0\), the derivative is \(a_jb-z_j-\lambda_1=0\), giving \(b=(z_j+\lambda_1)/a_j\), which is negative only if \(z_j<-\lambda_1\). At \(b=0\), the subgradient condition is \(|z_j|\leq\lambda_1\). These three cases yield the update:

$$ \beta_j\leftarrow\frac{S(z_j,\lambda_1)}{a_j} =\frac{S\left(x_j^\top r_{-j}/n,\lambda\alpha\right)} {x_j^\top x_j/n+\lambda(1-\alpha)}. $$

For standardized predictors, this becomes \(S(z_j,\lambda\alpha)/(1+\lambda(1-\alpha))\). The lasso update has denominator 1; the elastic-net ridge component adds to the denominator and further shrinks nonzero updates. If the coefficient is set to zero, the reason is that the partial association \(z_j\) does not exceed the lasso threshold in magnitude.

Worked Example: A Single Standardized Lasso Coordinate

Suppose a hypothetical two-sample dataset has one centered, standardized predictor \(x=(1,-1)^\top\) and centered response \(y=(2,-2)^\top\). The predictor has \(x^\top x/n=2/2=1\). Fit the lasso with \(\lambda=0.75\), starting from \(\beta=0\).

With only one predictor, the partial residual is \(r_{-1}=y\). The partial association is \(z_1=x^\top y/n=[(1)(2)+(-1)(-2)]/2=4/2=2\). The lasso has \(\lambda_1=0.75\) and \(\lambda_2=0\), so

$$ \beta_1\leftarrow\frac{S(2,0.75)}{1} =\frac{\operatorname{sign}(2)(2-0.75)}{1} =1.25. $$

The fitted values are \(X\beta=(1.25,-1.25)^\top\). The update has the same sign as the predictor-response association and is smaller than the unpenalized least-squares coefficient \(2\). The reduction is the lasso penalty acting on the coefficient.

A Cyclic Sweep on a Small Design

In a cyclic sweep, visit the predictors in a fixed order and update each using the current values of all the other coefficients. The residual form makes this efficient. If the current residual is \(r=y-X\beta\), then after changing \(\beta_j\) by \(\Delta=\beta_j^{\mathrm{new}}-\beta_j^{\mathrm{old}}\), update it as \(r\leftarrow r-x_j\Delta\). This keeps the residual consistent without recomputing the full matrix product after every coordinate.

Worked Example: One Elastic-Net Sweep With Correlated Predictors

Consider a hypothetical four-sample dataset with two standardized columns and centered response

$$ x_1=(1,1,-1,-1)^\top,\qquad x_2=(\sqrt{2},0,0,-\sqrt{2})^\top,\qquad y=(3,1,-1,-3)^\top. $$

Both columns are centered and have squared norm 4, so \(x_j^\top x_j/n=1\). Their cross-product is \(x_1^\top x_2/n=2\sqrt{2}/4=1/\sqrt{2}\), so they are correlated, not orthogonal. Use \(\lambda=0.5\), \(\alpha=0.5\), and start at \(\beta_1=\beta_2=0\). Thus \(\lambda_1=0.25\), \(\lambda_2=0.25\), and the denominator for either standardized coordinate is \(1.25\).

First update \(\beta_1\), using \(r_{-1}=y\). Its partial association is \(x_1^\top y/4=(3+1+1+3)/4=2\). Therefore

$$ \beta_1\leftarrow\frac{S(2,0.25)}{1.25} =\frac{1.75}{1.25}=1.400. $$

Next update \(\beta_2\). The partial residual is now \(r_{-2}=y-x_1(1.400)\), so its partial association is \(x_2^\top r_{-2}/4=x_2^\top y/4-(x_2^\top x_1/4)(1.400)\). Substituting the values gives

$$ \begin{aligned} z_2&=\frac{6\sqrt{2}}{4}-\frac{1}{\sqrt{2}}(1.400) =2.1213-0.9899=1.1314,\\ \beta_2&\leftarrow\frac{S(1.1314,0.25)}{1.25} =\frac{0.8814}{1.25}=0.7051. \end{aligned} $$

That completes one sweep from zero, giving \((\beta_1,\beta_2)=(1.400,0.7051)\). To show why the order matters within a sweep, update \(\beta_1\) once more using the current \(\beta_2\). Its partial association is \(2-(1/\sqrt{2})(0.7051)=1.5014\), so the new value is \(S(1.5014,0.25)/1.25=1.0011\). A later update of \(\beta_2\) would then use this new \(\beta_1\). The coordinates are not fitted independently: each update responds to the current contributions of the other predictors.

Optimality Checks and Failure Modes

A completed coordinate update minimizes the objective over that coordinate, but a single sweep does not usually minimize the full objective. At a solution, every coordinate must satisfy its one-dimensional optimality condition. Define the residual \(r=y-X\beta\) and \(g_j=x_j^\top r/n\). For the objective above, the conditions are

$$ \begin{cases} g_j=\lambda_1\operatorname{sign}(\beta_j)+\lambda_2\beta_j, &\beta_j\ne 0,\\ |g_j|\leq\lambda_1, &\beta_j=0. \end{cases} $$

These conditions follow from the derivative of the squared-error term, which is \(-x_j^\top r/n\), together with the derivative or subgradient of the penalty. They provide a practical diagnostic: a nonzero coefficient should match the signed penalty-adjusted partial association, while a zero coefficient should remain within the lasso threshold. A sizeable violation indicates that the coordinates have not yet reached a solution or that the residual, scaling, or penalty has been implemented incorrectly.

Worked Example: Checking Whether a Coordinate Should Be Zero

Suppose a hypothetical standardized gene column is \(x=(1,1,-1,-1)^\top\), and the partial residual after accounting for the other predictors is \(r_{-j}=(0.3,0.3,-0.3,-0.3)^\top\). Let \(\lambda_1=0.4\) and \(\lambda_2=0.2\). The column is centered and has \(x^\top x/4=1\), so \(a_j=1.2\). The partial association is

$$ z_j=\frac{x^\top r_{-j}}{4} =\frac{0.3+0.3+0.3+0.3}{4}=0.3. $$

Since \(|z_j|=0.3\leq 0.4\), soft thresholding gives \(S(0.3,0.4)=0\), and the coordinate update is \(\beta_j=0/1.2=0\). This is not a claim that the gene has no biological effect. It says only that, conditional on the other current coefficients and under this penalty, its partial association does not meet the threshold for a nonzero fitted coefficient.

For a convex objective, each exact coordinate update cannot increase \(Q\), because it minimizes \(Q\) over the coordinate being changed while holding the others fixed. With standardized columns, each coordinate subproblem has positive quadratic curvature, so its update is well-defined. Under the usual finite-dimensional convex coordinate-descent conditions, cycling toward coordinatewise optimality reaches a minimizer. If \(\lambda_2>0\), the squared-error term plus the ridge penalty makes the objective strictly convex in \(\beta\), giving a unique coefficient minimizer. With pure lasso, minimizers need not be unique when predictors are dependent; the fitted values can be unique even when multiple coefficient vectors attain the minimum.

This distinction matters when predictors are highly correlated. Coordinate descent can still decrease the objective, but coefficients may be sensitive to the order of updates or to small perturbations when the lasso solution is nonunique. The elastic-net ridge component can stabilize the coefficient solution, but does not make a poorly scaled or incorrectly constructed design matrix appropriate.

How Coordinate Descent Compares With Alternatives

ApproachWhat it doesPractical distinction
Orthogonal-predictor soft thresholdingApplies a soft-threshold rule to each predictor-response association.It gives a direct solution when predictor columns are orthogonal; correlated predictors require partial residuals and repeated updates.
Cyclic coordinate descentMinimizes the objective in one coefficient at a time, repeatedly cycling through predictors.Each step is inexpensive and uses the current residual; it avoids solving a \(p\)-dimensional linear system.
Full-system optimizationAttempts to optimize all coefficients jointly.Joint approaches can be useful in other settings, but a dense \(p\)-by-\(p\) system can be costly or singular when \(p>n\).

The main advantage of coordinate descent is computational simplicity, especially when residuals are updated efficiently and many coefficients remain zero. Its limitations include sensitivity to scaling, potentially slow progress with strongly correlated predictors, and the possibility of nonunique lasso coefficients. It also depends on the correct loss and penalty: these squared-error updates are not logistic-regression updates and should not be transferred unchanged to a different response model.

Common Mistakes

  • Ignoring the current coefficients. Using \(x_j^\top y/n\) at every update treats the predictors as if they were orthogonal. Use \(x_j^\top r_{-j}/n\), which accounts for the other current coefficients.
  • Dropping the elastic-net denominator. For the stated objective, the denominator is \(1+\lambda(1-\alpha)\) with standardized predictors. The ridge component changes more than the threshold.
  • Mixing penalty conventions. If the objective is written with different factors, its update must be derived from that objective. Do not combine a threshold or denominator from one parameterization with another.
  • Assuming a zero update proves a true effect is absent. A zero is a penalized-model result conditional on the other coefficients, the response, scaling, and chosen penalty.
  • Stopping after one pass. A sweep updates every coordinate once; it does not guarantee that all coordinates satisfy their optimality conditions.

A common mistaken argument is: “The predictor is standardized, so its lasso coefficient is just the soft-thresholded correlation with the response.” That is correct for an orthogonal design, not generally for correlated predictors. The correction is to form the partial residual excluding that predictor, compute \(x_j^\top r_{-j}/n\), and repeat the coordinate updates until the objective and coordinatewise conditions have settled.

Key takeaway: For standardized predictors, each lasso or elastic-net update soft-thresholds the predictor's association with its current partial residual. The lasso penalty determines the threshold; the elastic-net ridge penalty increases the denominator. Correlated predictors therefore require repeated, interdependent updates.

Check Your Understanding

Try each question, then compare your work with the solutions below.

  1. For a standardized predictor, suppose the partial association is \(z_j=-1.2\), with lasso threshold \(\lambda_1=0.3\) and ridge component \(\lambda_2=0\). Compute the coordinate update.
  2. With standardized predictors, \(z_j=0.5\), \(\lambda=0.8\), and \(\alpha=0.5\), compute the elastic-net coordinate update.
  3. Why is \(x_j^\top y/n\) generally not the right quantity for updating a coefficient after other coefficients have become nonzero?
  4. State the coordinatewise condition for a coefficient that is zero at a lasso or elastic-net solution.

Solutions. (1) \(S(-1.2,0.3)=-0.9\), and the lasso denominator is 1, so \(\beta_j=-0.900\). (2) Here \(\lambda_1=0.8(0.5)=0.4\), \(\lambda_2=0.8(0.5)=0.4\), and the denominator is \(1.4\). Thus \(\beta_j=S(0.5,0.4)/1.4=0.1/1.4=0.07143\). (3) Other fitted predictors contribute to the response; their current contribution must be removed to obtain \(r_{-j}\), so the update uses \(x_j^\top r_{-j}/n\). (4) With \(r=y-X\beta\), a zero coefficient must satisfy \(|x_j^\top r/n|\leq\lambda_1\).

Clinical Biostats