cv.rgam {relgam} | R Documentation |
Cross-validation for reluctant generalized additive model (rgam)
Description
Does k
-fold cross-validation for rgam
.
Usage
cv.rgam(x, y, lambda = NULL, family = c("gaussian", "binomial",
"poisson", "cox"), offset = NULL, init_nz, gamma, nfolds = 10,
foldid = NULL, keep = FALSE, parallel = FALSE, verbose = TRUE,
...)
Arguments
x |
Input matrix, of dimension |
y |
Response |
lambda |
A user-supplied |
family |
Response type. Either |
offset |
Offset vector as in |
init_nz |
A vector specifying which features we must include when computing the non-linear features. Default is to construct non-linear features for all given features. |
gamma |
Scale factor for non-linear features (vs. original features),
to be between 0 and 1. Default is 0.8 if |
nfolds |
Number of folds for CV (default is 10). Although |
foldid |
An optional vector of values between 1 and |
keep |
If |
parallel |
If TRUE, use parallel foreach to fit each fold. Must
register parallel before hand, such as doMC or others. Note that this also
passes |
verbose |
Print information as model is being fit? Default is
|
... |
Other arguments that can be passed to |
Details
The function runs rgam
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 error is accumulated, and the average error and standard
deviation over the folds is computed.
Note that cv.rgam
only does cross-validation for lambda but not for
the degrees of freedom hyperparameter.
Value
An object of class "cv.rgam"
.
glmfit |
A fitted |
lambda |
The values of |
nzero_feat |
The number of non-zero features for the model |
nzero_lin |
The number of non-zero linear components for the model
|
nzero_nonlin |
The number of non-zero non-linear components for 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. |
Examples
set.seed(1)
n <- 100; p <- 20
x <- matrix(rnorm(n * p), n, p)
beta <- matrix(c(rep(2, 5), rep(0, 15)), ncol = 1)
y <- x %*% beta + rnorm(n)
cvfit <- cv.rgam(x, y)
# specify number of folds
cvfit <- cv.rgam(x, y, nfolds = 5)