cv.gamlr: Cross Validation for gamlr

View source: R/cv.gamlr.R

cv.gamlrR Documentation

Cross Validation for gamlr

Description

Cross validation for gamma lasso penalty selection.

Usage

cv.gamlr(x, y, nfold=5, foldid=NULL, verb=FALSE, cl=NULL, ...)
## S3 method for class 'cv.gamlr'
plot(x, select=TRUE, df=TRUE, ...)
## S3 method for class 'cv.gamlr'
coef(object, select=c("1se","min"), ...)
## S3 method for class 'cv.gamlr'
predict(object, newdata, select=c("1se","min"), ...)

Arguments

x

Covariates; see gamlr.

y

Response; see gamlr.

nfold

The number of cross validation folds.

foldid

An optional length-n vector of fold memberships for each observation. If specified, this dictates nfold.

verb

Whether to print progress through folds.

cl

possible parallel library cluster. If this is not-NULL, the CV folds are executed in parallel. This copies the data nfold times, so make sure you have the memory space.

...

Arguments to gamlr.

object

A gamlr object.

newdata

New x data for prediction.

select

In prediction and coefficient extraction, select which "best" model to return: select="min" is that with minimum average OOS deviance, and select="1se" is that whose average OOS deviance is no more than 1 standard error away from the minimum. In plot, whether to draw these selections.

df

Whether to add to the plot degrees of freedom along the top axis.

Details

Fits a gamlr regression to the full dataset, and then performs nfold cross validation to evaluate out-of-sample (OOS) performance for different penalty weights.

plot.cv.gamlr can be used to plot the results: it shows mean OOS deviance with 1se error bars.

Value

gamlr

The full-data fitted gamlr object.

nfold

The number of CV folds.

foldid

The length-n vector of fold memberships.

cvm

Mean OOS deviance by gamlr\$lambda

cvs

The standard errors on cvm.

seg.min

The index of minimum cvm.

seg.1se

The index of 1se cvm (see details).

lambda.min

Penalty at minimum cvm.

lambda.1se

Penalty at 1se cvm.

Author(s)

Matt Taddy mataddy@gmail.com

References

Taddy (2017 JCGS), One-Step Estimator Paths for Concave Regularization, http://arxiv.org/abs/1308.5623

See Also

gamlr, hockey

Examples


n <- 100
p <- 100

xvar <- matrix(ncol=p,nrow=p)
for(i in 1:p) for(j in i:p) xvar[i,j] <- 0.5^{abs(i-j)}
x <- matrix(rnorm(p*n), nrow=n)%*%chol(xvar)
beta <- matrix( (-1)^(1:p)*exp(-(1:p)/10) )
mu = x%*%beta
y <- mu + rnorm(n,sd=sd(as.vector(mu))/2)

## fit with gamma=1 concavity
cvfit <- cv.gamlr(x, y, gamma=1, verb=TRUE)

coef(cvfit)[1:3,] # 1se default
coef(cvfit, select="min")[1:3,] # min OOS deviance

predict(cvfit, x[1:2,], select="min")
predict(cvfit$gamlr, x[1:2,], select=cvfit$seg.min)

par(mfrow=c(1,2))
plot(cvfit)
plot(cvfit$gamlr)


gamlr documentation built on April 17, 2023, 1:06 a.m.

Related to cv.gamlr in gamlr...