capping_function: Capping function

View source: R/capping_function.R

capping_functionR Documentation

Capping function

Description

The function capping_function computes the value of the capping function, defined in Taggart (2022), p.205.

It is used by the generalized Huber loss function among others (see Taggart 2022).

Usage

capping_function(t, a, b)

Arguments

t

It can be a vector of length n.

a

It can be a vector of length n (must have the same length as t).

b

It can be a vector of length n (must have the same length as t).

Details

The capping function \kappa_{a, b}(t) is defined by:

\kappa_{a, b}(t) := \max \lbrace \min \lbrace t, b \rbrace, -a \rbrace

or equivalently,

\kappa_{a, b}(t) := \left\lbrace \begin{array}{ll} -a, & t \leq -a\\ t, & -a < t \leq b\\ b, & t > b \end{array} \right.

Domain of function:

t \in \mathbb{R}

a \in [0, \infty]

b \in [0, \infty]

Range of function:

-a \leq \kappa_{a, b}(t) \leq b, \forall t \in \mathbb{R}, a, b \in [0, \infty]

Value

Vector of values of the capping function.

Note

For the definition of the capping function, see Taggart (2022), p.205.

Taggart (2022), p.205 admits the endpoints a = \infty and b = \infty, at which the corresponding cap is removed; the examples below include those cases.

References

Taggart RJ (2022) Point forecasting and forecast evaluation with generalized Huber loss. Electronic Journal of Statistics 16(1):201–231. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/21-EJS1957")}.

See Also

ghuber_sf, huber_sf

Examples

# Compute the capping function.

df <- data.frame(
    t = c(1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 2.5, 2.5, 3.5, 3.5),
    a = c(0, 0, 0, 0, Inf, Inf, Inf, Inf, 2, 3, 2, 3, 2, 3),
    b = c(0, 0, Inf, Inf, 0, 0, Inf, Inf, 3, 2, 3, 2, 3, 2)
)

df$cf <- capping_function(t = df$t, a = df$a, b = df$b)

print(df)

scoringfunctions documentation built on Aug. 30, 2026, 5:07 p.m.