Search code examples
rstatisticsglmnet

R: Getting AIC/BIC/Likelihood from GLMNet


I'm wondering if I can get AIC and BIC from GLMNet. I've found glmnet.cr that seems to be able to do it but my response is time, not ordinal. I could calculate it myself from likelihood but glmnet doesn't return that either.

Tangential: can I actually return the l1norm? I feel like it should just be

fit$norm

but it doesn't seem to be. (I know it says don't pull the numbers out but I'm actually not using the R)

Thanks in advance for the help.


Solution

  • I was struggling a lot with a way how to calculate AIC and BIC for glmnet models. However, after quite a lot of searching, I found on the third page of google results the answer. It can be found here. I am posting it here for future readers as I believe I cannot be the only one.

    In the end, I implemented the AIC and BIC in the following way:

    fit <- glmnet(x, y, family = "multinomial") 
    
    tLL <- fit$nulldev - deviance(fit)
    k <- fit$df
    n <- fit$nobs
    AICc <- -tLL+2*k+2*k*(k+1)/(n-k-1)
    AICc
    
    BIC<-log(n)*k - tLL
    BIC