cv.pcLasso {pcLasso} | R Documentation |
Cross-validation for pcLasso
Description
Does k
-fold cross-validation for pcLasso
.
Usage
cv.pcLasso(x, y, w = rep(1, length(y)), ratio = NULL, theta = NULL,
groups = vector("list", 1), family = "gaussian", nfolds = 10,
foldid = NULL, keep = FALSE, verbose = FALSE, ...)
Arguments
x |
|
y |
|
w |
Observation weights. Default is 1 for each observation. |
ratio |
Ratio of shrinkage between the second and first principal components
in the absence of the |
theta |
Multiplier for the quadratic penalty: a non-negative real number.
|
groups |
A list describing which features belong in each group. The
length of the list should be equal to the number of groups, with
|
family |
Response type. Either |
nfolds |
Number of folds for CV (default is 10). Although |
foldid |
An optional vector of values between 1 and |
keep |
If |
verbose |
Print out progess along the way? Default is |
... |
Other arguments that can be passed to |
Details
This function runs pcLasso nfolds+1
times: the first to get the
lambda
sequence, and the remaining nfolds
times to compute the
fit with each of the folds omitted. The error is accumulated, and the mean
error and standard deviation over the folds is compued. Note that
cv.pcLasso
does NOT search for values of theta
or ratio
.
A specific value of theta
or ratio
should be supplied.
Value
An object of class "cv.pcLasso"
, which is a list with the
ingredients of the cross-validation fit.
glmfit |
A fitted |
theta |
Value of |
lambda |
The values of |
nzero |
If the groups overlap, the number of non-zero coefficients
in the model |
orignzero |
If the groups are overlapping, this is the number of
non-zero coefficients in the model |
fit.preval |
If |
cvm |
The mean cross-validated error: a vector of length
|
cvse |
Estimate of standard error of |
cvlo |
Lower curve = |
cvup |
Upper curve = |
lambda.min |
The value of |
lambda.1se |
The largest value of |
foldid |
If |
name |
Name of error measurement used for CV. |
call |
The call that produced this object. |
See Also
pcLasso
and plot.cv.pcLasso
.
Examples
set.seed(1)
x <- matrix(rnorm(100 * 20), 100, 20)
y <- rnorm(100)
groups <- vector("list", 4)
for (k in 1:4) {
groups[[k]] <- 5 * (k-1) + 1:5
}
cvfit1 <- cv.pcLasso(x, y, groups = groups, ratio = 0.8)
# change no. of CV folds
cvfit2 <- cv.pcLasso(x, y, groups = groups, ratio = 0.8, nfolds = 5)
# specify which observations are in each fold
foldid <- sample(rep(seq(5), length = length(y)))
cvfit3 <- cv.pcLasso(x, y, groups = groups, ratio = 0.8, foldid = foldid)
# keep=TRUE to have pre-validated fits and foldid returned
cvfit4 <- cv.pcLasso(x, y, groups = groups, ratio = 0.8, keep = TRUE)