coefpath: coefpath

View source: R/coefpath.r

coefpathR Documentation

coefpath

Description

Visualize the coefficient path resulting from the elastic net

Usage

coefpath(model, ...)

## S3 method for class 'glmnet'
coefpath(
  model,
  xlab = "Log Lambda",
  ylab = "Coefficients",
  showLegend = c("onmouseover", "auto", "always", "follow", "never"),
  annotate = TRUE,
  elementID = NULL,
  ...
)

## S3 method for class 'cv.glmnet'
coefpath(
  model,
  xlab = "Log Lambda",
  ylab = "Coefficients",
  showLegend = c("onmouseover", "auto", "always", "follow", "never"),
  annotate = TRUE,
  colorMin = "black",
  strokePatternMin = "dotted",
  labelMin = "lambda.min",
  locMin = c("bottom", "top"),
  color1se = "black",
  strokePattern1se = "dotted",
  label1se = "lambda.1se",
  loc1se = c("bottom", "top"),
  ...
)

Arguments

model

A glmnet model

...

Arguments passed on to extractPath

xlab

x-axis label

ylab

y-axis label

showLegend

When to display the legend. Specify "always" to always show the legend. Specify "onmouseover" to only display it when a user mouses over the chart. Specify "follow" to have the legend show as overlay to the chart which follows the mouse. The default behavior is "auto", which results in "always" when more than one series is plotted and "onmouseover" when only a single series is plotted.

annotate

If TRUE (default) plot the name of the series

elementID

Unique identified for dygraph, if NULL it will be randomly generated

colorMin

Color for line showing lambda.min

strokePatternMin

Stroke pattern for line showing lambda.min

labelMin

Label for line showing lambda.min

locMin

Location for line showing lambda.min, can be 'bottom' or 'top'

color1se

Color for line showing lambda.1se

strokePattern1se

Stroke pattern for line showing lambda.1se

label1se

Label for line showing lambda.1se

loc1se

Location for line showing lambda.1se, can be 'bottom' or 'top'

Details

This is a replacement plot for visualizing the coefficient path resulting from the elastic net. This allows for interactively inspecting the plot so it is easier to disambiguate the coefficients.

Value

A dygraphs object

Author(s)

Jared P. Lander

Examples



library(glmnet)
library(ggplot2)
library(useful)
data(diamonds)
diaX <- useful::build.x(price ~ carat + cut + x - 1, data=diamonds, contrasts = TRUE)
diaY <- useful::build.y(price ~ carat + cut + x - 1, data=diamonds)
modG1 <- glmnet(x=diaX, y=diaY)
coefpath(modG1)

modG2 <- cv.glmnet(x=diaX, y=diaY, nfolds=5)
coefpath(modG2)

x <- matrix(rnorm(100*20),100,20)
y <- rnorm(100)
fit1 <- glmnet(x, y)
coefpath(fit1)



coefplot documentation built on March 18, 2022, 7:58 p.m.