Tutorials › High-Dimensional Genomic Data Analysis › Penalized Logistic Regression With High-Dimensional Predictors

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

Penalized Logistic Regression With High-Dimensional Predictors

Learn how ridge and lasso penalties modify logistic-likelihood estimation when genomic predictors outnumber samples, and how to interpret and check the resulting fits.

Advanced 12 min read

What You'll Learn

  • Write the Bernoulli logistic model and its average negative log-likelihood.
  • Formulate l1 and l2 penalties, including the convention for the intercept.
  • Derive the logistic-loss gradient and Hessian used to understand penalized estimation.
  • Apply lasso optimality conditions to determine when a coefficient can be zero.
  • Compare ridge shrinkage with lasso sparsity and recognize common fitting problems.

Why Penalize a Logistic Model?

A genomic study may record a binary outcome, such as whether a sample belongs to one of two disease groups, alongside expression measurements for thousands of genes. When the number of predictors \(p\) is much larger than the sample size \(n\), an unpenalized logistic model can have many coefficient vectors that fit the observed outcomes extremely well. In particular, separation can drive likelihood estimates toward arbitrarily large values. Penalization adds a cost for large coefficients, making the estimation problem more controlled and changing which fit is preferred.

The key idea is to retain the binary-outcome likelihood while modifying the objective being optimized. The l1 penalty can favor exact zero coefficients; the l2 penalty continuously shrinks coefficients toward zero. Both depend on the chosen predictor scales, so genomic predictors are commonly standardized before fitting. All objectives below use the average negative log-likelihood and exclude the intercept from the penalty. The value of a penalty parameter is meaningful only with its objective convention specified.

Model and Penalized Objectives

Definition: For sample \(i=1,\ldots,n\), let \(Y_i\in\{0,1\}\) be the outcome and let \(x_i=(x_{i1},\ldots,x_{ip})^T\) be the predictor vector. The logistic model assumes that, conditional on the predictors, the outcomes are independent Bernoulli variables with \[ P(Y_i=1\mid x_i)=\pi_i,\qquad \operatorname{logit}(\pi_i)=\log\left(\frac{\pi_i}{1-\pi_i}\right)=\beta_0+x_i^T\beta, \] where \(\beta_0\) is the intercept and \(\beta=(\beta_1,\ldots,\beta_p)^T\). Equivalently, \(\pi_i=1/\{1+\exp[-(\beta_0+x_i^T\beta)]\}\).

For observed outcomes, the average negative log-likelihood, also called the logistic loss, is

$$ L(\beta_0,\beta)=\frac{1}{n}\sum_{i=1}^n \left[\log\{1+\exp(\eta_i)\}-y_i\eta_i\right], \qquad \eta_i=\beta_0+x_i^T\beta. $$

The lasso-logistic estimate minimizes \(L(\beta_0,\beta)+\lambda_1\|\beta\|_1\), where \(\|\beta\|_1=\sum_{j=1}^p|\beta_j|\). The ridge-logistic estimate minimizes \(L(\beta_0,\beta)+(\lambda_2/2)\|\beta\|_2^2\), where \(\|\beta\|_2^2=\sum_{j=1}^p\beta_j^2\). Here \(\lambda_1\geq 0\) and \(\lambda_2\geq 0\); the factor \(1/2\) in the ridge penalty is a convention that simplifies derivatives. The intercept is not penalized, so the model can set its baseline outcome probability without paying a penalty.

These are convex optimization problems: logistic loss is convex, and each penalty is convex. Convexity means a solution satisfying the appropriate optimality conditions is a global minimum. It does not, by itself, guarantee a unique coefficient vector. For example, highly correlated or redundant predictors can allow multiple lasso solutions. With \(\lambda_2>0\), the penalized curvature in the slope coordinates is positive, though an intercept still requires outcome information to be estimable.

How the Penalty Changes Likelihood Estimation

Write \(\pi_i=1/\{1+\exp(-\eta_i)\}\). Differentiating the logistic loss gives the slope gradient \(n^{-1}X^T(\pi-y)\), where \(X\) is the matrix of predictors and \(\pi,y\) are the vectors of fitted probabilities and outcomes. The intercept derivative is \(n^{-1}\sum_i(\pi_i-y_i)\). Thus, without a penalty, estimation balances observed outcomes against fitted probabilities through score equations.

$$ \nabla_{\beta}L=\frac{1}{n}X^T(\pi-y), \qquad \nabla^2_{\beta}L=\frac{1}{n}X^TWX, \qquad W=\operatorname{diag}\{\pi_i(1-\pi_i)\}. $$

