cv.ernet: Cross-validation for ernet

View source: R/cv.ernet.R

cv.ernetR Documentation

Cross-validation for ernet

Description

Does k-fold cross-validation for ernet, produces a plot, and returns a value for lambda. This function is based on the cv function from the glmnet package.

Usage

cv.ernet(
  x,
  y,
  lambda = NULL,
  pred.loss = "loss",
  nfolds = 5,
  foldid,
  tau = 0.5,
  ...
)

Arguments

x

x matrix as in ernet.

y

response variable y as in ernet.

lambda

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

pred.loss

loss function used to calculate cross-validation error. The only option now is "loss", which is the asymmetric squared error loss (ASEL).

nfolds

number of folds. Default value is 5. Although nfolds can be as large as the sample size (leave-one-out CV), it is not recommended for large datasets. Smallest value allowed is 3.

foldid

an optional vector of values between 1 and nfolds, identifying what fold each observation is in. If supplied, nfolds will be supressed.

tau

the asymmetry coefficient τ used in the asymmetric squared error loss.

...

other arguments that can be passed to ernet.

Details

The function runs ernet nfolds+1 times; the first to get the lambda sequence, and the remainder to compute the fit with each of the folds removed. The average error and standard deviation over the folds are computed.

Value

an object of class cv.ernet is returned, which is a list with the ingredients of the cross-validation fit.

lambda

the values of lambda used in the fits.

cvm

the mean cross-validated error - a vector of length length(lambda).

cvsd

estimate of standard error of cvm.

cvupper

upper curve = cvm+cvsd.

cvlower

lower curve = cvm-cvsd.

nzero

number of non-zero coefficients at each lambda.

name

a text string indicating type of measure (for plotting purposes).

ernet.fit

a fitted ernet object for the full data.

lambda.min

The optimal value of lambda that gives minimum cross validation error cvm.

lambda.1se

The largest value of lambda such that error is within 1 standard error of the minimum.

Author(s)

Yuwen Gu and Hui Zou

Maintainer: Yuwen Gu <yuwen.gu@uconn.edu>

See Also

ernet

Examples


set.seed(1)
n <- 100
p <- 400
x <- matrix(rnorm(n * p), n, p)
y <- rnorm(n)
tau <- 0.90
pf <- abs(rnorm(p))
pf2 <- abs(rnorm(p))
lambda2 <- 1
m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf,
                  pf2 = pf2, standardize = FALSE, intercept = FALSE,
                  lambda2 = lambda2)


SALES documentation built on Aug. 16, 2022, 1:05 a.m.

Related to cv.ernet in SALES...