R/cv.lasso.klcompreg.R

Defines functions cv.lasso.klcompreg

Documented in cv.lasso.klcompreg

cv.lasso.klcompreg <- function(y, x, alpha = 1, type = "grouped", nfolds = 10,
                               folds = NULL, seed = NULL, graph = FALSE) {
  n <- dim(y)[1]  ## sample size
  ina <- 1:n
  if ( is.null(folds) )  folds <- Compositional::makefolds(ina, nfolds = nfolds,
                                                           stratified = FALSE, seed = seed)
  nfolds <- length(folds)
  foldid <- numeric(n)
  for ( i in 1:nfolds )  foldid[ folds[[ i ]] ] <- i

  mod <- glmnet::cv.glmnet(x, y, alpha = alpha, family = "multinomial", type.multinomial = type,
                           foldid = foldid, type.measure = "deviance")
  if ( graph )  plot(mod, cex.lab = 1.2, cex.axis = 1.2)
  mod
}

Try the Compositional package in your browser

Any scripts or data that you put into this service are public.

Compositional documentation built on Oct. 23, 2023, 5:09 p.m.