lambdaseq {tsutils} | R Documentation |
Generate sequence of lambda for LASSO regression
Description
Calculates the lambdaMax
value, which is the penalty term (lambda) beyond which coefficients are guaranteed to be all zero and provides a sequence of nLambda
values to lambdaMin
in logarithmic descent.
Usage
lambdaseq(
x,
y,
weight = NA,
alpha = 1,
standardise = TRUE,
lambdaRatio = 1e-04,
nLambda = 100,
addZeroLambda = FALSE
)
Arguments
x |
matrix of regressors. See |
y |
response variable. See |
weight |
vector of |
alpha |
elastic net mixing value. See |
standardise |
if |
lambdaRatio |
ratio between |
nLambda |
length of the lambda sequence. |
addZeroLambda |
if |
Value
A list that contains:
-
lambda
: sequence of lambda values, fromlambdaMax
tolambdaMin
. -
lambdaMin
: minimal lambda value. -
lambdaMax
: maximal lambda value. -
nullMSE
: MSE of the fit using just a constant term.
Author(s)
Oliver Schaer, info@oliverschaer.ch,
Nikolaos Kourentzes, nikolaos@kourentzes.com.
References
Hastie, T., Tibshirani, R., & Wainwright, M. (2015). Statistical learning with sparsity: the lasso and generalizations. CRC press.
Examples
y <- mtcars[,1]
x <- as.matrix(mtcars[,2:11])
lambda <- lambdaseq(x, y)$lambda
## Not run:
library(glmnet)
fit.lasso <- cv.glmnet(x, y, lambda = lambda)
coef.lasso <- coef(fit.lasso, s = "lambda.1se")
## End(Not run)