Each diagonal weight is nonnegative, so for any vector \(v\), \(v^T X^TWXv=\sum_i\pi_i(1-\pi_i)(x_i^Tv)^2\geq 0\). This verifies that the loss curvature is positive semidefinite. Ridge adds \(\lambda_2 I\) to the slope Hessian and \(\lambda_2\beta\) to the slope gradient. Lasso has no ordinary derivative at a zero coefficient; its optimality conditions use a subgradient instead.

Theorem: A lasso-logistic solution satisfies, for each slope \(j\), \[ \begin{cases} \frac{1}{n}x_j^T(\pi-y)+\lambda_1\operatorname{sign}(\beta_j)=0,&\beta_j\ne 0,\\ \left|\frac{1}{n}x_j^T(\pi-y)\right|\leq\lambda_1,&\beta_j=0. \end{cases} \] The intercept satisfies \(\sum_i(\pi_i-y_i)=0\). For ridge, the slope equations are \(\frac{1}{n}X^T(\pi-y)+\lambda_2\beta=0\).

For lasso, the zero-coefficient condition follows because the subgradients of \(|\beta_j|\) at zero fill the interval \([-1,1]\). A zero coefficient can minimize the objective exactly when the corresponding loss-gradient magnitude is no greater than \(\lambda_1\). For ridge, the penalty gradient is proportional to the coefficient itself: it reduces nonzero estimates but generally does not set them exactly to zero.

Worked Example: Comparing Penalty Costs at a Candidate Fit

Consider a hypothetical binary dataset with four samples and six gene predictors, so \(p=6>n=4\). The first gene has values \((-1,1,-1,1)\), and outcomes are \((0,1,0,1)\). Evaluate a candidate with intercept zero, first-gene coefficient \(\beta_1=0.8\), and all other coefficients zero. Use \(\lambda_1=\lambda_2=0.2\).

For the first and third samples, \(\eta_i=-0.8\) and \(y_i=0\), so the loss contribution is \(\log(1+\exp(-0.8))\). For the second and fourth, \(\eta_i=0.8\) and \(y_i=1\), giving that same contribution. The average loss is therefore \[ L=\log(1+\exp(-0.8))\approx 0.3711. \]

The lasso objective at this candidate is \(0.3711+0.2|0.8|=0.5311\). The ridge objective is \(0.3711+(0.2/2)(0.8^2)=0.4351\). At the all-zero slope vector and zero intercept, the average loss is \(\log(2)\approx0.6931\), with no penalty cost. The nonzero candidate improves the likelihood enough to lower either objective relative to that baseline. These calculations compare objective values at candidates; they do not establish that this candidate minimizes either objective.

Worked Example: A Ridge-Penalized Slope Estimate

A simple hypothetical dataset has two observations, with a single predictor \(x=(0,1)\), outcomes \(y=(0,1)\), and a fixed intercept of zero. This constrained example isolates the slope calculation; it is not a general instruction to fix the intercept in a fitted genomic model. Use the summed negative log-likelihood and ridge penalty \((\lambda_2/2)\beta_1^2\), with \(\lambda_2=0.25\).

The first observation contributes \(\log(2)\), and the second contributes \(\log(1+\exp(-\beta_1))\). The objective and its derivative are \[ Q(\beta_1)=\log(2)+\log(1+\exp(-\beta_1))+0.125\beta_1^2, \qquad Q'(\beta_1)=-\frac{1}{1+\exp(\beta_1)}+0.25\beta_1. \] At \(\beta_1=1\), \(Q'=-1/(1+\exp(1))+0.25\approx-0.01894\). At \(\beta_1=1.1\), \(Q'=-1/(1+\exp(1.1))+0.275\approx0.02526\). The derivative changes sign between these values. Since \[ Q''(\beta_1)=\frac{\exp(\beta_1)}{\{1+\exp(\beta_1)\}^2}+0.25>0, \] the objective is strictly convex, and this root is its unique minimum. Solving \(Q'(\beta_1)=0\) gives \(\hat\beta_1\approx1.04260\), or \(1.043\) to three decimal places. For comparison, without the ridge penalty the slope would diverge toward positive infinity: the observation with \(x=0\) contributes a constant, while the correctly classified observation with \(x=1\) has loss approaching zero as the slope grows.

Worked Example: Checking Whether Lasso Can Set All Slopes to Zero

Suppose a hypothetical dataset has \(n=4\), \(p=6\), outcomes \(y=(0,1,0,1)\), and all predictor entries lie between \(-1\) and \(1\). At intercept zero and zero slopes, every fitted probability is \(0.5\). Check whether the all-zero slope vector satisfies the lasso conditions when \(\lambda_1=0.5\).

