rcv.glmnet: Repeated Cross-Validation for cv.glmnet

View source: R/rcv.glmnet.R

rcv.glmnetR Documentation

Repeated Cross-Validation for cv.glmnet

Description

This functions returns the best lambda of repeated glmnet::cv.glmnet() calls.

Usage

rcv.glmnet(
    x, y,
    lambda = NULL, alpha = 1,
    nrepcv = 100L, nfolds = 10L, foldid = NULL, balanced = FALSE,
    ...,
    trace.it = interactive()
)

Arguments

x

matrix, as in cv.glmnet.

y

response as in cv.glmnet.

lambda

numeric, optional user-supplied lambda sequence; default is NULL and glmnet chooses its own sequence.

alpha

numeric(1), the elasticnet mixing parameter, default is 1 (lasso penality); see glmnet::glmnet() for details.

nrepcv

integer(1), number of repeated cross-validations (outer loop).

nfolds

integer, number of folds, same as in cv.glmnet.

foldid

matrix, an optional matrix with nrepcv rows and nrow(x) columns containing ids from 1 to nfolds identifying what fold each observation is in. If given nrepcv and nfolds are ignored.

balanced

logical, should classes/status be balanced in the folds (default: FALSE)?

...

further arguments passed to cv.glmnet.

trace.it

integer, if trace.it = 1, then a progress bar is displayed.

Value

An object of class rcv.glmnet that extends the cv.glmnet class.

Author(s)

Sebastian Gibb

References

Jerome Friedman, Trevor Hastie, Robert Tibshirani (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 33(1), 1-22. URL https://www.jstatsoft.org/v33/i01/.

Noah Simon, Jerome Friedman, Trevor Hastie, Rob Tibshirani (2011). Regularization Paths for Cox's Proportional Hazards Model via Coordinate Descent. Journal of Statistical Software, 39(5), 1-13. URL https://www.jstatsoft.org/v39/i05/.

See Also

glmnet::cv.glmnet()

Examples

# Examples taken from ?"glmnet::cv.glmnet"
set.seed(1010)
n <- 1000
p <- 100
nzc <- trunc(p/10)
x <- matrix(rnorm(n * p), n, p)
beta <- rnorm(nzc)
fx <- x[, seq(nzc)] %*% beta
eps <- rnorm(n) * 5
y <- drop(fx + eps)
set.seed(1011)
# nrepcv should usually be higher but to keep the runtime of the example low
# we choose 2 here
rcvob <- rcv.glmnet(x, y, nrepcv = 2, nfolds = 3)
plot(rcvob)
title("Gaussian Family", line = 2.5)
coef(rcvob)
predict(rcvob, newx = x[1:5, ], s = "lambda.min")

ampel-leipzig/ameld documentation built on Aug. 23, 2024, 7:31 p.m.