26 High-Dimensional and Sparse Methods
26.1 Learning objectives
By the end of this chapter you should be able to:
- Distinguish the lasso, ridge, elastic net, group lasso, and adaptive lasso, and choose between them based on the scientific question and the structure of the predictors.
- Use cross-validation in
glmnetfor tuning \(\lambda\), and recognize its weaknesses for selection-stable inference. - Apply screening rules (SAFE, strong, EDPP) to scale lasso fits to \(p\) in the millions, and use
biglassofor out-of-memory designs. - Use the knockoff filter (Candès et al., 2018) to control the false-discovery rate among selected variables, and explain what guarantees it provides and when those guarantees fail.
- Reason about post-selection inference: why naive confidence intervals after lasso are wrong, and what
selectiveInference,hdi, and debiased lasso offer instead. - Recognize when sparse methods are the right tool, and when they are an overfit solution to a problem that calls for hierarchical Bayesian shrinkage or principal components.
26.2 Orientation
When the number of candidate predictors \(p\) approaches or exceeds the sample size \(n\), ordinary least squares no longer identifies a unique solution. Overfitting then becomes the dominant statistical risk. Modern high-dimensional methods address this with two ideas. The first is structural assumption: the belief that the truth is sparse (few non-zero coefficients), grouped, or low-rank. The second is regularization: a penalty that encodes that assumption into the optimization.
The lasso (Tibshirani, 1996) launched this field by combining sparsity with computational tractability. The thirty years since have produced refinements (elastic net, group lasso, adaptive lasso) and scalability advances (coordinate descent, screening rules, biglasso). They have also produced a post-selection inference apparatus (knockoffs, debiased lasso, selective inference) that gives back something resembling confidence intervals.
In this chapter we shall cover all three. We begin with the penalty zoo and tuning, work through scaling, and finish with selection inference and the knockoff filter. The framing throughout is that sparsity is an assumption, not a fact. When the assumption holds, sparse methods are highly effective. When it does not, they produce confidently wrong answers.
26.3 The statistician’s contribution
LLMs can fit a glmnet model and call cv.glmnet. They cannot decide whether the lasso assumption (that few predictors are truly associated with the outcome) is appropriate for the problem at hand. Nor can they decide whether the selected variables warrant the causal language a collaborator wants to attach to them.
(Judgment 1.) Sparsity is a modeling commitment. The lasso assumes a sparse truth, in which most coefficients are exactly zero. In some applications this is a reasonable prior, for example a genome-wide association study in which most SNPs are unrelated to the phenotype. In others it is implausible. A clinical risk model is a case in point, since many demographic and clinical factors plausibly contribute small, partially correlated effects. Forcing sparsity on a non-sparse truth produces a biased model that is over-confident about which variables matter. Ridge regression or hierarchical Bayesian shrinkage would be the better tool. The statistician decides whether sparsity matches the science.
(Judgment 2.) The selected set is not the active set. The lasso selects predictors based on their conditional contribution given the others. Highly correlated predictors therefore get arbitrarily assigned. That is, the lasso picks one and zeros the others, even when biologically the others are equally involved. The selected set is one valid sparse representation of the data, not the set of true causal contributors. Reporting the selected variables as ‘the variables associated with the outcome’ overstates the guarantee. The statistician explains what the selection does and does not show.
(Judgment 3.) Post-selection inference is required. Naive standard errors and \(p\)-values computed on the selected variables ignore the selection event and are anti-conservative. The fix (knockoffs, debiased lasso, sample splitting, or stability selection) is part of the analysis. An LLM that returns a glmnet fit and the selected variables without addressing inference has produced an exploration, not a result.
26.4 The penalty zoo
In symbols, the lasso minimizes \[ \frac{1}{2n}\|y - X\beta\|_2^2 + \lambda \|\beta\|_1 \] for tuning parameter \(\lambda \ge 0\). The \(\ell_1\) penalty shrinks coefficients toward zero and sets some exactly to zero. That is, it performs shrinkage and selection simultaneously.
Ridge uses \(\|\beta\|_2^2\) instead. It shrinks but does not select, and it is the right choice when many small contributions are expected.
Elastic net (Zou & Hastie, 2005) mixes the two: \(\alpha \|\beta\|_1 + (1-\alpha)\|\beta\|_2^2\). The combination retains the lasso’s selection while sharing information across correlated predictors. It thereby avoids both the lasso’s arbitrary single pick and ridge’s lack of selection.
Group lasso (Yuan & Lin, 2006) applies the penalty to groups of coefficients (e.g., all dummy levels of a categorical predictor), so that a group is selected or zeroed as a unit. It is the right tool whenever predictors come in natural groups, such as dummy-coded factors, splines, or gene pathways.
Adaptive lasso (Zou, 2006) applies different weights to different coefficients, with the weights derived from a preliminary estimator. Under regularity conditions it has the oracle property. That is, it consistently selects the true active set and gives asymptotically normal estimates on that set, properties the plain lasso lacks.
SCAD (Fan & Li, 2001) and MCP (Zhang, 2010) are non-convex penalties that further reduce the bias toward zero on large coefficients. They are implemented in ncvreg and are standard in genetics applications. On the minus side, they lose the convex-optimization guarantees of the lasso. On the plus side, they often perform better in practice on truly sparse problems.
A practical default is to start with elastic net. The lasso is one corner case (\(\alpha = 1\)) and ridge is the other (\(\alpha = 0\)). The elastic net interpolates between them and is robust to the mis-specification of either extreme. We use the group lasso when groups are natural, and SCAD or MCP when the bias of the lasso is the binding constraint.
26.5 Tuning \(\lambda\) via cross-validation
cv.glmnet is the standard tool. It returns two choices of \(\lambda\): lambda.min (the value minimizing mean CV error) and lambda.1se (the largest \(\lambda\) within one standard error of the minimum). The 1-SE rule produces sparser, more interpretable solutions at modest predictive cost, and it is the conventional default for selection. For prediction-oriented work, lambda.min typically wins on out-of-sample loss.
library(glmnet)
fit_cv <- cv.glmnet(
x = X, y = y,
family = "binomial", alpha = 0.5,
nfolds = 10
)
plot(fit_cv)
coef(fit_cv, s = "lambda.1se")Standardize predictors. glmnet standardizes by default. This is correct and should not be turned off. The lasso penalty is not scale-invariant, so unstandardized predictors on different scales receive different effective penalties.
The CV loss is not the inferential target. CV measures predictive accuracy. If the question is which variables matter, CV optimization is a means to an end. If the question is which variables are stable across resamples, stability selection (Meinshausen & Bühlmann, 2010) is a better tool. It refits on many subsamples and retains the variables that are selected with high probability.
Repeated CV reduces variance. Single 10-fold CV gives noisy \(\lambda\) estimates. Repeating CV with different fold assignments and averaging is standard. glmnet’s cv.glmnet does not do this directly, so we wrap it in a loop or use caret/tidymodels for repeated CV.
26.6 Scaling: screening rules and biglasso
When \(p\) is in the millions (typical for genome-wide analyses), even coordinate descent on the full design is too slow. Two ideas extend the reach of the lasso.
Screening rules identify predictors that are guaranteed or almost guaranteed to have a zero coefficient at the target \(\lambda\), and they exclude those predictors from the active-set computation.
- SAFE (El Ghaoui et al., 2012) gives a provably safe exclusion: predictors that fail the SAFE bound have zero coefficient at \(\lambda\), exactly.
- Strong rules (Tibshirani et al., 2012) are a heuristic, not a safe rule, and they can occasionally discard a predictor that is in fact active. In practice they exclude almost all truly inactive predictors. A check of the Karush-Kuhn-Tucker conditions after fitting catches any such violation, so the final solution is still exact.
- EDPP (Wang et al., 2015) (Enhanced Dual Polytope Projection) is a more aggressive safe rule that often excludes 99% or more of predictors at the first \(\lambda\).
glmnet uses strong rules internally. For very large problems where even strong rules are insufficient, biglasso (Zeng & Breheny, 2017) adds out-of-memory support via memory-mapped files, parallelism, and a more aggressive EDPP-derived screening. It achieves order-of-magnitude speedups over glmnet on \(p\) in the millions.
library(biglasso)
X.bm <- as.big.matrix(X)
fit <- biglasso(X.bm, y, family = "binomial",
ncores = 4)
plot(fit)The bigmemory design avoids loading the full matrix into R’s heap, which allows fits on designs that exceed RAM.
26.7 Selection inference: knockoffs and beyond
Once we have a selected variable set, the natural next question is ‘are these variables really associated, or is some of the selection a chance artifact?’ Naive lasso output cannot answer it.
The knockoff filter (Candès et al., 2018) constructs artificial ‘knockoff’ variables. These mimic the joint distribution of the original predictors but are conditionally independent of the outcome given the originals. We run the lasso on the augmented design (originals plus knockoffs) and compare the order of entry of originals versus knockoffs. This comparison gives a finite-sample false discovery rate (FDR) guarantee.
The code is short:
library(knockoff)
result <- knockoff.filter(
X, y, fdr = 0.10,
knockoffs = create.second_order,
statistic = stat.glmnet_coefdiff
)
result$selectedThe result is a set of variables for which the FDR (the expected proportion of false discoveries among the selected) is at most 0.10. This is a rigorous finite-sample guarantee under one assumption: the knockoff construction satisfies the exchangeability condition. In the model-X framework (Candès et al., 2018), that condition requires the joint distribution of \(X\) to be known, while the conditional distribution of \(y\) given \(X\) may be arbitrary. For a Gaussian design with known mean and covariance, create.gaussian builds exact model-X knockoffs from those supplied parameters. When the covariance is unknown, create.second_order (the knockoff.filter default) estimates it from the data, and the guarantee then holds only approximately.
The strengths and limits of the framework are as follows:
- Strength. A finite-sample FDR guarantee is rare in high-dimensional inference, and the knockoff filter is the cleanest available answer for genome-wide selection.
- Limit. Power can be modest, especially when predictors are highly correlated. The knockoffs and the originals are by construction similar, so the lasso may enter them in similar order.
- Limit. The construction depends on knowing the joint distribution of \(X\). For a designed experiment or GWAS in which \(X\) has known structure, this is acceptable. For observational data with arbitrary correlations and missing data, the assumptions become heavier.
Other approaches. Debiased lasso (Geer et al., 2014; Zhang & Zhang, 2014) removes the bias from the lasso estimate by an explicit correction. This produces asymptotically normal estimators amenable to confidence intervals. Selective inference (Lee et al., 2016; Taylor & Tibshirani, 2018) conditions on the selection event and produces \(p\)-values that are valid given that selection. Sample splitting (Meinshausen et al., 2009) uses one half of the data to select and the other half to compute classical inference on the selected set. Stability selection (Meinshausen & Bühlmann, 2010) runs many lasso fits on subsamples and retains the variables selected with high probability.
For a typical analysis our recommendation is threefold. We use knockoffs for FDR-controlled selection in high-dimensional discovery. We use sample splitting or debiased lasso when classical confidence intervals on the selected set are required. We use stability selection as a sanity check on any selected set.
26.8 Worked example: a genome-wide-style analysis
To illustrate, consider a simulated design with \(n = 1000\), \(p = 20{,}000\), and 30 truly active predictors.
library(glmnet)
library(knockoff)
set.seed(228)
n <- 1000; p <- 20000
X <- matrix(rnorm(n * p), n, p)
beta <- numeric(p)
active <- sample(p, 30)
beta[active] <- rnorm(30, 0, 1.5)
y <- X %*% beta + rnorm(n)
fit_cv <- cv.glmnet(X, y, alpha = 0.5)
selected_glmnet <- which(coef(fit_cv,
s = "lambda.1se")[-1] != 0)
length(selected_glmnet)
length(intersect(selected_glmnet, active))The elastic net at lambda.1se selects roughly 60 to 80 variables, among which about 22 of the 30 truly active are recovered. The rest are false discoveries, for a realized false-discovery rate of roughly 63 to 73%.
result <- knockoff.filter(
X, y, fdr = 0.10,
knockoffs = create.second_order,
statistic = stat.glmnet_coefdiff
)
length(result$selected)
length(intersect(result$selected, active))We note that at \(p = 20{,}000\) the second-order construction must estimate and factor a \(20{,}000 \times 20{,}000\) covariance matrix, which occupies about 3.2 GB in double precision. The call is therefore computationally heavy and memory-intensive.
The knockoff filter at FDR 0.10 selects about 18 variables, of which about 17 are truly active. The realized FDR is roughly 0.06, well within the 0.10 target. The price is reduced power. The knockoff selection misses 13 of the 30 active predictors, while the naive lasso would have caught more, but the false-discovery rate is now controlled.
For a genome-wide study in which the cost of follow-up experiments on false discoveries is high, the controlled FDR of the knockoff filter is usually the better trade.
26.9 Collaborating with an LLM on high-dimensional methods
LLMs are reliable on the syntax of glmnet, biglasso, knockoff, and ncvreg, and on explaining how the lasso, ridge, and elastic net differ. They are unreliable on the choice of method for a given scientific question and on selection inference.
Prompt 1: ‘Fit a lasso to this binary outcome and report the selected variables.’ Provide the data and the formula.
What to watch for. The LLM will return a cv.glmnet fit and a list of selected variables, often without any warning about the absence of selection inference. It will not flag that the selected variables are not the same as ‘the variables associated with the outcome’. Nor will it flag that classical intervals on those variables are invalid. It will not mention stability selection or knockoffs.
Verification. Always supplement a lasso selection with at least one of (a) stability selection, (b) knockoffs for FDR control, or (c) sample splitting for classical inference. The LLM default of ‘fit and report selected’ is only the start of an analysis.
Prompt 2: ‘Should I use lasso, ridge, or elastic net for this problem?’ Provide the scientific question, the expected sparsity, and the predictor structure.
What to watch for. The LLM will often default to the lasso on the basis of interpretability and sparsity arguments, without checking whether sparsity is a defensible assumption for the problem. It may not raise the correlated-predictor issue (the lasso picks arbitrarily among correlated predictors).
Verification. Ask explicitly: is a sparse truth plausible? Are predictors correlated? If the answer on sparsity is ‘no’ or unclear, ridge or elastic net with small \(\alpha\) is the safer default. If the answer on correlation is ‘yes,’ the sharing of correlated predictors in the elastic net is a feature.
Prompt 3: ‘Implement a knockoff filter for this design and report the selected variables at FDR 0.05.’ Provide the design and outcome.
What to watch for. The LLM will produce a working knockoff::knockoff.filter call. It will not always discuss the assumption that the joint distribution of \(X\) is appropriately captured, and it may default to create.gaussian even when the design is non-Gaussian. It will rarely run a power-loss diagnostic comparing knockoff selection to plain lasso selection.
Verification. Check that the knockoff construction is appropriate for the design (Gaussian, second-order, model-X with conditional density estimation). Then compare the size of the knockoff selection, and its overlap, with the plain lasso selection. A knockoff filter that selects far fewer variables than the lasso may be reasonable, since FDR control trades power. Alternatively, it may signal a problem with the knockoff construction.
In practice, we frame the scientific question before asking for a fit, and we never accept a selected-variable list without an inference plan attached. The LLM handles the fitting of high-dimensional methods well. The choice of method, and the selection inference the science requires, remain with the statistician.
26.10 Principle in use
Three habits define defensible high-dimensional work:
State the sparsity assumption. Before fitting a lasso, write down why you expect the truth to be sparse and what proportion of predictors you expect to be active. If the answer is ‘I have no reason to expect sparsity,’ use ridge or elastic net with small \(\alpha\) instead.
Pair selection with inference. Every selected-variable list should be reported with one of: stability selection probabilities, knockoff FDR-controlled selection, debiased lasso intervals, or sample-split classical intervals. Naked selection lists invite over-interpretation.
Stress-test correlated predictors. When variables are highly correlated, lasso selection is unstable; small changes in the data can swap which correlated variable is retained. Run the analysis on bootstrap resamples and report the proportion of resamples on which each variable is selected. Variables selected on \(<60\%\) of resamples should be reported as candidate rather than confirmed.
26.11 Exercises
Simulate a regression with \(n = 500\), \(p = 5000\), 50 truly active predictors with effects \(N(0, 1)\), and correlation \(\rho = 0.7\) within blocks of 5 predictors. Fit lasso, ridge, and elastic net at \(\alpha = 0.5\). Compare predictive MSE and the count of true positives among selected. Which method dominates?
Repeat exercise 1 but with effects \(N(0, 0.2)\) on all predictors (no truly zero coefficients). Which method dominates now? Explain why.
Apply the knockoff filter to the design from exercise 1 at FDR 0.10. Report the realized FDR and the power. Is the realized FDR within the target?
Use stability selection on the design from exercise 1. Plot the selection probability as a function of \(\lambda\) for the truly active variables and for a random sample of inactive ones.
Compare the running time of
glmnetandbiglassoon a design with \(n = 5000\), \(p = 100{,}000\). Document the speedup and identify under what conditionsbiglassobecomes worth the additional setup cost.
26.12 Further reading
- Hastie et al. (2015), Statistical Learning with Sparsity. The textbook treatment of the lasso and its extensions, by the authors of
glmnet. - Tibshirani (1996), Regression Shrinkage and Selection via the Lasso. The original paper.
- Candès et al. (2018), Panning for Gold: Model-X Knockoffs for High-Dimensional Controlled Variable Selection. The knockoff filter reference.
- Meinshausen & Bühlmann (2010), Stability Selection. The reference for resampling-based selection.
- The
glmnetvignette (https://glmnet.stanford.edu/) is exemplary; theknockoffpackage documentation (https://web.stanford.edu/group/candes/knockoffs/) is the practical entry point.