visualize.loss: Plots grpnet Loss Function on Link or Response Scale

View source: R/visualize.loss.R

visualize.lossR Documentation

Plots grpnet Loss Function on Link or Response Scale

Description

Makes a plot or returns a data frame containing the specified loss function evaluated at a sequence of input values.

Usage

visualize.loss(x = seq(-3, 3, length.out = 1001),
               family = c("gaussian", "multigaussian",
                          "svm1", "svm2", "logit",
                          "binomial", "multinomial", 
                          "poisson", "negative.binomial", 
                          "Gamma", "inverse.gaussian"),
               theta = 1,
               type = c("link", "response"),
               y = NULL,
               plot = TRUE,
               add = FALSE,
               ...)

Arguments

x

sequence of linear predictor values at which to evaluate the loss.

family

Character specifying the assumed distribution for the response variable. Partial matching is allowed. See options below.

theta

For SVM1: additional ("smoothing") parameter, that controls the smoothing rate of the hinge loss function. For negative binomial: additional ("size") parameter, where the variance function is defined as V(\mu) = \mu + \mu^2/ \theta

type

Default of type = "link" plots x versus the loss. Change to type = "response" to plot mu versus the loss.

y

Response value used to compute loss. Note that the loss function is interpreted as a function of x given y.

plot

if TRUE (default), then the result is plotted; otherwise the result is returned as a data frame.

add

if FALSE (default), then the plot function is used to create a new graphic; otherwise the lines function is used to add lines to an existing graphic.

...

additional arguments passed to plot function, e.g., xlim, ylim, etc.

Details

grpnet implements the following loss functions:

gaussian/multigaussian

L = (y - \mu)^2

svm1

L = \left\{ \begin{array}{ll} \frac{1}{2\theta}(1 - \mu y)_{+}^2 & 1 - \theta < \mu y \\ 1 - \mu y - \theta / 2 & \mu y \leq 1 - \theta \end{array} \right.

svm2

L = (1 - \mu y)_{+}^2

logit

L = \log(1 + \exp(-\mu y))

binomial

L = -y\log(\mu) - (1-y) \log(1-\mu)

multinomial

L = -\sum_{l=1}^m I(y=l) \log(\mu_l)

poisson

L = \mu - y \log(\mu)

negative.binomial

L = (\theta + y) \log(\theta + \mu) - y \log(\mu) + c
where c = \log(\Gamma(\theta)) - \log(\Gamma(\theta + y)) - \theta \log(\theta)
is a constant with respect to \mu

Gamma

L = \log(\mu) + y / \mu

inverse.gaussian

L = (y - \mu)^2 / (\mu^2 y)

Value

If plot = TRUE, a plot is produced and nothing is returned.

If plot = FALSE, a data frame is returned with columns:

eta

linear predictor, i.e., fitted values on link scale (same as input x)

mu

expected value, i.e., fitted values on response scale (family$linkinv(x))

loss

loss function evaluation for given eta (and y)

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

References

Helwig, N. E. (2025). Versatile descent algorithms for group regularization and variable selection in generalized linear models. Journal of Computational and Graphical Statistics, 34(1), 239-252. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10618600.2024.2362232")}

See Also

visualize.penalty for plotting penalty function

visualize.shrink for plotting shrinkage operator

Examples

visualize.loss(family = "gaussian")

visualize.loss(family = "svm1", theta = 0.1)

visualize.loss(family = "svm2")

visualize.loss(family = "logit")

visualize.loss(family = "binomial")

visualize.loss(family = "poisson")

visualize.loss(family = "negative.binomial", theta = 10)

visualize.loss(family = "Gamma")

visualize.loss(family = "inverse.gaussian")

grpnet documentation built on June 10, 2025, 5:13 p.m.