Package: glmnet 5.0

glmnet: Lasso and Elastic-Net Regularized Generalized Linear Models

Extremely efficient procedures for fitting the entire lasso or elastic-net regularization path for linear regression, logistic and multinomial regression models, Poisson regression, Cox model, multiple-response Gaussian, and the grouped multinomial regression; see <doi:10.18637/jss.v033.i01> and <doi:10.18637/jss.v039.i05>. There are two new and important additions. The family argument can be a GLM family object, which opens the door to any programmed family (<doi:10.18637/jss.v106.i01>). This comes with a modest computational cost, so when the built-in families suffice, they should be used instead. The other novelty is the relax option, which refits each of the active sets in the path unpenalized. The algorithm uses cyclical coordinate descent in a path-wise fashion, as described in the papers cited.

Authors:Jerome Friedman [aut], Trevor Hastie [aut, cre], Rob Tibshirani [aut], Balasubramanian Narasimhan [aut], Kenneth Tay [aut], Noah Simon [aut], Junyang Qian [ctb], James Yang [aut], Jonathan Taylor [aut]

glmnet_5.0.tar.gz
glmnet_5.0.zip(r-4.7)glmnet_5.0.zip(r-4.6)glmnet_5.0.zip(r-4.5)
glmnet_5.0.tgz(r-4.6-x86_64)glmnet_5.0.tgz(r-4.6-arm64)glmnet_5.0.tgz(r-4.5-x86_64)glmnet_5.0.tgz(r-4.5-arm64)
glmnet_5.0.tar.gz(r-4.7-arm64)glmnet_5.0.tar.gz(r-4.7-x86_64)glmnet_5.0.tar.gz(r-4.6-arm64)glmnet_5.0.tar.gz(r-4.6-x86_64)
glmnet_5.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
glmnet/json (API)

# Install 'glmnet' in R:
install.packages('glmnet', repos = c('https://trevorhastie.r-universe.dev', 'https://cloud.r-project.org'))
Uses libs:
  • c++– GNU Standard C++ Library v3
Datasets:

On CRAN:

Conda:

This package does not link to any Github/Gitlab/R-forge repository. No issue tracker or development information is available.

cpp

15.95 score 95 stars 880 packages 36k scripts 167k downloads 1.6k mentions 24 exports 9 dependencies

Last updated from:51f61a9819. Checks:11 WARNING, 2 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64WARNING213
linux-devel-x86_64WARNING214
source / vignettesOK295
linux-release-arm64WARNING213
linux-release-x86_64WARNING234
macos-release-arm64WARNING148
macos-release-x86_64WARNING306
macos-oldrel-arm64WARNING147
macos-oldrel-x86_64WARNING433
windows-develWARNING227
windows-releaseWARNING195
windows-oldrelWARNING200
wasm-releaseOK166

Exports:assess.glmnetbigGlmbuildPredmatCindexcoef.glmnetcoef.relaxedconfusion.glmnetcoxgradcoxnet.deviancecv.glmnetglmnetglmnet.controlglmnet.measuresmakeXna_sparse_fixna.replacepredict.glmnetpredict.relaxedprepareXprint.cv.glmnetrelax.glmnetrmultroc.glmnetstratifySurv

Dependencies:codetoolsforeachiteratorslatticeMatrixRcppRcppEigenshapesurvival

A History of glmnet
1. Introduction | 2. Origins: coordinate descent and the first release (2008--2010) | 3. Filling out the matrix (2010--2018) | 4. Usability matures: v3.0 (2019) | 5. GLM extension: v4.0 (2020) | 6. Cox catches up: v4.1 (2021) | 7. Fortran → C++ port (2021--2022) | 8. Applications feeding back into the package | 9. Streamlined Cox and v5.0 (2026) | 10. Looking forward | 11. Contributors and acknowledgements | References

Last update: 2026-05-04
Started: 2026-05-04

Some notes on the score and Hessian of weighted Cox's proportional hazards with ties
Abstract | The easy case: no ties | Right censored | Start / stop | Difference of cumsums | Second derivative | Probabilistic interpretation | Ties and zero weights | First derivative | A lemma or two | Derivatives revisited | Full Hessian | Non-diagonal term | Diagonal term | Appendix: Proofs of Lemmas | Proof of Lemma 1 (Forward cumsum representation) | Proof of Lemma 2 (Adjoint cumsum representation)

Last update: 2026-05-04
Started: 2026-05-04

Regularized Cox Regression
Introduction | Basic usage for right-censored data | Cross-validation | Handling of ties | Cox models for start-stop data | Stratified Cox models | Plotting survival curves | References

Last update: 2026-05-04
Started: 2019-11-09

