Solved – glmnet – compute maximal lambda value

glmnet

I would like to be able to compute the glmnet "lambda.max" value, in a logistic regression model. The lambda_max value stands for the smallest value for which all coefficients are zero.

According to the glmnet package vignette, "lambda.max is not given, but easily computed from the input x and y". I have unfortunately no idea on the way to compute this parameter.

Best Answer

The smallest value of lambda for which no parameters are selected may be computed by

$\max_j \frac{1}{\alpha n} \sum_{i=1}^n [Y_i - \bar Y (1- \bar Y)] X_{ij}$

See my example:

n <- 500
p <- 3
b <- c(-5,3,2,0)

X <- cbind(rep(1,n),scale(matrix(rnorm(p*n),nrow=n)))
Y <- rbinom(n,1,prob = exp(X%*%b)/(1 + exp(X%*%b)))

alpha <- .5

max( abs(t(Y - mean(Y)*(1-mean(Y))) %*% X ) )/ ( alpha * n) # largest lambda value
glmnet(x=X,y=Y,family="binomial",alpha = alpha,standardize=FALSE)$lambda[1] # largest lambda value

This comes out of the coordinate descent algorithm from this paper: Friedman, Jerome, Trevor Hastie, and Rob Tibshirani. "Regularization paths for generalized linear models via coordinate descent." Journal of statistical software 33.1 (2010): 1.