
coefpath
coefpath.RdVisualize the coefficient path resulting from the elastic net
Usage
coefpath(model, ...)
# S3 method for glmnet
coefpath(
model,
xlab = "Log Lambda",
ylab = "Coefficients",
showLegend = c("onmouseover", "auto", "always", "follow", "never"),
annotate = TRUE,
elementID = NULL,
...
)
# S3 method for 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
glmnetmodel- ...
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
NULLit 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.
Examples
if(requireNamespace('glmnet', quietly=TRUE)){
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)
}
#> Loading required package: Matrix
#> Loaded glmnet 4.1-8