The intercept score is \(\sum_i(0.5-y_i)=0\), so the intercept condition holds. For any gene \(j\), its loss-gradient magnitude at this fit is \[ \left|\frac{1}{4}\sum_{i=1}^4 x_{ij}(0.5-y_i)\right| \leq \frac{1}{4}\sum_{i=1}^4|x_{ij}|\,|0.5-y_i| \leq \frac{1}{4}(4)(0.5)=0.5. \] Thus every zero coefficient satisfies the lasso condition for \(\lambda_1=0.5\); by convexity, this intercept and zero slope vector are a global minimum. For gene 1 with values \((-1,1,-1,1)\), the gradient is \(-0.5\), exactly at the allowed boundary. If \(\lambda_1\) were \(0.4\), this gene's zero-coefficient condition would fail, so the all-zero slope vector could not be a minimum.

Assumptions, Diagnostics, and Comparisons

The likelihood formulation assumes a correctly coded binary outcome and independent observations conditional on their predictors. The logistic mean structure specifies how the conditional probability relates to the predictors; it does not require the predictors themselves to be independent. The penalty changes the estimation target but does not repair a dependence structure that was ignored, an outcome that was miscoded, or an inappropriate functional form.

Before interpreting a fit, check that both outcome classes are represented, that predictors have sensible scales, and that the computation has converged. Very large fitted linear predictors can indicate near-separation or numerical overflow; probabilities extremely close to zero or one can also make likelihood curvature small. For lasso, inspect whether the zero and nonzero coefficients satisfy the subgradient conditions to numerical tolerance. For ridge, inspect the penalized gradient. Persistent large gradients, unstable objective values, or sensitivity to scaling signal that the numerical solution or model setup needs attention.

FeatureLasso-logisticRidge-logistic
Penalty\(\lambda_1\sum_j|\beta_j|\)\((\lambda_2/2)\sum_j\beta_j^2\)
Effect on slopesCan set coefficients exactly to zeroShrinks coefficients continuously
Typical geometryMay produce sparse fits; correlated predictors can have nonunique allocationsUsually retains many small coefficients; positive penalty regularizes slope curvature
Common concernSelected genes can change with small data or tuning changesIndividual gene effects may be hard to distinguish when predictors are highly correlated

Both methods trade an unpenalized likelihood fit for a penalized one, and neither makes a coefficient a causal effect. A ridge coefficient describes the fitted change in log odds per one-unit increase in that predictor, holding the other modeled predictors fixed; a lasso zero means that coefficient is zero in this penalized fit, not that the gene has no biological role. In genomic work, a one-unit change depends on the measurement scale, which is why scale choices should be explicit.

Common Mistakes and Limitations

  • Penalizing the intercept by default. The objectives here penalize slopes only. Penalizing the intercept changes how the baseline probability is estimated and is a different specification.
  • Assuming ridge produces sparse coefficients. Its smooth quadratic penalty shrinks slopes, but typically leaves them nonzero. Exact zeros are a defining possibility of the l1 penalty.
  • Reading a lasso zero as proof of no association. A zero is an outcome of this penalized fit and its penalty strength, not a test result or a biological conclusion.
  • Comparing penalty values without their objective convention. An average loss and a summed loss have different numerical scales. State the objective before interpreting \(\lambda\).

Penalization does not eliminate uncertainty from small samples, dependence among genes, or model misspecification. Nor does a stable numerical solution by itself show that a penalty choice is appropriate. These objectives describe how estimates are obtained; assessing predictive performance or choosing a penalty requires additional procedures.

Key takeaway: Logistic lasso and ridge retain the Bernoulli likelihood but add different costs to the slope coefficients. Ridge adds a smooth linear term to the score equations; lasso imposes a subgradient threshold that can keep a coefficient exactly at zero.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. For ridge-logistic regression, what term is added to the slope gradient?
  2. Why can a lasso coefficient be exactly zero while a ridge coefficient is usually not?
  3. In the all-zero example, what happens to the lasso zero-coefficient condition for gene 1 if \(\lambda_1=0.4\)?
  4. What is the probability interpretation of the linear predictor \(\eta_i\) in logistic regression?
  5. Name one assumption or diagnostic that should be checked before interpreting a penalized logistic fit.

Solutions. (1) Ridge adds \(\lambda_2\beta\) to the slope gradient. (2) The l1 subgradient at zero includes every value between \(-\lambda_1\) and \(\lambda_1\), allowing the optimum to remain at zero; the l2 derivative is zero only when its coefficient is zero and otherwise continuously shrinks it. (3) The gene's gradient magnitude is \(0.5>0.4\), so its zero-coefficient condition fails and the all-zero slope vector cannot be optimal. (4) \(\eta_i\) is the log odds of \(Y_i=1\) conditional on its predictors. (5) Examples include checking independent observations, confirming both outcome classes are present, standardizing predictors appropriately, or checking penalized-gradient and subgradient residuals for convergence.

Clinical Biostats