Tutorials › Exam PA - Predictive Analytics › Sparse and Dense Signal Patterns

Exam PA · Lasso Selection and Elastic Net · Tutorial 449 of 966

Sparse and Dense Signal Patterns

See how lasso and elastic net can represent sparse and distributed signals differently, and work through the calculations that explain those differences.

Advanced 11 min read

What You'll Learn

  • Describe how a sparse signal differs from a signal distributed across many predictors.
  • Use the coordinate solution for elastic net with orthogonal standardized predictors.
  • Compare lasso and elastic net coefficient patterns at specified penalty settings.
  • Explain why the elastic net quadratic penalty can spread coefficients across duplicate features.
  • Identify when a coefficient pattern reflects the feature representation rather than a uniquely determined signal.

Signal Pattern and Penalty Choice

A predictive signal may be sparse: a small number of features carry most of the useful information, while many others contribute little. Or it may be distributed: predictive information is spread across a larger set of features, perhaps because several related variables each contain part of the signal. These descriptions concern how the signal is represented by the available predictors; they do not establish which variables cause an outcome.

Lasso and elastic net can produce different coefficient patterns even when applied to the same data. Lasso uses an absolute-value penalty that can set coefficients exactly to zero. Elastic net combines that penalty with a squared-coefficient penalty. The absolute-value component still permits zero coefficients, while the squared component can make sharing signal across related features less costly than selecting just one. Neither method guarantees recovery of the underlying pattern. The result also depends on the features, their scaling, and the penalty settings.

Definition: A sparse signal pattern is one in which a relatively small subset of predictors carries most of the predictive contribution. A distributed signal pattern is one in which predictive contribution is spread across several or many predictors. These are descriptions of a modeling pattern, not claims about causation or a guarantee about which variables should be selected.

Objective and Orthogonal-Predictor Formula

Assume the response and predictors have been centered, the intercept is handled separately and is not penalized, and the columns of the design matrix \(X\) are standardized. For a squared-error model, write the elastic net objective as

$$ \frac{1}{2n}\|y-X\beta\|_2^2+ \lambda\left\{\alpha\|\beta\|_1+ \frac{1-\alpha}{2}\|\beta\|_2^2\right\}, \qquad 0\leq\alpha\leq1,\quad \lambda\geq0. $$

Here \(\beta\) is the vector of coefficients, \(n\) is the number of observations, and \(\|\beta\|_1=\sum_j|\beta_j|\), while \(\|\beta\|_2^2=\sum_j\beta_j^2\). At \(\alpha=1\), the objective is lasso; at \(\alpha=0\), it is ridge; intermediate values combine both penalties. This tutorial uses the stated objective and scaling throughout. Changing the loss normalization or penalty convention changes the numerical interpretation of \(\lambda\).

A useful exact comparison is available when predictors are orthogonal under this scaling, so that \(X^\mathsf{T}X/n=I\). Define \(z_j=x_j^\mathsf{T}y/n\), where \(x_j\) is column \(j\) of \(X\). With orthogonal predictors, each coefficient can be minimized separately:

$$ \hat\beta_j= \frac{\operatorname{sign}(z_j)(|z_j|-\lambda\alpha)_+} {1+\lambda(1-\alpha)}, \qquad (a)_+=\max(a,0). $$

For lasso, \(\alpha=1\), so the threshold is \(\lambda\) and the denominator is 1. For elastic net, the threshold is \(\lambda\alpha\); when \(\alpha<1\), the denominator exceeds 1 if \(\lambda>0\), adding shrinkage to coefficients that survive the threshold. This formula relies on the orthogonality and standardization assumptions above. With correlated predictors, the coordinates do not minimize independently, so this coordinate formula cannot be applied as if the predictors were orthogonal.

Why the Coordinate Formula Holds

When \(X^\mathsf{T}X/n=I\), the squared-error part of the objective, up to a term that does not depend on \(\beta\), is \(\frac12\sum_j(\beta_j-z_j)^2\). Thus the part involving one coefficient is

$$ g_j(\beta_j)= \frac12(\beta_j-z_j)^2+ \lambda\alpha|\beta_j|+ \frac{\lambda(1-\alpha)}{2}\beta_j^2. $$

If \(z_j>0\) and a minimizing coefficient is positive, differentiating on the positive side gives

$$ g'_j(\beta_j) =(\beta_j-z_j)+\lambda\alpha+\lambda(1-\alpha)\beta_j=0, $$ $$ \beta_j=\frac{z_j-\lambda\alpha}{1+\lambda(1-\alpha)}. $$

This positive solution is valid only when \(z_j>\lambda\alpha\). If \(z_j\leq\lambda\alpha\), the minimum is at zero: the slope from the right at zero is \(-z_j+\lambda\alpha\), which is nonnegative, so moving to a positive coefficient cannot reduce the objective. Applying the same argument to a negative coefficient gives the corresponding result for \(z_j<0\), yielding the signed threshold formula. The denominator follows from the derivative of the quadratic penalty; it is not part of the threshold.

