I have been following a tutorial of LASSO regression with R commands (here), but I am confused at some point which I think is more conceptual.
I expected to get an estimate of the regression parameters, as well as a subset of the parameters that are meaningful to explain the response (sort of what would be obtained by using a backward stepwise regression). Instead, it seems that the output from this are the estimates of these coefficients at different values of a penalizing factor (λ).
So I am just guessing here but, is it possible to take the best value of λ (e.g. that with minimum AIC) to cut off the model on that value and get the corresponding estimates of these parameters? If so, how to do it?
In the following reproducible example... would the output mean that no factor is meaningful to predict mpg in the dataset of mtcars??
library("dplyr") library("glmnet") set.seed(123) y <- mtcars %>% select(mpg) %>% scale(center = TRUE, scale = FALSE) %>% as.matrix() X <- mtcars %>% select(-mpg) %>% as.matrix() lambdas_to_try <- 10^seq(-3, 5, length.out = 100) lasso_cv <- cv.glmnet(X, y, alpha = 1, lambda = lambdas_to_try, standardize = TRUE, nfolds = 10) plot(lasso_cv) lambda_cv <- lasso_cv$lambda.min model_cv <- glmnet(X, y, alpha = 1, lambda = lambda_cv, standardize = TRUE) res <- glmnet(X, y, alpha = 1, lambda = lambdas_to_try, standardize = FALSE) plot(res, xvar = "lambda") legend("bottomright", lwd = 1, col = 1:6, legend = colnames(X), cex = .7) abline(v = log(lambda_cv))