elastic.net {quadrupen} | R Documentation |
Fit a linear model with elastic-net regularization
Description
Adjust a linear model with elastic-net regularization, mixing a
(possibly weighted) \ell_1
-norm (LASSO) and a
(possibly structured) \ell_2
-norm (ridge-like). The
solution path is computed at a grid of values for the
\ell_1
-penalty, fixing the amount of \ell_2
regularization. See details for the criterion optimized.
Usage
elastic.net(
x,
y,
lambda1 = NULL,
lambda2 = 0.01,
penscale = rep(1, p),
struct = NULL,
intercept = TRUE,
normalize = TRUE,
naive = FALSE,
nlambda1 = ifelse(is.null(lambda1), 100, length(lambda1)),
min.ratio = ifelse(n <= p, 0.01, 1e-04),
max.feat = ifelse(lambda2 < 0.01, min(n, p), min(4 * n, p)),
beta0 = NULL,
control = list(),
checkargs = TRUE
)
Arguments
x |
matrix of features, possibly sparsely encoded
(experimental). Do NOT include intercept. When normalized os
|
y |
response vector. |
lambda1 |
sequence of decreasing |
lambda2 |
real scalar; tunes the |
penscale |
vector with real positive values that weight the
|
struct |
matrix structuring the coefficients (preferably
sparse). Must be at least positive semidefinite (this is checked
internally if the |
intercept |
logical; indicates if an intercept should be
included in the model. Default is |
normalize |
logical; indicates if variables should be
normalized to have unit L2 norm before fitting. Default is
|
naive |
logical; Compute either 'naive' of classic
elastic-net as defined in Zou and Hastie (2006): the vector of
parameters is rescaled by a coefficient |
nlambda1 |
integer that indicates the number of values to put
in the |
min.ratio |
minimal value of |
max.feat |
integer; limits the number of features ever to
enter the model; i.e., non-zero coefficients for the Elastic-net:
the algorithm stops if this number is exceeded and |
beta0 |
a starting point for the vector of parameter. When
|
control |
list of argument controlling low level options of the algorithm –use with care and at your own risk– :
|
checkargs |
logical; should arguments be checked to
(hopefully) avoid internal crashes? Default is
|
Details
The optimized criterion is the following:
βhatλ1,λ2 = argminβ 1/2 RSS(β) + λ1 | D β |1 + λ/2 2 βT S β,
where
D
is a diagonal matrix, whose diagonal terms are provided
as a vector by the penscale
argument. The \ell_2
structuring matrix S
is provided via the struct
argument, a positive semidefinite matrix (possibly of class
Matrix
).
Value
an object with class quadrupen
, see the
documentation page quadrupen
for details.
See Also
See also quadrupen
,
plot,quadrupen-method
and crossval
.
Examples
## Simulating multivariate Gaussian with blockwise correlation
## and piecewise constant vector of parameters
beta <- rep(c(0,1,0,-1,0), c(25,10,25,10,25))
cor <- 0.75
Soo <- toeplitz(cor^(0:(25-1))) ## Toeplitz correlation for irrelevant variables
Sww <- matrix(cor,10,10) ## bloc correlation between active variables
Sigma <- bdiag(Soo,Sww,Soo,Sww,Soo)
diag(Sigma) <- 1
n <- 50
x <- as.matrix(matrix(rnorm(95*n),n,95) %*% chol(Sigma))
y <- 10 + x %*% beta + rnorm(n,0,10)
labels <- rep("irrelevant", length(beta))
labels[beta != 0] <- "relevant"
## Comparing the solution path of the LASSO and the Elastic-net
plot(elastic.net(x,y,lambda2=0), label=labels) ## a mess
plot(elastic.net(x,y,lambda2=10), label=labels) ## a lot better