repeated.cv.glmnet: repeated.cv.glmnet

View source: R/dCVnet_innerloop.R

repeated.cv.glmnetR Documentation

repeated.cv.glmnet

Description

Repeatedly runs a cv.glmnet and returns averaged results. This is intended as a dCVnet internal function.

Usage

repeated.cv.glmnet(
  x,
  y,
  folds = NULL,
  lambda = NULL,
  alpha = 1,
  nfolds = NULL,
  nreps = NULL,
  family = c("gaussian", "binomial", "poisson", "multinomial", "cox", "mgaussian"),
  ...,
  debug = FALSE
)

Arguments

x

input matrix, of dimension nobs x nvars; each row is an observation vector. Can be in sparse matrix format (inherit from class "sparseMatrix" as in package Matrix). Requirement: nvars >1; in other words, x should have 2 or more columns.

y

response variable. Quantitative for family="gaussian", or family="poisson" (non-negative counts). For family="binomial" should be either a factor with two levels, or a two-column matrix of counts or proportions (the second column is treated as the target class; for a factor, the last level in alphabetical order is the target class). For family="multinomial", can be a nc>=2 level factor, or a matrix with nc columns of counts or proportions. For either "binomial" or "multinomial", if y is presented as a vector, it will be coerced into a factor. For family="cox", preferably a Surv object from the survival package: see Details section for more information. For family="mgaussian", y is a matrix of quantitative responses.

folds

This is a list where each element is an integer vector of length n_cases. The integer for each case labels it as belonging to a fold 1:n_folds. This argument overrides the number of repeats and the k in repeated k-fold cv.

lambda

use a fixed, user supplied lambda sequence (descending) see glmnet

alpha

The elasticnet mixing parameter, with 0\le\alpha\le 1. The penalty is defined as

(1-\alpha)/2||\beta||_2^2+\alpha||\beta||_1.

alpha=1 is the lasso penalty, and alpha=0 the ridge penalty.

nfolds

if folds are not specified, how many folds should be used in cross-validation? The default (nfolds=NULL) uses 10-fold.

nreps

if folds are not specified, how many times to repeat k-fold cross-validation? The default (nreps=NULL) uses 5 repeats.

family

Either a character string representing one of the built-in families, or else a glm() family object. For more information, see Details section below or the documentation for response type (above).

...

arguments passed to cv.glmnet

debug

return an unmerged list.

Details

The code will run for any glmnet family, but folds & lambdas must be correctly specified.

Value

a cv.glmnet object with cv performance averaged.

See Also

amalgamate_cv.glmnet

Examples

## Not run: 
data("CoxExample", package = "glmnet") # x and y
mod <- repeated.cv.glmnet(x = CoxExample$x, y = CoxExample$y, family = "cox")

## End(Not run)

AndrewLawrence/dCVnet documentation built on Sept. 24, 2024, 5:24 a.m.