# How can I calculate the number of degrees of freedom in the Elastic Net regularization, specifically in R?

In the elastic net, and specifically in glment package in R - how would I obtain the number of degrees of freedom? Note that in the Glmnet Vignette it says that the df you get from the ouput after an Elastic Net model is the number of effective degrees of freedom for the LASSO! I'm using elastic net with alpha = 0.5, so the question is what do I use for the degrees of freedom? (I need that to compute AIC manually) This is from a talk by Hui Zou. You can find the full talk here.

This should be relatively easy to implement in R. If you need some guidance, you can check the lassovar package by A. Kock and L. Callot; see the command .ridge.df in lassovar-ada.R.

Related reference:

Zou, H., Hastie, T., & Tibshirani, R. (2007). On the "degrees of freedom" of the lasso. Ann. Statist., 35(5), 2173–2192. https://doi.org/10.1214/009053607000000127 -- This is the formal proof that df of the lasso = number of non-zero coefficients of the lasso.

• If this is the correct formula, I was wondering why glmnet is just returning the nr of nonzero coefficients as \$df though. Would anyone know? – Tom Wenseleers Apr 14 '18 at 7:35
• I suppose returning the effective df would be computationally costly as it requires one matrix inversion per lambda. Also, the focus of glmnet is on cross-validation rather than tuning parameter selection via information criteria (for which df are relevant). – aahr1 Apr 15 '18 at 10:53
• Is this the true active set or the estimated active set? Using the true active set would make the estimator infeasible, so I suppose we have the estimated one here. – Richard Hardy May 3 '19 at 14:40