Learn R Programming

⚠️There's a newer version (4.1-8) of this package.Take me there.

Lasso and Elastic-Net Regularized Generalized Linear Models

We provide extremely efficient procedures for fitting the entire lasso or elastic-net regularization path for linear regression (gaussian), multi-task gaussian, logistic and multinomial regression models (grouped or not), Poisson regression and the Cox model. The algorithm uses cyclical coordinate descent in a path-wise fashion. Details may be found in Friedman, Hastie, and Tibshirani (2010), Simon et al. (2011), Tibshirani et al. (2012), Simon, Friedman, and Hastie (2013).

Version 3.0 is a major release with several new features, including:

  • Relaxed fitting to allow models in the path to be refit without regularization. CV will select from these, or from specified mixtures of the relaxed fit and the regular fit;
  • Progress bar to monitor computation;
  • Assessment functions for displaying performance of models on test data. These include all the measures available via cv.glmnet, as well as confusion matrices and ROC plots for classification models;
  • print methods for CV output;
  • Functions for building the x input matrix for glmnet that allow for one-hot-encoding of factor variables, appropriate treatment of missing values, and an option to create a sparse matrix if appropriate.
  • A function for fitting unpenalized a single version of any of the GLMs of glmnet.

Version 4.0 is a major release that allows for any GLM family, besides the built-in families.

Version 4.3 is a major release that expands the scope for survival modeling, allowing for (start, stop) data, strata, and sparse X inputs. It also provides a much-requested method for survival:survfit.

References

Friedman, Jerome, Trevor Hastie, and Robert Tibshirani. 2010. “Regularization Paths for Generalized Linear Models via Coordinate Descent.” Journal of Statistical Software, Articles 33 (1): 1–22. https://doi.org/10.18637/jss.v033.i01.

Simon, Noah, Jerome Friedman, and Trevor Hastie. 2013. “A Blockwise Descent Algorithm for Group-Penalized Multiresponse and Multinomial Regression.”

Simon, Noah, Jerome Friedman, Trevor Hastie, and Robert Tibshirani. 2011. “Regularization Paths for Cox’s Proportional Hazards Model via Coordinate Descent.” Journal of Statistical Software, Articles 39 (5): 1–13. https://doi.org/10.18637/jss.v039.i05.

Tibshirani, Robert, Jacob Bien, Jerome Friedman, Trevor Hastie, Noah Simon, Jonathan Taylor, and Ryan Tibshirani. 2012. “Strong Rules for Discarding Predictors in Lasso-Type Problems.” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 74 (2): 245–66. https://doi.org/10.1111/j.1467-9868.2011.01004.x.

Copy Link

Version

Install

install.packages('glmnet')

Monthly Downloads

160,579

Version

4.1-4

License

GPL-2

Maintainer

Trevor Hastie

Last Published

April 15th, 2022

Functions in glmnet (4.1-4)

Cindex

compute C index for a Cox model
cox.fit

Fit a Cox regression model with elastic net regularization for a single value of lambda
bigGlm

fit a glm with all the options in glmnet
coxgrad

Compute gradient for Cox model
coxnet.deviance

Compute deviance for Cox model
cox_obj_function

Elastic net objective function value for Cox regression model
cox.path

Fit a Cox regression model with elastic net regularization for a path of lambda values
fid

Helper function for Cox deviance and gradient
get_cox_lambda_max

Get lambda max for Cox regression model
glmnet.fit

Fit a GLM with elastic net regularization for a single value of lambda
glmnet.measures

Display the names of the measures used in CV for different "glmnet" families
elnet.fit

Solve weighted least squares (WLS) problem for a single lambda value
glmnet-package

Elastic net model paths for some generalized linear models
get_eta

Helper function to get etas (linear predictions)
glmnet-internal

Internal glmnet functions
predict.cv.glmnet

make predictions from a "cv.glmnet" object.
plot.glmnet

plot coefficients from a "glmnet" object
coef.glmnet

Extract coefficients from a glmnet object
deviance.glmnet

Extract the deviance from a glmnet object
mycoxph

Helper function to fit coxph model for survfit.coxnet
cv.glmnet

Cross-validation for glmnet
predict.glmnetfit

Get predictions from a glmnetfit fit object
na.replace

Replace the missing entries in a matrix columnwise with the entries in a supplied vector
get_start

Get null deviance, starting mu and lambda max
obj_function

Elastic net objective function value
pen_function

Elastic net penalty value
print.cv.glmnet

print a cross-validated glmnet object
response.coxnet

Make response for coxnet
mycoxpred

Helper function to amend ... for new data in survfit.coxnet
dev_function

Elastic net deviance value
plot.cv.glmnet

plot the cross-validation curve produced by cv.glmnet
survfit.cv.glmnet

Compute a survival curve from a cv.glmnet object
use.cox.path

Check if glmnet should call cox.path
glmnet

fit a GLM with lasso or elasticnet regularization
print.glmnet

print a glmnet object
rmult

Generate multinomial samples from a probability matrix
glmnet.control

internal glmnet parameters
glmnet.path

Fit a GLM with elastic net regularization for a path of lambda values
stratifySurv

Add strata to a Surv object
survfit.coxnet

Compute a survival curve from a coxnet object
weighted_mean_sd

Helper function to compute weighted mean and standard deviation
makeX

convert a data frame to a data matrix with one-hot encoding
MultiGaussianExample

Synthetic dataset with multiple Gaussian responses
beta_CVX

Simulated data for the glmnet vignette
CoxExample

Synthetic dataset with right-censored survival response
MultinomialExample

Synthetic dataset with multinomial response
QuickStartExample

Synthetic dataset with Gaussian response
BinomialExample

Synthetic dataset with binary response
PoissonExample

Synthetic dataset with count response
assess.glmnet

assess performance of a 'glmnet' object using test data.
SparseExample

Synthetic dataset with sparse design matrix