I'm pleased to announce that the glmnetUtils package is now available on CRAN. I wrote this after using the popular glmnet package to fit elastic net models for a few customer projects, and rewriting the same boilerplate code each time.
glmnetUtils provides some quality-of-life improvements for glmnet, specifically:
- a formula/data frame interface to glmnet and cv.glmnet. No more manual fiddling around with model.matrix/as.matrix/data.matrix, worrying about NA values, etc.
- a cva.glmnet function to choose both the alpha and lambda parameters via cross-validation, following the approach described in the help page for cv.glmnet. Optionally does the cross-validation in parallel.
- Methods for predict and coef for the above.
In addition, to facilitate analysis of very wide datasets, glmnetUtils by default takes a slightly different approach to generating model matrices. Rather than calling model.frame() and model.matrix() on the full dataset, it builds up the model.matrix term by term. This is because model.frame() creates a terms object, which can be excessively large for wide data. Building up the model matrix one term at a time avoids this problem.