cv.gamsel {gamsel} | R Documentation |
Cross-validation Routine for Gamsel
Description
A routine for performing K-fold cross-validation for gamsel.
Usage
cv.gamsel(
x,
y,
lambda = NULL,
family = c("gaussian", "binomial"),
degrees = rep(10, p),
dfs = rep(5, p),
bases = pseudo.bases(x, degrees, dfs, parallel = parallel, ...),
type.measure = c("mse", "mae", "deviance", "class"),
nfolds = 10,
foldid,
keep = FALSE,
parallel = FALSE,
...
)
Arguments
x |
|
y |
response |
lambda |
Optional use-supplied lambda sequence. If |
family |
|
degrees |
|
dfs |
|
bases |
|
type.measure |
Loss function for cross-validated error calculation.
Currently there are four options: |
nfolds |
Numer of folds (default is 10). Maximum value is |
foldid |
Optional vector of length |
keep |
If |
parallel |
If |
... |
Other arguments that can be passed to |
Details
This function has the effect of running gamsel
nfolds
+1 times.
The initial run uses all the data and gets the lambda
sequence. The
remaining runs fit the data with each of the folds omitted in turn. The
error is accumulated, and the average error and standard deviation over the
folds is computed. Note that cv.gamsel
does NOT search for values
for gamma
. A specific value should be supplied, else gamma=.4
is assumed by default. If users would like to cross-validate gamma
as
well, they should call cv.gamsel
with a pre-computed vector
foldid
, and then use this same fold vector in separate calls to
cv.gamsel
with different values of gamma
. Note also that the
results of cv.gamsel
are random, since the folds are selected at
random. Users can reduce this randomness by running cv.gamsel
many
times, and averaging the error curves.
Value
an object of class "cv.gamsel"
is returned, which is a list
with the ingredients of the cross-validation fit.
lambda |
the values
of |
cvm |
The mean cross-validated
error - a vector of length |
cvsd |
estimate of
standard error of |
cvup |
upper curve = |
cvlo |
lower curve = |
nzero |
number of non-zero
coefficients at each |
name |
a text string indicating type of measure (for plotting purposes). |
gamsel.fit |
a fitted gamsel object for the full data. |
lambda.min |
value of |
lambda.1se |
largest value of |
fit.preval |
if |
foldid |
if
|
index.min |
the sequence number of the minimum lambda. |
index.1se |
the sequence number of the 1se lambda value. |
Author(s)
Alexandra Chouldechova and Trevor Hastie
Maintainer: Trevor
Hastie hastie@stanford.edu
References
Chouldechova, A. and Hastie, T. (2015) Generalized Additive Model Selection
See Also
gamsel
, plot
function for cv.gamsel
object.
Examples
##data=gamsel:::gendata(n=500,p=12,k.lin=3,k.nonlin=3,deg=8,sigma=0.5)
data = readRDS(system.file("extdata/gamsel_example.RDS", package = "gamsel"))
attach(data)
bases=pseudo.bases(X,degree=10,df=6)
# Gaussian gam
gamsel.out=gamsel(X,y,bases=bases)
par(mfrow=c(1,2),mar=c(5,4,3,1))
summary(gamsel.out)
gamsel.cv=cv.gamsel(X,y,bases=bases)
par(mfrow=c(1,1))
plot(gamsel.cv)
par(mfrow=c(3,4))
plot(gamsel.out,newx=X,index=20)