View source: R/capping_function.R
| capping_function | R Documentation |
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).
capping_function(t, a, b)
t |
It can be a vector of length |
a |
It can be a vector of length |
b |
It can be a vector of length |
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]
Vector of values of the capping function.
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.
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")}.
ghuber_sf, huber_sf
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.