plot.par.w.elnet: Plot method for 'par.w.elnet' objects

View source: R/plot_par_welnet.R

plot.par.w.elnetR Documentation

Plot method for par.w.elnet objects

Description

A plot method to visualize the results of par_wElnet(): the weighted error curve across the lambda grid for each alpha, and/or a summary of the best (minimum) error achieved by each alpha, with the overall best (alpha, lambda) combination highlighted.

         For the single-alpha output of \code{\link{wElnet}} itself, see
         [plot.w.elnet()].

Usage

## S3 method for class 'par.w.elnet'
plot(
  x,
  type = c("both", "profile", "summary"),
  log.lambda = TRUE,
  legend.pos = "topright",
  palette = NULL,
  main.profile = NULL,
  xlab.profile = NULL,
  ylab.profile = NULL,
  main.summary = NULL,
  xlab.summary = NULL,
  ylab.summary = NULL,
  ...
)

Arguments

x

An object of class par.w.elnet, the output of par_wElnet().

type

A string indicating what to plot. One of:

  • "profile": error vs. log(lambda), one curve per alpha (base plot, similar in spirit to glmnet's own CV plot, but overlaying every alpha on a single panel so they can be compared directly).

  • "summary": minimum error achieved vs. alpha, one point per alpha, with the overall best alpha highlighted.

  • "both" (default): both plots side by side.

log.lambda

A logical value. If TRUE (default), the x-axis of the "profile" plot is log(lambda), matching glmnet convention. If FALSE, lambda is plotted on its original scale.

legend.pos

A string passed to legend() for the "profile" panel. Default is "topright". Set to NULL to suppress the legend (useful when there are many alphas and the legend gets crowded).

palette

A vector of colors to cycle through for the different alphas in the "profile" plot. Defaults to grDevices::hcl.colors(n, "Zissou 1"), where n is the number of alphas.

main.profile, xlab.profile, ylab.profile

Optional strings overriding the title and axis labels of the "profile" panel. If NULL (default), sensible defaults are used ("Error profile by alpha", "log(lambda)" or "lambda", and "Weighted error").

main.summary, xlab.summary, ylab.summary

Optional strings overriding the title and axis labels of the "summary" panel. If NULL (default), sensible defaults are used ("Best error by alpha", "alpha", and "Minimum weighted error").

...

Additional graphical parameters (e.g. col, pch, cex, lwd) passed to the underlying plot() calls. Do not pass main, xlab, or ylab here – use the dedicated arguments above instead.

Value

Invisibly returns x. Called for its side effect of producing a plot.

Examples


library(MLSurvey)
data(nhanes2013_sbc)
alpha <- c(0.000, 0.001, 0.008, 0.027, 0.064, 0.125, 0.216, 0.343, 0.512, 0.729, 1.000)

en.par <- par_wElnet(alpha = alpha,
                      data = nhanes2013_sbc,
                      col.y = "HBP", col.x = 2:61,
                      family = "binomial",
                      cluster = "SDMVPSU", strata = "SDMVSTRA", weights = "WTSAF2YR",
                      method = "dCV", k = 10, R = 20)

plot(en.par)                    # both panels
plot(en.par, type = "profile")  # just the error-vs-lambda curves
plot(en.par, type = "summary")  # just the best-error-vs-alpha curve
plot(en.par, type = "profile", main.profile = "My custom title", xlab.profile = "Penalty")



MLSurvey documentation built on Nov. 18, 2026, 5:11 p.m.