Worked Example: A Concentrated Signal in Orthogonal Features

Suppose three centered, standardized, orthogonal predictors have \(z=(2.4,0.7,0.3)\). Compare lasso with \(\lambda=0.8\) and elastic net with \(\lambda=0.8\), \(\alpha=0.5\). Use the coordinate formula and report coefficients to four decimal places.

Method. Apply the threshold and denominator separately for each method. The orthogonality assumption is what makes these coordinate calculations valid.

For lasso, \(\alpha=1\). Its threshold is \(\lambda\alpha=0.8(1)=0.8\), and its denominator is \(1+\lambda(1-\alpha)=1\). The three positive \(z_j\) values give

$$ \hat\beta_{\text{lasso}} =((2.4-0.8)_+,\ (0.7-0.8)_+,\ (0.3-0.8)_+) =(1.6,\ 0,\ 0). $$

For elastic net, the threshold is \(0.8(0.5)=0.4\), and the denominator is \(1+0.8(1-0.5)=1.4\). Therefore

$$ \hat\beta_{\text{EN}}= \left(\frac{2.4-0.4}{1.4}, \frac{0.7-0.4}{1.4}, 0\right) =(1.4286,\ 0.2143,\ 0). $$

The elastic net retains a second feature that lasso removes, but it still sets the third coefficient to zero. The result illustrates a possible difference in representation; it does not show that the second predictor is necessarily important in another sample or design. The common mistake is to use the lasso threshold \(0.8\) for elastic net. Its threshold here is \(0.4\), and its denominator is \(1.4\); both parts of the formula matter.

More Distributed Patterns Under Orthogonality

If several orthogonal predictors have moderate associations with the response, lasso may keep only the ones whose \(|z_j|\) exceed \(\lambda\). Elastic net at the same \(\lambda\) and an intermediate \(\alpha\) has a lower threshold, \(\lambda\alpha\), but also shrinks the retained coefficients through its denominator. The number of nonzero coefficients can therefore differ, while the sizes of retained coefficients differ as well. A lower threshold does not mean that every elastic net coefficient must be larger: its extra quadratic shrinkage acts in the opposite direction.

Worked Example: A More Distributed Orthogonal Signal

Four centered, standardized, orthogonal predictors have \(z=(1.4,1.2,0.8,0.6)\). Compare lasso with \(\lambda=0.8\) to elastic net with \(\lambda=0.8\), \(\alpha=0.5\). Give the coefficient vectors to four decimal places and count the nonzero coefficients.

For lasso, the threshold is \(0.8\) and the denominator is 1. Thus

$$ \hat\beta_{\text{lasso}}= (1.4-0.8,\ 1.2-0.8,\ (0.8-0.8)_+,\ (0.6-0.8)_+) =(0.6,\ 0.4,\ 0,\ 0). $$

The equality \(z_3=0.8\) gives a zero coefficient because the positive-part expression is zero at the threshold. Lasso retains two coefficients.

For elastic net, the threshold is \(0.8(0.5)=0.4\) and the denominator is \(1+0.8(0.5)=1.4\). The coefficients are

$$ \hat\beta_{\text{EN}}= \left(\frac{1.0}{1.4},\frac{0.8}{1.4}, \frac{0.4}{1.4},\frac{0.2}{1.4}\right) =(0.7143,\ 0.5714,\ 0.2857,\ 0.1429). $$

Elastic net retains all four coefficients, whereas lasso retains two. In particular, the third and fourth \(z_j\) values exceed the elastic net threshold \(0.4\), so both are nonzero. The common mistake is to count only three elastic net coefficients or to treat the threshold as \(0.8\). Checking each value against \(0.4\) gives four nonzero coefficients.

Correlated Features and Representation

The orthogonal examples clarify thresholding, but related features are often correlated. When two or more features carry similar information, lasso can favor a representation that uses just one of them. Which feature is selected can depend on the data and the details of the design. Elastic net's squared-coefficient penalty can make a shared representation more attractive, particularly when predictors are very similar. This is a tendency, not a rule that guarantees equal coefficients or selection of every related feature.

The effect can be seen exactly for duplicate predictors. Suppose \(p\) standardized columns are identical, their common fitted contribution is determined by the coefficient sum \(s=\sum_{j=1}^p\beta_j\), and the response is aligned so that the squared-error term, up to a constant, is \(\frac12(c-s)^2\), with \(c>0\). Consider nonnegative coefficients. For a fixed sum \(s\), the lasso penalty depends only on \(s\), while the elastic net quadratic penalty depends on how that sum is allocated.

Justification: For nonnegative coefficients with fixed sum \(s\), \(\sum_j|\beta_j|=s\). Also, \(\sum_j\beta_j^2\geq s^2/p\), because \((\sum_j\beta_j)^2\leq p\sum_j\beta_j^2\). Equality in this inequality holds when every coefficient equals \(s/p\). Thus the elastic net quadratic penalty is minimized by equal allocation among identical predictors, once the optimal sum \(s\) is fixed.

