View source: R/weighted_interval_score.R
weighted_interval_score | R Documentation |
Weighted interval score (WIS), a well-known quantile-based approximation of the commonly-used continuous ranked probability score (CRPS). WIS is a proper score, and can be thought of as a distributional generalization of absolute error. For example, see Bracher et al. (2020) for discussion in the context of COVID-19 forecasting.
weighted_interval_score(
x,
actual,
quantile_levels = NULL,
na_handling = c("impute", "drop", "propagate", "fail"),
...
)
x |
A vector of class |
actual |
double. Actual value(s) |
quantile_levels |
probabilities. If specified, the score will be
computed at this set of levels. Otherwise, those present in |
na_handling |
character. Determines missing values are handled.
For |
... |
not used |
a vector of nonnegative scores.
quantile_levels <- c(.2, .4, .6, .8)
predq1 <- 1:4 #
predq2 <- 8:11
dstn <- quantile_pred(rbind(predq1, predq2), quantile_levels)
actual <- c(3.3, 7.1)
weighted_interval_score(dstn, actual)
weighted_interval_score(dstn, actual, c(.25, .5, .75))
# Missing value behaviours
dstn <- quantile_pred(matrix(c(1, 2, NA, 4), nrow = 1), 1:4 / 5)
weighted_interval_score(dstn, 2.5)
weighted_interval_score(dstn, 2.5, 1:9 / 10)
weighted_interval_score(dstn, 2.5, 1:9 / 10, na_handling = "drop")
weighted_interval_score(dstn, 2.5, na_handling = "propagate")
weighted_interval_score(
quantile_pred(matrix(1:4, nrow = 1), 1:4 / 5),
actual = 2.5,
quantile_levels = 1:9 / 10,
na_handling = "fail"
)
# Using some actual forecasts --------
library(dplyr)
training <- covid_case_death_rates %>%
filter(time_value >= "2021-10-01", time_value <= "2021-12-01")
preds <- flatline_forecaster(
training, "death_rate",
flatline_args_list(quantile_levels = c(.01, .025, 1:19 / 20, .975, .99))
)$predictions
actuals <- covid_case_death_rates %>%
filter(time_value == as.Date("2021-12-01") + 7) %>%
select(geo_value, time_value, actual = death_rate)
preds <- left_join(preds, actuals,
by = c("target_date" = "time_value", "geo_value")
) %>%
mutate(wis = weighted_interval_score(.pred_distn, actual))
preds
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.