softthresh: Fit a sparse variant of the fused lasso

View source: R/softthresh.R

softthreshR Documentation

Fit a sparse variant of the fused lasso

Description

This function computes solution path to a fused lasso problem of the form

1/2 ∑_{i=1}^n (y_i - β_i)^2 + λ ∑_{(i,j) \in E} |β_i - β_j| + γ \cdot λ ∑_{i=1}^p |β_i|,

given the solution path corresponding to γ=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)

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.

Value

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

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

# 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)))

genlasso documentation built on Aug. 22, 2022, 9:09 a.m.