The function plot.genlasso produces a plot of the coordinate
paths for objects of class "genlasso". This can be helpful for
visualizing the full solution path for small problems; however, for
moderate or large problems, the plot produced can be quite dense and
difficult to interpret. The function plot.trendfilter applies
to objects of class "trendfilter", and plots trend filtering
coefficients at a single value of lambda (or multiple
values, as specified by the user) as a function of the input positions
(which, recall, are assumed to be evenly spaced if not specified).
The function plot.cv.trendfilter plots the output of
cv.trendfilter.
Usage
## S3 method for class 'genlasso'
plot(x, type = c("primal", "dual", "both"), numbers = FALSE,
vlines = TRUE, xlab, ylab, ...)
## S3 method for class 'trendfilter'
plot(x, style = c("trend", "path"), lambda, nlam, df, xlab,
ylab, ...)
## S3 method for class 'cv.trendfilter'
plot(x, legendpos = "top", xlab, ylab, ...)
Arguments
x
an object of the appropriate class ("genlasso" or anything class
inherits this for plot.genlasso, "trendfilter" for
plot.trendfilter, and "cv.trendfilter" for
plot.cv.trendfilter).
type
for plot.genlasso, a character string, one of "primal",
"dual", or "both", indicating which solution path system(s) should
be plotted. Default is "primal".
numbers
for plot.genlasso,
a logical variable indicating if coordinate paths should be labeled
by their numbers. Default is FALSE.
vlines
for plot.genlasso,
a logical variable indicating if dashed lines should be drawn at
knots in the path, with black lines for hitting events, and red
lines for leaving events. Default is TRUE.
style
for plot.trendfilter,
a character string, either "trend" or "path". If "trend", then trend
filtering coefficients are plotted according to their underlying
positions. If
"path", then a plot of the coordinate paths is produced with the
function plot.genlasso. Default is "trend".
lambda, nlam, df
for plot.trendfilter,
these arguments work exactly as they do in
coef.genlasso, and they are used to specify which
solutions should be extracted and plotted from the computed solution
path stored in x. The only difference is, if all three
are missing, then nlam is set to 10 (whereas in
coef.genlasso, the default is to set lambda equal to
the full set of knots along the solution path).
legendpos
for plot.cv.trendfilter, a character string indicating the
position of the legend. Default is "top".
xlab
an optional character string label for the x-axis.
ylab
an optional character string label for the y-axis.
...
additional arguments.
Value
For plot.trendfilter, with style set to "trend", a
coefficient object is silently returned as specified by lambda,
nlam, or df.
See Also
genlasso, trendfilter,
cv.trendfilter
Examples
# Constant trend filtering (the 1d fused lasso)
set.seed(0)
n = 100
beta0 = rep(sample(1:10,5),each=n/5)
y = beta0 + rnorm(n,sd=0.8)
a = fusedlasso1d(y)
cv = cv.trendfilter(a)
plot(a,style="path")
plot(cv)
plot(a,lambda=cv$lambda.1se)