# 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