Solved – LASSO in R for variable selection: how to choose the tuning parameter

lassopredictive-modelsrregression

I apologize in advance if this question is basic.

I am trying to use LASSO for variable selection, with an implementation in R. I currently have 15 predictors, and looking to reduce the variable space and select the best predictors only, to be included in my final factor model.

Some have advised me to use LASSO for this purpose. However, after reading some documentation about the subject, I am still unsure of how to choose the tuning parameter $\lambda$. As for the implementation in R, I attempted to use the glmnet package:

Get value of tuning parameter $\lambda$

library(glmnet)
ans <- cv.glmnet(data, return[,1], standardize = TRUE)
par(mfrow=c(1, 2))
plot(ans$glmnet.fit, "norm", label=TRUE)
plot(ans$glmnet.fit, "lambda", label=TRUE)
dev.new()
plot(ans)

However, I am not sure how to interpret the results. I then run the following:

model <- cv.glmnet(data, return[,1], standardize = TRUE)
coef(model)

Could anyone please clarify the results of LASSO in R?

Thanks,

Best Answer

By calling cv.glmnet with default arguments you're k-fold cross-validating on lambda with k = 10. The fitted model will use the 1-standard-error-from-min value of lambda by default, and you can get the value by calling cv.glmnet.object$lambda.1se. See page 5 of the vignette: http://cran.r-project.org/web/packages/glmnet/glmnet.pdf.

Related Question