| fused_lasso | R Documentation |
This function fits the standard version of the fused lasso.
It can take a general matrix x and allows for possible weights on the
lambda1 and lambda2 penalties.
fused_lasso(
x,
y,
lambda1 = NULL,
lambda2 = 1,
pen_fused = c("L1", "L2", "Huber"),
penscale = rep(1, ncol(x)),
struct = NULL,
intercept = TRUE,
normalize = TRUE,
nlambda1 = ifelse(is.null(lambda1), 50, length(lambda1)),
minratio = 0.01,
maxfeat = ifelse(lambda2 < 1, min(nrow(x), ncol(x)), min(2 * nrow(x), ncol(x))),
beta0 = rep(0, ncol(x)),
control = list()
)
x |
matrix of features, possibly sparsely encoded
(experimental). Do NOT include intercept. When normalized is
|
y |
response vector. |
lambda1 |
sequence of decreasing |
lambda2 |
real scalar; tunes the |
pen_fused |
penalty used for fusing the variables (either L1, L2 or Huber). Default is L1 |
penscale |
vector with real positive values that weight the penalty of each feature. Default sets all weights to 1. |
struct |
Description of the graph that corresponds to 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
|
nlambda1 |
integer that indicates the number of values to put
in the |
minratio |
minimal value of |
maxfeat |
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. By default, will initialized zero. May save time in some situation. |
control |
list of argument controlling low level options of the algorithm:
|
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_1 fusion penalty
is structured by a possibly weighted graph G provided via the struct
argument, as a symmetric (undirected) adjacency matrix.
an object with class FusedLassoFit, inheriting from QuadrupenFit.
Original code by Holger Hoefling, refactoring by Julien Chiquet
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 <- Matrix::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)
res <- fused_lasso(x, y, lambda2=5)
G <- igraph::make_ring(ncol(x)) |> igraph::as_adjacency_matrix(sparse = FALSE)
resG <- fused_lasso(x, y, lambda2=5, struct = G)
plot(res)
plot(resG)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.