Cross Validated Asked by Thomas on August 20, 2020

I am using the `glmnet`

package in R, and not(!) the `caret`

package for my binary ElasticNet regression. I have come to the point where I would like to compare models (e.g. lambda set to `lambda.1se`

or `lambda.min`

, and models where `k-fold`

is set to 5 or 10). But, I have not yet achieved to compute the `AICc`

or `BIC`

for my models. How do I do that? I tried this and this but it did not work for me, I only get an empty list.

Code:

```
set.seed(123)
foldid <- sample(rep(seq(10), length.out = nrow(x.train)))
list.of.fits.df <- list()
for (i in 0:10){
fit.name <- paste0("alpha", i/10)
list.of.fits.df[[fit.name]] <- cv.glmnet(x.train, y.train, type.measure = c("auc"), alpha = i/10, family = "binomial", nfolds = 10, foldid = foldid, parallel = TRUE)
}
best.fit <- coef(list.of.fits.df[[fit.name]], s = list.of.fits.df[[fit.name]]$lambda.1se)
best.fit.min <- coef(list.of.fits.df[[fit.name]], s = list.of.fits.df[[fit.name]]$lambda.min)
#AICc & BIC
#???
```

How do I find an `AIC`

and/or `BIC`

value from my `list.of.fits[[fit.name]]$lambda.min`

?

Create a function

```
cv_aicc <- function(fit, lambda = 'lambda.1se'){
whlm <- which(fit$lambda == fit[[lambda]])
with(fit$glmnet.fit,
{
tLL <- nulldev - nulldev * (1 - dev.ratio)[whlm]
k <- df[whlm]
n <- nobs
return(list('AICc' = - tLL + 2 * k + 2 * k * (k + 1) / (n - k - 1),
'BIC' = log(n) * k - tLL))
})
}
```

Plug in the lists now.

```
AICc <- cv_aicc(list.of.fits.df[[fit.name]])
AICc.min <- cv_aicc(list.of.fits.df[[fit.name]], 'lambda.min')
```

Correct answer by Thomas on August 20, 2020

2 Asked on December 21, 2020 by uzbekistan

dynamic regression fixed effects model generalized moments panel data random effects model

2 Asked on December 20, 2020 by david-ernst

anova experiment design multiple comparisons post hoc statistical power

0 Asked on December 19, 2020 by user276835

conditional probability machine learning mathematical statistics nested data regression

0 Asked on December 18, 2020 by oumayma-bounouh

forecast combination forecasting normal distribution pdf weights

1 Asked on December 18, 2020 by farzad

0 Asked on December 18, 2020 by germania

0 Asked on December 17, 2020 by pavel

1 Asked on December 17, 2020

0 Asked on December 16, 2020 by whuber

1 Asked on December 16, 2020 by jlearner

1 Asked on December 16, 2020 by ber08

forecasting garch hidden markov model variance volatility forecasting

0 Asked on December 16, 2020 by noumenal

1 Asked on December 15, 2020 by emmettcc

1 Asked on December 15, 2020 by suzee

generalized linear model machine learning multiple regression neural networks regression

0 Asked on December 15, 2020

1 Asked on December 14, 2020 by bandit_king28

9 Asked on December 13, 2020 by jessica

1 Asked on December 13, 2020 by kh_one

1 Asked on December 13, 2020 by l-sicilis

Get help from others!

Recent Questions

- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?
- Does Google Analytics track 404 page responses as valid page views?

Recent Answers

- Peter Machado on Why fry rice before boiling?
- Lex on Does Google Analytics track 404 page responses as valid page views?
- Jon Church on Why fry rice before boiling?
- haakon.io on Why fry rice before boiling?
- Joshua Engel on Why fry rice before boiling?

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP