cv.sparsenet: Cross-validation for sparsenet

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/cv.sparsenet.R

Description

Does k-fold cross-validation for sparsenet, produces a plot, and returns values for gamma, lambda

Usage

1
2
cv.sparsenet(x, y, weights, type.measure = c("mse", "mae"), ...,nfolds = 10,
       foldid, trace.it=FALSE)

Arguments

x

x matrix as in sparsenet.

y

response y as in sparsenet.

weights

Observation weights; defaults to 1 per observation

type.measure

loss to use for cross-validation. Currently two options: squared-error (type.measure="mse") or mean-absolute error ( type.measure="mae" )

...

Other arguments that can be passed to sparsenet.

nfolds

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

foldid

an optional vector of values between 1 and nfold identifying whhat fold each observation is in. If supplied, nfold can be missing.

trace.it

If TRUE, then we get a printout that shows the progress

Details

The function runs sparsenet 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.

Value

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

lambda

the values of lambda used in the fits. This is an nlambda x ngamma matrix

cvm

The mean cross-validated error - a matrix shaped like lambda

cvsd

estimate of standard error of cvm.

cvup

upper curve = cvm+cvsd.

cvlo

lower curve = cvm-cvsd.

nzero

number of non-zero coefficients at each lambda, gamma pair.

name

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

sparsenet.fit

a fitted sparsenet object for the full data.

call

The call that produced this object

parms.min

values of gamma, lambda that gives minimum cvm.

which.min

indices for the above

lambda.1se

gamma, lambda of smallest model (df) such that error is within 1 standard error of the minimum.

which.1se

indices of the above

Author(s)

Rahul Mazumder, Jerome Friedman and Trevor Hastie

Maintainer: Trevor Hastie <[email protected]>

References

http://www.stanford.edu/~hastie/Papers/Sparsenet/jasa_MFH_final.pdf

See Also

glmnet package, predict, coef, print and plot methods, and the sparsenet function.

Examples

1
2
3
4
5
6
7
train.data=gendata(100,1000,nonzero=30,rho=0.3,snr=3)
fit=sparsenet(train.data$x,train.data$y)
par(mfrow=c(3,3))
plot(fit)
par(mfrow=c(1,1))
fitcv=cv.sparsenet(train.data$x,train.data$y,trace.it=TRUE)
plot(fitcv)

Example output

Loading required package: glmnet
Loading required package: Matrix
Loading required package: foreach
Loaded glmnet 2.0-12

Loading required package: shape
Loaded sparsenet 1.2

12345678910

sparsenet documentation built on May 29, 2017, 2:19 p.m.