trendfilter and fusedlasso.genlasso(y, X, D, approx = FALSE, maxsteps = 2000, minlam = 0,
tol = 1e-11, eps = 1e-8, verbose = FALSE)X is
assumed to be the identity matrix. If the passed X does not
have full column rank, then a X, or if no X is given, the length of
y. This can be a sparse matrix from Matrix package,
but this will be iFALSE.X is column rank deficient. Default is
1e-8.FALSE
indicates a variable leaving the boundary.maxsteps or
minlam options results in a value of FALSE).genlasso function lies in its flexibility, i.e., the user can
specify any penalty matrix D of their choosing. However, for a
trend filtering problem or a fused lasso problem, it is strongly
recommended to use one of the speciality functions,
trendfilter or fusedlasso. When compared
to these functions, genlasso is not as numerically stable and
much less efficient. Note that, when D is passed as a sparse matrix, the linear
systems that arise at each step of the path algorithm are solved
separately via a sparse solver. The usual strategy (when D is
simply a matrix) is to maintain a matrix factorization of D,
and solve these systems by (or downdating) this factorization, as
these linear systems are highly related. Therefore,
when D is sufficiently sparse and structured, it can be
advantageous to pass it as a sparse matrix; but if D is truly
dense, passing it as a sparse matrix will be highly inefficient.
trendfilter, fusedlasso,
coef.genlasso, predict.genlasso,
plot.genlasso# Using the generalized lasso to run a standard lasso regression
# (not advisable---for example purposes only!)
set.seed(1)
n = 100
p = 10
X = matrix(rnorm(n*p),nrow=n)
y = 3*X[,1] + rnorm(n)
D = diag(1,p)
out = genlasso(y,X,D)
coef(out, lambda=sqrt(n*log(p)))Run the code above in your browser using DataLab