As part of a statistical learning research paper I am collaborating on, I am running/fitting two hundred sixty thousand different LASSO Regressions on the same number of different randomly generated synthetic data sets and calculating some standard classification performance measurements (True Positive Rate, True Negative Rate, and False Positive Rate) so that I can use these measurements as Benchmark performance metrics to compare the performance of the novel supervised statistical learning algorithm for variable selection eating evaluated in the paper/study on the same 260K data sets with.

I am going to be using the statistical programming language are for this purpose because that is the programming language suitable for this task which I am most comfortable with by far. What would be the best function and corresponding package to use for this task?

I will accept any suggestion BESIDES the enet function from the elasticnet package because I have had issues working with this function in the past.

p.s. I understand that in order to get it to work on the 260K data sets sequentially, whatever function it turns out to be best suited, it will need to be implemented within an lapply or a parLapply function.


2 Answers 2


A common choice would be the glmnet package which has "extremely efficient procedures for fitting the entire lasso or elastic-net regularization path for linear regression."

Within the glmnet package, use the glmnet function with alpha=1.

  • $\begingroup$ thank you for the answer. I am going to level with you here though sir. I asked this question after asking several others which were never answered over the last several weeks about how to fix a certain specific issue I am having with the Variables Selected by my LASSOs fit with enet(), glmnet(), and lars(). The problem with my glmnet fit LASSOs is that each of them returns all 30 candidate factors & my problem with the others is that they do not match. Here: stackoverflow.com/questions/75277919/… $\endgroup$
    – Marlen
    Jan 31, 2023 at 17:00
  • $\begingroup$ You are correct also, but this other answer has the actual explicit code solutions which I prefer here. Hope accepting this other answer doesn't penalize yours by accident! $\endgroup$
    – Marlen
    Feb 3, 2023 at 0:27

Brian Spiering's answer was correct Marlen, however, I clicked on the link you posted in a comment below his answer and spotted the problem. You have alpha = 0 instead of alpha = 1, not sure if this was a typo or you were confused which means what, but you want it to be set equal to 1 in your glmnet function.

So, what you want is:

# fitting the n LASSO Regressions using glmnet
set.seed(11)     # to ensure replicability
system.time(LASSO.fits <- lapply(datasets, function(i) 
           glmnet(x = as.matrix(select(i, starts_with("X"))), 
                  y = i$Y, alpha = 0))) 

Hope it works for you!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.