Worked Example: Sharing Signal Across Four Duplicate Features

Suppose four identical standardized predictors have a common response alignment \(c=1.8\). Their coefficients are constrained to be nonnegative, and the objective, up to a constant, is \(\frac12(1.8-s)^2+0.3s+0.15\sum_{j=1}^4\beta_j^2\), where \(s=\sum_{j=1}^4\beta_j\). This is elastic net with \(\lambda=0.6\), \(\alpha=0.5\). Find the minimizing total and equal coefficient allocation.

Method. For a fixed sum \(s\), the quadratic penalty is minimized by equal coefficients. In that allocation, each coefficient is \(s/4\), so \(\sum_j\beta_j^2=4(s/4)^2=s^2/4\). Substitute into the objective:

$$ Q(s)=\frac12(1.8-s)^2+0.3s+0.15\frac{s^2}{4}. $$

Differentiate and set the derivative to zero:

$$ Q'(s)=s-1.8+0.3+0.075s=1.075s-1.5, \qquad 1.075s-1.5=0, $$ $$ s=\frac{1.5}{1.075}=\frac{60}{43}\approx1.3953. $$

The equal allocation is therefore

$$ \beta_j=\frac{s}{4}=\frac{15}{43}\approx0.3488, \qquad j=1,2,3,4. $$

The derivative is zero at this sum, and the second derivative is \(Q''(s)=1.075>0\), confirming a minimum. Substitution into the derivative gives \(1.075(60/43)-1.5=0\), a direct check. The common mistake is to choose a sum without differentiating the objective after substituting the equal allocation; equal sharing for a fixed sum does not itself determine the optimal sum.

Interpreting the Trade-Off

The examples show why there is no universal rule that one method is better for “sparse” or “dense” data. When a few features carry most of the signal and a compact representation is desirable, lasso's exact zeros can be useful. When many features contribute or related predictors offer overlapping information, elastic net may represent the signal across more coefficients. But a denser fitted coefficient vector is not proof that the underlying signal is truly distributed, and a sparse vector is not proof that only those selected features matter.

Coefficient patterns also depend on how predictors are represented. Scaling affects the penalty applied to a coefficient, which is why comparisons require an appropriate common scaling, as in the examples. Categorical encodings, interactions, and groups of related variables can change what “one feature” means. A penalty acts on the supplied columns; it does not automatically recognize a real-world construct as a single indivisible variable.

At fixed \(\lambda\), \(\alpha\), and design, the two methods need not have the same number of nonzero coefficients or the same total fitted contribution. Nor should a comparison be reduced to counting selected predictors: the coefficient magnitudes and the way correlated features share a representation matter. The useful practice is to state the assumed signal pattern, inspect the feature structure, and explain the representation each penalty produces without interpreting selection as causation.

Key takeaway: Lasso's absolute-value penalty creates a threshold for zero coefficients. Elastic net uses the threshold \(\lambda\alpha\) and adds quadratic shrinkage; with correlated or duplicate features, that quadratic term can favor sharing the coefficient sum. These mechanisms can produce different representations of sparse and distributed signals, but neither guarantees the true pattern.

Check Your Understanding

For the numerical questions, assume centered, standardized, orthogonal predictors unless the question states that features are duplicates. Give coefficients to four decimal places where needed.

  1. Three orthogonal predictors have \(z=(1.9,1.1,0.5)\). For elastic net with \(\lambda=0.6\) and \(\alpha=0.5\), find the threshold, denominator, and coefficient vector. (Answer: threshold \(0.3\), denominator \(1.3\), coefficients \((1.2308,0.6154,0.1538)\).)
  2. Four orthogonal predictors have \(z=(1.6,1.0,0.7,0.2)\). Under lasso with \(\lambda=0.75\), give the coefficient vector and number of nonzero coefficients. (Answer: \((0.85,0.25,0,0)\); 2 nonzero coefficients.)
  3. Three orthogonal predictors have \(z=(2.2,1.4,0.9)\). For elastic net with \(\lambda=1\) and \(\alpha=0.4\), calculate the threshold, denominator, and coefficient vector. (Answer: threshold \(0.4\), denominator \(1.6\), coefficients \((1.1250,0.6250,0.3125)\).)
  4. Three identical standardized predictors have a nonnegative coefficient sum \(s\), and their objective is \(\frac12(2.4-s)^2+0.2s+0.15\sum_{j=1}^3\beta_j^2\). Find the minimizing total and the equal allocation. (Answer: total \(s=2\); each coefficient is \(2/3\approx0.6667\).)
  5. For the four-predictor orthogonal example with \(z=(1.4,1.2,0.8,0.6)\), explain why the elastic net coefficients are all nonzero at \(\lambda=0.8,\alpha=0.5\), although the lasso coefficients for \(\lambda=0.8\) are not. (Answer: elastic net's threshold is \(0.4\), below all four \(z_j\) values, so it retains four coefficients; lasso's threshold is \(0.8\), so it retains only the first two.)
Clinical Biostats