crossvalidation {smoothedLasso} | R Documentation |
Perform cross validation to select the regularization parameter.
Description
Perform cross validation to select the regularization parameter.
Usage
crossvalidation(auxfun, X, y, param, K = 10)
Arguments
auxfun |
A complete fitting function which takes as arguments a data matrix |
X |
The design matrix. |
y |
The response vector. |
param |
A vector of regularization parameters which are to be evaluated via cross validation. |
K |
The number of folds for cross validation (should divide the number of rows of |
Value
A vector of average errors over all folds. The entries in the returned vector correspond to the entries in the vector param
in the same order.
References
Hahn, G., Lutz, S., Laha, N., and Lange, C. (2020). A framework to efficiently smooth L1 penalties for linear regression. bioRxiv:2020.09.17.301788.
Tibshirani, R. (2013). Model selection and validation 1: Cross-validation. https://www.stat.cmu.edu/~ryantibs/datamining/lectures/18-val1.pdf
Examples
library(smoothedLasso)
n <- 1000
p <- 100
betavector <- runif(p)
X <- matrix(runif(n*p),nrow=n,ncol=p)
y <- X %*% betavector
auxfun <- function(X,y,lambda) {
temp <- standardLasso(X,y,lambda)
obj <- function(z) objFunction(z,temp$u,temp$v,temp$w)
objgrad <- function(z) objFunctionGradient(z,temp$w,temp$du,temp$dv,temp$dw)
return(minimizeFunction(p,obj,objgrad))
}
lambdaVector <- seq(0,1,by=0.1)
print(crossvalidation(auxfun,X,y,lambdaVector,10))