Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

lasso.cv

Select Predictors via (10-fold) Cross-Validation of the Lasso


Description

Performs (n-fold) cross-validation of the lasso (via cv.glmnet) and determines the prediction optimal set of parameters.

Usage

lasso.cv(x, y,
         nfolds = 10,
         grouped = nrow(x) > 3*nfolds,
         ...)

Arguments

x

numeric design matrix (without intercept) of dimension n * p.

y

response vector of length n.

nfolds

the number of folds to be used in the cross-validation

grouped

corresponds to the grouped argument to cv.glmnet. This has a smart default such that glmnet does not give a warning about too small sample size.

...

further arguments to be passed to cv.glmnet.

Details

The function basically only calls cv.glmnet, see source code.

Value

Vector of selected predictors.

Author(s)

Lukas Meier

See Also

hdi which uses lasso.cv() by default; cv.glmnet. An alternative for hdi(): lasso.firstq.

Examples

x <- matrix(rnorm(100*1000), nrow = 100, ncol = 1000)
y <- x[,1] * 2 + x[,2] * 2.5 + rnorm(100)
sel <- lasso.cv(x, y)
sel

hdi

High-Dimensional Inference

v0.1-7
GPL
Authors
Lukas Meier [aut, cre], Ruben Dezeure [aut], Nicolai Meinshausen [aut], Martin Maechler [aut], Peter Buehlmann [aut]
Initial release
2019-03-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.