Learn R Programming

scoringfunctions (version 1.1)

capping_function: 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)

Value

Vector of values of the capping function.

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\{ \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 \geq 0$$

$$b \geq 0$$

References

Taggart RJ (2022) Point forecasting and forecast evaluation with generalized Huber loss. Electronic Journal of Statistics 16:201--231. tools:::Rd_expr_doi("10.1214/21-EJS1957").

Examples

Run this code
# 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)

Run the code above in your browser using DataLab