plotmo (version 3.6.0)

plot_glmnet: Plot a glmnet model

Description

Plot the coefficient paths of a glmnet model.

An enhanced version of plot.glmnet.

Usage

plot_glmnet(x = stop("no 'x' argument"),
           xvar = c("rlambda", "lambda", "norm", "dev"),
           label = 10, nresponse = NA, grid.col = NA, s = NA, ...)

Arguments

x

The glmnet model.

xvar

What gets plotted along the x axis. One of: "rlambda" (default) decreasing log lambda (lambda is the glmnet penalty) "lambda" log lambda "norm" L1-norm of the coefficients "dev" percent deviance explained The default xvar differs from plot.glmnet to allow s to be plotted when this function is invoked by plotres.

label

Default 10. Number of variable names displayed on the right of the plot. One of: FALSE display no variables TRUE display all variables integer (default) number of variables to display (default is 10)

nresponse

Which response to plot for multiple response models.

grid.col

Default NA. Color of the optional grid, for example grid.col="lightgray".

s

For use by plotres. The x position of the gray vertical line indicating the lambda s passed by plotres to predict.glmnet to calculate the residuals. Plotres defaults to s=0.

Dot arguments are passed internally to matplot.

Use col to change the color of curves; for example col=1:4. The six default colors are intended to be distinguishable yet harmonious (to my eye at least), with adjacent colors as different as easily possible.

See Also

Chapter 6 in plotres vignette discusses this function.

Examples

# NOT RUN {
if (require(glmnet)) {
    x <- matrix(rnorm(100 * 10), 100, 10)   # n=100 p=10
    y <- x[,1] + x[,2] + 2 * rnorm(100)     # y depends only on x[,1] and x[,2]
    mod <- glmnet(x, y)

    plot_glmnet(mod)

    # plotres(mod)                          # plot the residuals
}
# }