View source: R/powerweighted_sf.R
| powerweighted_sf | R Documentation |
The function powerweighted_sf computes the power-weighted squared error scoring
function with parameter a, when y materialises and x is the
predictive \dfrac{\textnormal{E}_F [Y^{a + 1}]}{\textnormal{E}_F [Y^a]}
functional.
The power-weighted squared error scoring function is defined by eqs. (10) and
(11) in Gneiting (2011), applied to the weight function w(y) = y^a and to
the squared error scoring function.
powerweighted_sf(x, y, a)
x |
Predictive
|
y |
Realisation (true value) of process. It can be a vector of length
|
a |
It can be a vector of length |
The power-weighted squared error scoring function is defined by:
S(x, y, a) := y^a (x - y)^{2}
Domain of function:
x > 0
y > 0
a \in \mathbb{R}
Range of function:
S(x, y, a) \geq 0, \forall x, y > 0, a \in \mathbb{R}
Vector of power-weighted squared errors.
The \dfrac{\textnormal{E}_F [Y^{a + 1}]}{\textnormal{E}_F [Y^a]}
functional is the ratio of expectations formed by weighting the probability
distribution F of Y with w(y) = y^a (eq. (11) in
Gneiting 2011).
The power-weighted squared error scoring function is negatively oriented (i.e. the smaller, the better).
The power-weighted squared error scoring function is strictly
\mathbb{F}-consistent for the
\dfrac{\textnormal{E}_F [Y^{a + 1}]}{\textnormal{E}_F [Y^a]} functional
(Theorem 5 in Gneiting 2011). \mathbb{F} is the family of probability
distributions F for which \textnormal{E}_F[Y^a],
\textnormal{E}_F[Y^{a + 1}] and \textnormal{E}_F[Y^{a + 2}] exist
and are finite (Theorem 5 in Gneiting 2011).
At a = 0 the power-weighted squared error scoring function reduces to
serr_sf and the functional to the mean \textnormal{E}_F[Y], at
a = 1 it reduces to obsweighted_sf, and at a = -2 it reduces
to sperr_sf.
srelerr_sf targets the same functional as the case a = 1, but is
not a member of this family, because it weights with the prediction x
rather than with the realisation y (p. 752 in Gneiting 2011).
Gneiting T (2011) Making and evaluating point forecasts. Journal of the American Statistical Association 106(494):746–762. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1198/jasa.2011.r10138")}.
powerweighted_if
# Compute the power-weighted squared error scoring function.
df <- data.frame(
y = rep(x = 2, times = 6),
x = c(1, 2, 3, 1, 2, 3),
a = rep(x = c(1, -2), each = 3)
)
df$powerweighted_penalty <- powerweighted_sf(x = df$x, y = df$y, a = df$a)
print(df)
# The power-weighted squared error scoring function reduces to the squared
# error scoring function at a = 0, to the observation-weighted scoring function
# at a = 1 and to the squared percentage error scoring function at a = -2.
set.seed(12345)
n <- 10
x <- runif(n = n, min = 0, max = 2)
y <- runif(n = n, min = 0, max = 2)
max(abs(powerweighted_sf(x = x, y = y, a = 0) - serr_sf(x = x, y = y)))
max(abs(powerweighted_sf(x = x, y = y, a = 1) - obsweighted_sf(x = x, y = y)))
max(abs(powerweighted_sf(x = x, y = y, a = -2) - sperr_sf(x = x, y = y)))
# values are slightly higher than 0 due to rounding error
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.