cv.lasso {EAinference} | R Documentation |
Compute K-fold cross-validated mean squared error for lasso
Description
Computes K-fold cross-validated mean squared error to propose a lambda value for lasso, group lasso, scaled lasso or scaled group lasso.
Usage
cv.lasso(X, Y, group = 1:ncol(X), weights = rep(1, max(group)), type,
K = 10L, minlbd, maxlbd, num.lbdseq = 100L, parallel = FALSE,
ncores = 2L, plot.it = FALSE, verbose = FALSE)
Arguments
X |
predictor matrix. |
Y |
response vector. |
group |
|
weights |
weight vector with length equal to the number of groups. Default is
|
type |
type of penalty. Must be specified to be one of the following:
|
K |
integer. Number of folds |
minlbd |
numeric. Minimum value of the lambda sequence. |
maxlbd |
numeric. Maximum value of the lambda sequence. |
num.lbdseq |
integer. Length of the lambda sequence. |
parallel |
logical. If |
ncores |
integer. The number of cores to use for parallelization. |
plot.it |
logical. If true, plots the squared error curve. |
verbose |
logical. |
Value
lbd.min |
a value of lambda which gives a minimum squared error. |
lbd.1se |
a largest lambda within 1 standard error from |
lbd.seq |
lambda sequence. |
cv |
mean squared error at each lambda value. |
cvsd |
the standard deviation of cv. |
Examples
set.seed(123)
n <- 30
p <- 50
group <- rep(1:(p/10),each=10)
weights <- rep(1, max(group))
X <- matrix(rnorm(n*p),n)
truebeta <- c(rep(1,5),rep(0,p-5))
Y <- X%*%truebeta + rnorm(n)
# To accelerate the computational time, we set K=2 and num.lbdseq=2.
# However, in practice, Allowing K=10 and num.lbdseq > 100 is recommended.
cv.lasso(X = X, Y = Y, group = group, weights = weights, K = 2,
type = "grlasso", num.lbdseq = 2, plot.it = FALSE)
cv.lasso(X = X, Y = Y, group = group, weights = weights, K = 2,
type = "sgrlasso", num.lbdseq = 2, plot.it = FALSE)