Learn R Programming

genlasso (version 1.6.1)

softthresh: Fit a sparse variant of the fused lasso

Description

This function computes solution path to a fused lasso problem of the form $$ 1/2 \sum_{i=1}^n (y_i - \beta_i)^2 + \lambda \sum_{(i,j) \in E} |\beta_i - \beta_j| + \gamma \cdot \lambda \sum_{i=1}^p |\beta_i|, $$ given the solution path corresponding to \(\gamma=0\). Note that the predictor matrix here is the identity, and in this case the new solution path is given by a simple soft-thresholding operation (Friedman et al. 2007).

Usage

softthresh(object, lambda, gamma)

Value

Returns a numeric matrix of primal solutions, one column for each value of lambda.

Arguments

object

an object of class "fusedlasso", fit with no predictor matrix X (taken to mean that the predictor matrix is the identity) and with gamma set to 0. Other objects will issue a warning that soft-thresholding does not give the exact primal solution path to a sparsified generalized lasso problem.

lambda

a numeric vector giving the values of lambda at which the solution should be computed and returned; if missing, defaults to the knots in the solution path stored in object.

gamma

a numeric variable giving the ratio of the fusion and sparsity tuning parameters, must be greater than or equal to 0.

References

Friedman J., Hastie T., Hoefling H. and Tibshirani, R. (2007), "Pathwise coordinate optimization", Annals of Applied Statistics 1 (2) 302--332.

See Also

fusedlasso

Examples

Run this code
# The 1d fused lasso
set.seed(0)
n = 100
beta0 = rep(sample(1:10,5),each=n/5)
beta0 = beta0-mean(beta0)
y = beta0 + rnorm(n,sd=0.8)
a = fusedlasso1d(y)

lambda = 4
b1 = coef(a,lambda=lambda)$beta

gamma = 0.5
b2 = softthresh(a,lambda=lambda,gamma=gamma)

plot(1:n,y)
lines(1:n,b1)
lines(1:n,b2,col="red")
legend("topright",lty=1,col=c("black","red"),
       legend=c(expression(gamma==0),expression(gamma==0.5)))

Run the code above in your browser using DataLab