Description Usage Arguments Value References Examples
View source: R/smoothedLasso.r
Perform cross validation to select the regularization parameter.
1 | crossvalidation(auxfun, X, y, param, K = 10)
|
auxfun |
A complete fitting function which takes as arguments a data matrix X, a response vector y, and some parameter p (to be tuned), and returns the estimator (betavector) (minimizer) of the regression operator under investigation. |
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 X). The default is 10. |
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.
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.