An Introduction to glmnet
Introduction | Installation | Quick Start | Linear Regression: family = "gaussian" (default) | Commonly used function arguments | Predicting and plotting with glmnet objects | Cross-validation | Other function arguments | Linear Regression: family = "mgaussian" (multi-response) | Logistic Regression: family = "binomial" | Multinomial Regression: family = "multinomial" | Poisson Regression: family = "poisson" | Cox Regression: family = "cox" | Programmable GLM families: family = family() | Assessing models on test data | Performance measures | Prevalidation | ROC curves for binomial data | Confusion matrices for classification | Filtering variables | Other Package Features | Sparse matrix support | Fitting big and/or sparse unpenalized generalized linear models | Creating x from mixed variables and/or missing data | Progress bar | Appendix 0: Convergence Criteria | Appendix 1: Internal Parameters | Appendix 2: Comparison with Other Packages | References

Last update: 2025-06-02
Started: 2019-11-09

The Relaxed Lasso
Introduction | Simple relaxed fitting | More details on relaxed fitting | Possible convergence issues for relaxed fits | Application to forward stepwise regression | References

Last update: 2021-06-24
Started: 2019-11-09

The family Argument for glmnet
Introduction | Using class "family" objects for the family argument | More on GLM families | Fitting Gaussian, binomial and Poisson GLMs | Timing comparisons | Fitting other GLMs | Class "glmnetfit" objects | Step size halving within iteratively reweighted least squares (IRLS)

Last update: 2021-01-11
Started: 2020-05-14

Readme and manuals

Help Manual

Help pageTopics
Elastic net model paths for some generalized linear modelsglmnet-package
assess performance of a 'glmnet' object using test data.assess.glmnet confusion.glmnet roc.glmnet
Simulated data for the glmnet vignettebeta_CVX x y
fit a glm with all the options in 'glmnet'bigGlm
Synthetic dataset with binary responseBinomialExample
compute C index for a Cox modelCindex
Extract coefficients from a glmnet objectcoef.glmnet coef.relaxed predict.coxnet predict.elnet predict.fishnet predict.glmnet predict.lognet predict.mrelnet predict.multnet predict.relaxed
Synthetic dataset with right-censored survival responseCoxExample
Compute gradient for Cox modelcoxgrad
Compute deviance for Cox modelcoxnet.deviance
Cross-validation for glmnetcv.glmnet
Elastic net deviance valuedev_function
Extract the deviance from a glmnet objectdeviance.glmnet
Solve weighted least squares (WLS) problem for a single lambda valueelnet.fit
Helper function for Cox deviance and gradientfid
Helper function to get etas (linear predictions)get_eta
Get null deviance, starting mu and lambda maxget_start
fit a GLM with lasso or elasticnet regularizationglmnet relax.glmnet
Internal glmnet algorithm parametersglmnet.control
Fit a GLM with elastic net regularization for a single value of lambdaglmnet.fit
Display the names of the measures used in CV for different "glmnet" familiesglmnet.measures
Fit a GLM with elastic net regularization for a path of lambda valuesglmnet.path
convert a data frame to a data matrix with one-hot encodingmakeX
Synthetic dataset with multiple Gaussian responsesMultiGaussianExample
Synthetic dataset with multinomial responseMultinomialExample
Helper function to fit coxph model for survfit.coxnetmycoxph
Helper function to amend ... for new data in survfit.coxnetmycoxpred
Replace the missing entries in a matrix columnwise with the entries in a supplied vectorna.replace
Elastic net objective function valueobj_function
Elastic net penalty valuepen_function
plot the cross-validation curve produced by cv.glmnetplot.cv.glmnet plot.cv.relaxed
plot coefficients from a "glmnet" objectplot.glmnet plot.mrelnet plot.multnet plot.relaxed
Synthetic dataset with count responsePoissonExample
make predictions from a "cv.glmnet" object.coef.cv.glmnet coef.cv.relaxed predict.cv.glmnet predict.cv.relaxed
Get predictions from a 'glmnetfit' fit objectpredict.glmnetfit
print a cross-validated glmnet objectprint.cv.glmnet print.cv.relaxed
print a glmnet objectprint.bigGlm print.glmnet print.relaxed
Synthetic dataset with Gaussian responseQuickStartExample
Make response for coxnetresponse.coxnet
Generate multinomial samples from a probability matrixrmult
Synthetic dataset with sparse design matrixSparseExample
Add strata to a Surv objectstratifySurv
Compute a survival curve from a coxnet objectsurvfit.coxnet
Compute a survival curve from a cv.glmnet objectsurvfit.cv.glmnet
Helper function to compute weighted mean and standard deviationweighted_mean_sd