Consider a regression problem with observations and covariates. Create one simulated dataset as follows. Generate the first covariate as independent standard normal draws. Then form the second covariate as
where is another vector of independent standard normal draws, so that and have population correlation . Generate the remaining covariates as independent standard normal vectors of length .
Thus and are extremely highly correlated, while and are independent of one another and of the remaining covariates. Finally, generate the response as
where is a vector of independent standard normal errors, independent of the covariates. Both members of the correlated pair appear in the generating equation with the same coefficient, even though each one carries almost the same observed information as the other. The two independent signals and have coefficients that differ by a factor of two, and have zero coefficients.
Use seed 43246 and independently repeat the complete data generation and fitting procedure 200 times. Within each repetition, center and standardize the covariates using divisor and center the response. Fit the lasso model with the glmnet package in R or sklearn.linear_model.Lasso in Python, without scaling the variables inside the fitting function, at
Make sure you understand which argument specifies the scaling option in a lasso fit and how to give a specific penalty value; the default settings of the fitting function do not produce the fits required here.
Fit all four penalties to the same generated dataset before beginning the next repetition. Leave the intercept unpenalized and convert the fitted slopes back to the original covariate scale. Store the slopes in one array whose dimensions correspond to the 200 repetitions, 10 covariates, and four penalties. Treat a slope as nonzero when its absolute value exceeds . Use a tight convergence tolerance as well as a sufficiently large iteration limit, because the nearly identical covariates make coefficient allocation sensitive to numerical accuracy. In R, use control = list(thresh = 1e-18, maxit = 1000000); in Python, use tol=1e-10, max_iter=100000. Verify that all 800 fits converge. R and Python use different random-number generators, so their exact numerical results need not agree.
For every covariate and penalty, report the selection frequency and the mean absolute fitted slope, where the mean includes fitted zeros. Draw one figure for each summary. Explain how increasing the penalty changes the fitted magnitudes and selection frequencies.
For the pair , report the frequency of four mutually exclusive outcomes at each penalty: only the first covariate is selected, only the second is selected, both are selected, and neither is selected. Compare the two marginal selection frequencies and explain why they are similar. Describe how the four outcomes shift as the penalty increases, and explain why lasso can produce a sparse fitted rule that omits one member of the pair even though both members appear in the generating equation.
Compare the selection frequencies of and with the average selection frequency among . Explain how signal magnitude and the penalty account for the pattern. Use the correlated pair to explain why a fitted zero does not establish that the corresponding population coefficient is zero, and why a nonzero fitted coefficient does not establish that the variable is uniquely important.