cv.sparsegl {sparsegl} | R Documentation |
Cross-validation for a sparsegl
object.
Description
Performs k-fold cross-validation for sparsegl()
.
This function is largely similar glmnet::cv.glmnet()
.
Usage
cv.sparsegl(
x,
y,
group = NULL,
family = c("gaussian", "binomial"),
lambda = NULL,
pred.loss = c("default", "mse", "deviance", "mae", "misclass"),
nfolds = 10,
foldid = NULL,
weights = NULL,
offset = NULL,
...
)
Arguments
x |
Double. A matrix of predictors, of dimension
|
y |
Double/Integer/Factor. The response variable.
Quantitative for |
group |
Integer. A vector of consecutive integers describing the grouping of the coefficients (see example below). |
family |
Character or function. Specifies the generalized linear model to use. Valid options are:
For any other type, a valid |
lambda |
A user supplied |
pred.loss |
Loss to use for cross-validation error. Valid options are:
|
nfolds |
Number of folds - default is 10. Although |
foldid |
An optional vector of values between 1 and |
weights |
Double vector. Optional observation weights. These can
only be used with a |
offset |
Double vector. Optional offset (constant predictor without a
corresponding coefficient). These can only be used with a
|
... |
Additional arguments to |
Details
The function runs sparsegl()
nfolds + 1
times; the first to
get the lambda
sequence, and then the remainder to compute the fit
with each of the folds omitted. The average error and standard error
over the folds are computed.
Value
An object of class cv.sparsegl()
is returned, which is a
list with the components describing the cross-validation error.
lambda |
The values of |
cvm |
The mean cross-validated error - a vector of
length |
cvsd |
Estimate of standard error of |
cvupper |
Upper curve = |
cvlower |
Lower curve = |
name |
A text string indicating type of measure (for plotting purposes). |
nnzero |
The number of non-zero coefficients for each |
active_grps |
The number of active groups for each |
sparsegl.fit |
A fitted |
lambda.min |
The optimal value of |
lambda.1se |
The largest value of |
call |
The function call. |
See Also
sparsegl()
, as well as plot()
,
predict()
, and coef()
methods for "cv.sparsegl"
objects.
Examples
n <- 100
p <- 20
X <- matrix(rnorm(n * p), nrow = n)
eps <- rnorm(n)
beta_star <- c(rep(5, 5), c(5, -5, 2, 0, 0), rep(-5, 5), rep(0, (p - 15)))
y <- X %*% beta_star + eps
groups <- rep(1:(p / 5), each = 5)
cv_fit <- cv.sparsegl(X, y, groups)