Learn R Programming

scoringfunctions (version 1.2)

powerweighted_sf: Power-weighted squared error scoring function

Description

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.

Usage

powerweighted_sf(x, y, a)

Value

Vector of power-weighted squared errors.

Arguments

x

Predictive \(\dfrac{\textnormal{E}_F [Y^{a + 1}]}{\textnormal{E}_F [Y^a]}\) functional (prediction). It can be a vector of length \(n\) (must have the same length as \(y\)).

y

Realisation (true value) of process. It can be a vector of length \(n\) (must have the same length as \(x\)).

a

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

Details

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}$$

References

Gneiting T (2011) Making and evaluating point forecasts. Journal of the American Statistical Association 106(494):746--762. tools:::Rd_expr_doi("10.1198/jasa.2011.r10138").

See Also

powerweighted_if

Examples

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

Run the code above in your browser using DataLab