From 263c85ce4797c41ecc54421584e4c3f151e8d9df Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 2 Nov 2023 16:29:56 +0100 Subject: [PATCH 01/81] Create a function that calculates the WIS based on a quantile format (no separate results yet) --- NAMESPACE | 1 + R/metrics-quantile.R | 48 +++++++++-- man/wis.Rd | 19 +++++ tests/testthat/test-interval_score.R | 114 ++++++++++++++++++++------- 4 files changed, 148 insertions(+), 34 deletions(-) create mode 100644 man/wis.Rd diff --git a/NAMESPACE b/NAMESPACE index 67415dbe9..dcdb31328 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -65,6 +65,7 @@ export(theme_scoringutils) export(transform_forecasts) export(validate) export(validate_general) +export(wis) importFrom(Metrics,ae) importFrom(Metrics,ape) importFrom(Metrics,se) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index c9e3afb42..1d6c5d35d 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -1,3 +1,41 @@ +#' Weighted Interval Score +#' @export +wis <- function(observed, + predicted, + quantile, + separate_results = FALSE, + weigh = TRUE, + count_median_twice = FALSE, + na.rm = TRUE) { + + assert_input_quantile(observed, predicted, quantile) + reformatted <- quantile_to_interval(observed, predicted, quantile) + + reformatted[, wis := interval_score(observed = observed, + lower = lower, + upper = upper, + interval_range = range, + weigh = weigh, + separate_results = separate_results)] + + if (!count_median_twice) { + reformatted[, weight := ifelse(range == 0, 0.5, 1)] + } else { + reformatted[, weight := 1] + } + + # summarise results by forecast_id + if (!separate_results) { + reformatted <- reformatted[, .(wis = weighted.mean( + x = wis, w = weight) + ), by = forecast_id] + } + + return(reformatted$wis) +} + + + #' @title Quantile Score #' #' @description @@ -43,17 +81,11 @@ #' Evaluating epidemic forecasts in an interval format, #' Johannes Bracher, Evan L. Ray, Tilmann Gneiting and Nicholas G. Reich, #' -# - quantile_score <- function(observed, predicted, quantile, weigh = TRUE) { - # get central prediction interval which corresponds to given quantiles - central_interval <- abs(0.5 - quantile) * 2 - alpha <- 1 - central_interval - # compute score - this is the version explained in the SI of Bracher et. al. error <- abs(predicted - observed) score <- 2 * ifelse( @@ -62,8 +94,12 @@ quantile_score <- function(observed, # adapt score such that mean of unweighted quantile scores corresponds to # unweighted interval score of the corresponding prediction interval + # --> needs central prediction interval which corresponds to given quantiles + central_interval <- abs(0.5 - quantile) * 2 + alpha <- 1 - central_interval score <- 2 * score / alpha + # if weigh, then reverse last operation if (weigh) { score <- score * alpha / 2 } diff --git a/man/wis.Rd b/man/wis.Rd new file mode 100644 index 000000000..e2d678caa --- /dev/null +++ b/man/wis.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics-quantile.R +\name{wis} +\alias{wis} +\title{Weighted Interval Score} +\usage{ +wis( + observed, + predicted, + quantile, + separate_results = FALSE, + weigh = TRUE, + count_median_twice = FALSE, + na.rm = TRUE +) +} +\description{ +Weighted Interval Score +} diff --git a/tests/testthat/test-interval_score.R b/tests/testthat/test-interval_score.R index 5f156334b..e075db9fc 100644 --- a/tests/testthat/test-interval_score.R +++ b/tests/testthat/test-interval_score.R @@ -1,6 +1,6 @@ test_that("wis works, median only", { y <- c(1, -15, 22) - lower <- upper <- c(1, 2, 3) + lower <- upper <- predicted_quantile <- c(1, 2, 3) quantile_probs <- 0.5 actual <- interval_score(y, @@ -8,6 +8,13 @@ test_that("wis works, median only", { weigh = TRUE, interval_range = 0 ) + + actual_wis <- wis( + observed = y, + predicted = matrix(predicted_quantile), + quantile = quantile_probs, + ) + expected <- abs(y - lower) expect_identical(actual, expected) @@ -32,17 +39,26 @@ test_that("wis works, 1 interval only", { lower <- c(0, 1, 0) upper <- c(2, 2, 3) quantile_probs <- c(0.25, 0.75) + predicted <- matrix(c(lower, upper), ncol = 2) alpha <- 0.5 + expected <- (upper - lower) * (alpha / 2) + c(0, 1 - (-15), 22 - 3) - actual <- scoringutils::interval_score(y, + actual <- interval_score( + y, lower = lower, upper = upper, weigh = TRUE, interval_range = 50 ) - expected <- (upper - lower) * (alpha / 2) + c(0, 1 - (-15), 22 - 3) + + actual_wis <- wis( + observed = y, + predicted = predicted, + quantile = quantile_probs, + ) expect_identical(actual, expected) + expect_identical(actual_wis, expected) }) test_that("WIS works within score for one interval", { @@ -89,15 +105,31 @@ test_that("wis works, 1 interval and median", { quantile_probs <- c(0.25, 0.5, 0.75) alpha <- 0.5 - expected <- 0.5 * ( abs(y - quantile[, 2]) + (quantile[, 3] - quantile[, 1]) * (alpha / 2) + c(0, 1 - (-15), 22 - 3) ) + actual_wis <- wis( + observed = y, + predicted = quantile, + quantile = quantile_probs, + count_median_twice = TRUE + ) + expect_identical(eval$interval_score, expected) + expect_identical(actual_wis, expected) }) +# covidHubUtils test: +y <- c(1, -15, 22) +forecast_quantiles_matrix <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) + test_that("wis works, 2 intervals and median", { test_data <- data.frame( observed = rep(c(1, -15, 22), times = 5), @@ -116,8 +148,7 @@ test_that("wis works, 2 intervals and median", { eval <- summarise_scores(eval, by = c("model", "date")) - y <- c(1, -15, 22) - quantile <- rbind(c(-1, 0, 1, 2, 3), c(-2, 1, 2, 2, 4), c(-2, 0, 3, 3, 4)) + quantile <- forecast_quantiles_matrix quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) alpha1 <- 0.2 @@ -129,21 +160,22 @@ test_that("wis works, 2 intervals and median", { (quantile[, 4] - quantile[, 2]) * (alpha2 / 2) + c(0, 1 - (-15), 22 - 3) ) + actual_wis <- wis( + observed = y, + predicted = quantile, + quantile = quantile_probs, + count_median_twice = TRUE + ) + expect_equal( as.numeric(eval$interval_score), as.numeric(expected) ) + expect_identical(actual_wis, expected) }) # additional tests from the covidhubutils repo test_that("wis is correct, median only - test corresponds to covidHubUtils", { - y <- c(1, -15, 22) - forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) - ) - forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) forecast_quantiles_matrix <- forecast_quantiles_matrix[, 3, drop = FALSE] forecast_quantile_probs <- forecast_quantile_probs[3] @@ -202,18 +234,19 @@ test_that("wis is correct, median only - test corresponds to covidHubUtils", { expected <- abs(y - forecast_quantiles_matrix[, 1]) + actual_wis <- wis( + observed = y, + predicted = matrix(forecast_quantiles_matrix), + quantile = 0.5, + count_median_twice = FALSE + ) + expect_equal(eval$interval_score, expected) + expect_equal(actual_wis, expected) }) test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", { - y <- c(1, -15, 22) - forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) - ) - forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) forecast_quantiles_matrix <- forecast_quantiles_matrix[, c(1, 5), drop = FALSE] forecast_quantile_probs <- forecast_quantile_probs[c(1, 5)] @@ -281,19 +314,19 @@ test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", expected <- (forecast_quantiles_matrix[, 2] - forecast_quantiles_matrix[, 1]) * (alpha1 / 2) + c(0, (-2) - (-15), 22 - 4) + actual_wis <- wis( + observed = y, + predicted = forecast_quantiles_matrix, + quantile = c(0.1, 0.9), + count_median_twice = FALSE + ) + expect_equal(eval$interval_score, expected) + expect_equal(actual_wis, expected) }) test_that("wis is correct, 2 intervals and median - test corresponds to covidHubUtils", { - y <- c(1, -15, 22) - forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) - ) - forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) - target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) horizons <- c("1", "2", "1") locations <- c("01", "01", "02") @@ -362,6 +395,13 @@ test_that("wis is correct, 2 intervals and median - test corresponds to covidHub (forecast_quantiles_matrix[, 4] - forecast_quantiles_matrix[, 2]) * (alpha2 / 2) + c(0, 1 - (-15), 22 - 3) ) + actual_wis <- wis( + observed = y, + predicted = forecast_quantiles_matrix, + quantile = c(0.1, 0.25, 0.5, 0.75, 0.9), + count_median_twice = FALSE + ) + expect_equal(eval$interval_score, expected) }) @@ -382,6 +422,14 @@ test_that("Quantlie score and interval score yield the same result, weigh = FALS weigh = w ) + wis <- wis( + observed = observed, + predicted = cbind(lower, upper), + quantile = c(alpha / 2, 1 - alpha / 2), + count_median_twice = FALSE, + weigh = w + ) + qs_lower <- quantile_score(observed, predicted = lower, quantile = alpha / 2, @@ -393,6 +441,7 @@ test_that("Quantlie score and interval score yield the same result, weigh = FALS weigh = w ) expect_equal((qs_lower + qs_upper) / 2, is) + expect_equal(wis, is) } }) @@ -413,6 +462,14 @@ test_that("Quantlie score and interval score yield the same result, weigh = TRUE weigh = w ) + wis <- wis( + observed = observed, + predicted = cbind(lower, upper), + quantile = c(alpha / 2, 1 - alpha / 2), + count_median_twice = FALSE, + weigh = w + ) + qs_lower <- quantile_score(observed, predicted = lower, quantile = alpha / 2, @@ -424,5 +481,6 @@ test_that("Quantlie score and interval score yield the same result, weigh = TRUE weigh = w ) expect_equal((qs_lower + qs_upper) / 2, is) + expect_equal(wis, is) } }) From 2d06ef70476604801ddde335629fa5208dde5060 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 2 Nov 2023 17:30:00 +0100 Subject: [PATCH 02/81] fix warnings / messages by updating documentation --- NAMESPACE | 1 + R/metrics-quantile.R | 49 +++++++++++++++++++++------- R/z_globalVariables.R | 1 + man/wis.Rd | 22 +++++++++++++ tests/testthat/test-interval_score.R | 11 +++++++ 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index dcdb31328..f1235f87b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -158,5 +158,6 @@ importFrom(stats,rbinom) importFrom(stats,reorder) importFrom(stats,runif) importFrom(stats,sd) +importFrom(stats,weighted.mean) importFrom(stats,wilcox.test) importFrom(utils,combn) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 1d6c5d35d..1bdf844fb 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -1,4 +1,10 @@ #' Weighted Interval Score +#' @inheritParams interval_score +#' @param predicted vector of size n with the predicted values +#' @param quantile vector with quantile levels of size N +#' @param count_median_twice if TRUE, count the median twice in the score +#' @param na.rm if TRUE, ignore NA values when computing the score +#' @importFrom stats weighted.mean #' @export wis <- function(observed, predicted, @@ -11,12 +17,22 @@ wis <- function(observed, assert_input_quantile(observed, predicted, quantile) reformatted <- quantile_to_interval(observed, predicted, quantile) - reformatted[, wis := interval_score(observed = observed, - lower = lower, - upper = upper, - interval_range = range, - weigh = weigh, - separate_results = separate_results)] + if (separate_results) { + cols <- c("wis", "dispersion", "underprediction", "overprediction") + } else { + cols <- "wis" + } + + reformatted[, eval(cols) := do.call( + interval_score, + list(observed = observed, + lower = lower, + upper = upper, + interval_range = range, + weigh = weigh, + separate_results = separate_results + ) + )] if (!count_median_twice) { reformatted[, weight := ifelse(range == 0, 0.5, 1)] @@ -25,13 +41,22 @@ wis <- function(observed, } # summarise results by forecast_id - if (!separate_results) { - reformatted <- reformatted[, .(wis = weighted.mean( - x = wis, w = weight) - ), by = forecast_id] - } + reformatted <- reformatted[ + , lapply(.SD, weighted.mean, na.rm = na.rm, w = weight), + by = c("forecast_id"), + .SDcols = colnames(reformatted) %like% paste(cols, collapse = "|") + ] - return(reformatted$wis) + if (separate_results) { + return(list( + wis = reformatted$wis, + dispersion = reformatted$dispersion, + underprediction = reformatted$underprediction, + overprediction = reformatted$overprediction + )) + } else { + return(reformatted$wis) + } } diff --git a/R/z_globalVariables.R b/R/z_globalVariables.R index 3f5591611..b81fb3452 100644 --- a/R/z_globalVariables.R +++ b/R/z_globalVariables.R @@ -71,6 +71,7 @@ globalVariables(c( "value_scaled", "var_of_interest", "variable", + "weight", "wis_component_name", "x", "y", diff --git a/man/wis.Rd b/man/wis.Rd index e2d678caa..fbf8bc6f7 100644 --- a/man/wis.Rd +++ b/man/wis.Rd @@ -14,6 +14,28 @@ wis( na.rm = TRUE ) } +\arguments{ +\item{observed}{A vector with observed values of size n} + +\item{predicted}{vector of size n with the predicted values} + +\item{quantile}{vector with quantile levels of size N} + +\item{separate_results}{if \code{TRUE} (default is \code{FALSE}), then the separate +parts of the interval score (dispersion penalty, penalties for over- and +under-prediction get returned as separate elements of a list). If you want a +\code{data.frame} instead, simply call \code{\link[=as.data.frame]{as.data.frame()}} on the output.} + +\item{weigh}{if TRUE, weigh the score by alpha / 2, so it can be averaged +into an interval score that, in the limit, corresponds to CRPS. Alpha is the +decimal value that represents how much is outside a central prediction +interval (e.g. for a 90 percent central prediction interval, alpha is 0.1) +Default: \code{TRUE}.} + +\item{count_median_twice}{if TRUE, count the median twice in the score} + +\item{na.rm}{if TRUE, ignore NA values when computing the score} +} \description{ Weighted Interval Score } diff --git a/tests/testthat/test-interval_score.R b/tests/testthat/test-interval_score.R index e075db9fc..4a69c7539 100644 --- a/tests/testthat/test-interval_score.R +++ b/tests/testthat/test-interval_score.R @@ -484,3 +484,14 @@ test_that("Quantlie score and interval score yield the same result, weigh = TRUE expect_equal(wis, is) } }) + +test_that("wis works with separate results", { + wis <- wis( + observed = y, + predicted = forecast_quantiles_matrix, + quantile = forecast_quantile_probs, + separate_results = TRUE + ) + expect_equal(wis$wis, wis$dispersion + wis$overprediction + wis$underprediction) +}) + From 2a1beea72f5382116d5478caccb6545ee15cae93 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 17:41:40 +0100 Subject: [PATCH 03/81] Regroup files to distinguish metrics with a one-to-one and a many-to-one relationship --- R/metrics-quantile.R | 252 ++++++++++++++++++++++--------------------- R/metrics-range.R | 7 ++ 2 files changed, 136 insertions(+), 123 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 1bdf844fb..a15822989 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -1,3 +1,7 @@ +################################################################################ +# Metrics with a many-to-one relationship between input and score +################################################################################ + #' Weighted Interval Score #' @inheritParams interval_score #' @param predicted vector of size n with the predicted values @@ -13,7 +17,6 @@ wis <- function(observed, weigh = TRUE, count_median_twice = FALSE, na.rm = TRUE) { - assert_input_quantile(observed, predicted, quantile) reformatted <- quantile_to_interval(observed, predicted, quantile) @@ -60,128 +63,6 @@ wis <- function(observed, } - -#' @title Quantile Score -#' -#' @description -#' Proper Scoring Rule to score quantile predictions. Smaller values are better. -#' The quantile score is -#' closely related to the Interval score (see [interval_score()]) and is -#' the quantile equivalent that works with single quantiles instead of -#' central prediction intervals. -#' -#' @param quantile vector of size n with the quantile levels of the -#' corresponding predictions. -#' @param weigh if TRUE, weigh the score by alpha / 2, so it can be averaged -#' into an interval score that, in the limit, corresponds to CRPS. Alpha is the -#' value that corresponds to the (alpha/2) or (1 - alpha/2) quantiles provided -#' and will be computed from the quantile. Alpha is the decimal value that -#' represents how much is outside a central prediction interval (E.g. for a -#' 90 percent central prediction interval, alpha is 0.1). Default: `TRUE`. -#' @return vector with the scoring values -#' @inheritParams interval_score -#' @inheritParams ae_median_sample -#' @examples -#' observed <- rnorm(10, mean = 1:10) -#' alpha <- 0.5 -#' -#' lower <- qnorm(alpha / 2, rnorm(10, mean = 1:10)) -#' upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 1:10)) -#' -#' qs_lower <- quantile_score(observed, -#' predicted = lower, -#' quantile = alpha / 2 -#' ) -#' qs_upper <- quantile_score(observed, -#' predicted = upper, -#' quantile = 1 - alpha / 2 -#' ) -#' interval_score <- (qs_lower + qs_upper) / 2 -#' @export -#' @keywords metric -#' @references Strictly Proper Scoring Rules, Prediction,and Estimation, -#' Tilmann Gneiting and Adrian E. Raftery, 2007, Journal of the American -#' Statistical Association, Volume 102, 2007 - Issue 477 -#' -#' Evaluating epidemic forecasts in an interval format, -#' Johannes Bracher, Evan L. Ray, Tilmann Gneiting and Nicholas G. Reich, -#' -quantile_score <- function(observed, - predicted, - quantile, - weigh = TRUE) { - - # compute score - this is the version explained in the SI of Bracher et. al. - error <- abs(predicted - observed) - score <- 2 * ifelse( - observed <= predicted, 1 - quantile, quantile - ) * error - - # adapt score such that mean of unweighted quantile scores corresponds to - # unweighted interval score of the corresponding prediction interval - # --> needs central prediction interval which corresponds to given quantiles - central_interval <- abs(0.5 - quantile) * 2 - alpha <- 1 - central_interval - score <- 2 * score / alpha - - # if weigh, then reverse last operation - if (weigh) { - score <- score * alpha / 2 - } - - return(score) -} - - -#' @title Absolute Error of the Median (Quantile-based Version) -#' -#' @description -#' Absolute error of the median calculated as -#' -#' \deqn{ -#' \textrm{abs}(\textrm{observed} - \textrm{prediction}) -#' }{ -#' abs(observed - median_prediction) -#' } -#' -#' The function was created for internal use within [score()], but can also -#' used as a standalone function. -#' -#' @param predicted numeric vector with predictions, corresponding to the -#' quantiles in a second vector, `quantiles`. -#' @param quantiles numeric vector that denotes the quantile for the values -#' in `predicted`. Only those predictions where `quantiles == 0.5` will -#' be kept. If `quantiles` is `NULL`, then all `predicted` and -#' `observed` will be used (this is then the same as [abs_error()]) -#' @return vector with the scoring values -#' @seealso [ae_median_sample()], [abs_error()] -#' @importFrom stats median -#' @inheritParams ae_median_sample -#' @examples -#' observed <- rnorm(30, mean = 1:30) -#' predicted_values <- rnorm(30, mean = 1:30) -#' ae_median_quantile(observed, predicted_values, quantiles = 0.5) -#' @export -#' @keywords metric - -ae_median_quantile <- function(observed, predicted, quantiles = NULL) { - if (!is.null(quantiles)) { - if (!any(quantiles == 0.5) && !anyNA(quantiles)) { - return(NA_real_) - warning( - "in order to compute the absolute error of the median, `0.5` must be ", - "among the quantiles given. Maybe you want to use `abs_error()`?" - ) - } - observed <- observed[quantiles == 0.5] - predicted <- predicted[quantiles == 0.5] - } - abs_error_median <- abs(observed - predicted) - return(abs_error_median) -} - - - #' @title Determines Bias of Quantile Forecasts #' #' @description @@ -303,3 +184,128 @@ bias_quantile <- function(observed, predicted, quantile) { } return(bias) } + + +################################################################################ +# Metrics with a one-to-one relationship between input and score +################################################################################ + + +#' @title Quantile Score +#' +#' @description +#' Proper Scoring Rule to score quantile predictions. Smaller values are better. +#' The quantile score is +#' closely related to the Interval score (see [interval_score()]) and is +#' the quantile equivalent that works with single quantiles instead of +#' central prediction intervals. +#' +#' @param quantile vector of size n with the quantile levels of the +#' corresponding predictions. +#' @param weigh if TRUE, weigh the score by alpha / 2, so it can be averaged +#' into an interval score that, in the limit, corresponds to CRPS. Alpha is the +#' value that corresponds to the (alpha/2) or (1 - alpha/2) quantiles provided +#' and will be computed from the quantile. Alpha is the decimal value that +#' represents how much is outside a central prediction interval (E.g. for a +#' 90 percent central prediction interval, alpha is 0.1). Default: `TRUE`. +#' @return vector with the scoring values +#' @inheritParams interval_score +#' @inheritParams ae_median_sample +#' @examples +#' observed <- rnorm(10, mean = 1:10) +#' alpha <- 0.5 +#' +#' lower <- qnorm(alpha / 2, rnorm(10, mean = 1:10)) +#' upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 1:10)) +#' +#' qs_lower <- quantile_score(observed, +#' predicted = lower, +#' quantile = alpha / 2 +#' ) +#' qs_upper <- quantile_score(observed, +#' predicted = upper, +#' quantile = 1 - alpha / 2 +#' ) +#' interval_score <- (qs_lower + qs_upper) / 2 +#' @export +#' @keywords metric +#' @references Strictly Proper Scoring Rules, Prediction,and Estimation, +#' Tilmann Gneiting and Adrian E. Raftery, 2007, Journal of the American +#' Statistical Association, Volume 102, 2007 - Issue 477 +#' +#' Evaluating epidemic forecasts in an interval format, +#' Johannes Bracher, Evan L. Ray, Tilmann Gneiting and Nicholas G. Reich, +#' +quantile_score <- function(observed, + predicted, + quantile, + weigh = TRUE) { + + # compute score - this is the version explained in the SI of Bracher et. al. + error <- abs(predicted - observed) + score <- 2 * ifelse( + observed <= predicted, 1 - quantile, quantile + ) * error + + # adapt score such that mean of unweighted quantile scores corresponds to + # unweighted interval score of the corresponding prediction interval + # --> needs central prediction interval which corresponds to given quantiles + central_interval <- abs(0.5 - quantile) * 2 + alpha <- 1 - central_interval + score <- 2 * score / alpha + + # if weigh, then reverse last operation + if (weigh) { + score <- score * alpha / 2 + } + + return(score) +} + + +#' @title Absolute Error of the Median (Quantile-based Version) +#' +#' @description +#' Absolute error of the median calculated as +#' +#' \deqn{ +#' \textrm{abs}(\textrm{observed} - \textrm{prediction}) +#' }{ +#' abs(observed - median_prediction) +#' } +#' +#' The function was created for internal use within [score()], but can also +#' used as a standalone function. +#' +#' @param predicted numeric vector with predictions, corresponding to the +#' quantiles in a second vector, `quantiles`. +#' @param quantiles numeric vector that denotes the quantile for the values +#' in `predicted`. Only those predictions where `quantiles == 0.5` will +#' be kept. If `quantiles` is `NULL`, then all `predicted` and +#' `observed` will be used (this is then the same as [abs_error()]) +#' @return vector with the scoring values +#' @seealso [ae_median_sample()], [abs_error()] +#' @importFrom stats median +#' @inheritParams ae_median_sample +#' @examples +#' observed <- rnorm(30, mean = 1:30) +#' predicted_values <- rnorm(30, mean = 1:30) +#' ae_median_quantile(observed, predicted_values, quantiles = 0.5) +#' @export +#' @keywords metric + +ae_median_quantile <- function(observed, predicted, quantiles = NULL) { + if (!is.null(quantiles)) { + if (!any(quantiles == 0.5) && !anyNA(quantiles)) { + return(NA_real_) + warning( + "in order to compute the absolute error of the median, `0.5` must be ", + "among the quantiles given. Maybe you want to use `abs_error()`?" + ) + } + observed <- observed[quantiles == 0.5] + predicted <- predicted[quantiles == 0.5] + } + abs_error_median <- abs(observed - predicted) + return(abs_error_median) +} diff --git a/R/metrics-range.R b/R/metrics-range.R index fe8f54cab..6c25a878d 100644 --- a/R/metrics-range.R +++ b/R/metrics-range.R @@ -1,3 +1,7 @@ +################################################################################ +# Metrics with a one-to-one relationship between input and score +################################################################################ + #' @title Interval Score #' #' @description @@ -154,6 +158,9 @@ interval_score <- function(observed, } +################################################################################ +# Metrics with a many-to-one relationship between input and score +################################################################################ #' @title Determines Bias of Quantile Forecasts based on the range of the #' prediction intervals From b8845eaa23b5ccffa27a6fd4406bb3f2d8f1fb6c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 17:52:58 +0100 Subject: [PATCH 04/81] Create a function that computes the wis with a one-to-one relationship. Function is horribly named and we need to decide what to do with it --- R/metrics-quantile.R | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index a15822989..92b2a2528 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -263,6 +263,96 @@ quantile_score <- function(observed, } +# Weighted Interval Score, But With One-to-One Relationship +wis_one_to_one <- function(observed, + predicted, + quantile, + separate_results = FALSE, + output = c("matrix", "data.frame", "vector"), + weigh = TRUE) { + + # input checks + assert_input_quantile(observed, predicted, quantile) + + # store original data + n <- length(observed) + N <- length(quantile) + original_data <- data.table( + forecast_id = rep(1:n, each = N), + observed = rep(observed, each = N), + predicted = as.vector(t(predicted)), + quantile = quantile + ) + + # define output columns + if (separate_results) { + cols <- c("wis", "dispersion", "underprediction", "overprediction") + } else { + cols <- "wis" + } + + # reformat input to interval format and calculate interval score + reformatted <- quantile_to_interval(observed, predicted, quantile) + reformatted[, eval(cols) := do.call( + interval_score, + list(observed = observed, + lower = lower, + upper = upper, + interval_range = range, + weigh = weigh, + separate_results = separate_results + ) + )] + + # melt data to long format, calclate quantiles, and merge back to original + long <- melt(reformatted, + measure.vars = c("lower", "upper"), + variable.name = "boundary", + value.name = "predicted", + id.vars = c("forecast_id", "observed", "range", cols)) + # calculate quantiles + long[, quantile := (100 - range) / 200] # lower quantiles + long[boundary == "upper", quantile := 1 - quantile] # upper quantiles + # remove boundary, range, take unique value to get rid of duplicated median + long[, c("boundary", "range") := NULL] + long <- unique(long) # should maybe check for count_median_twice? + out <- merge( + original_data, long, all.x = TRUE, + by = c("forecast_id", "observed", "predicted", "quantile") + )[, forecast_id := NULL] + + # handle returns depending on the output format + if (output == "data.frame") { + return(out) + } + + wis <- out$wis + if (separate_results) { + components <- list( + underprediction = out$underprediction, + overprediction = out$overprediction, + dispersion = out$dispersion + ) + } + + if (output == "vector" && separate_results) { + return(c(wis = wis, components)) + } else if (output == "vector") { + return(wis) + } + + if (output == "matrix") { + wis <- matrix(wis, nrow = n, ncol = N) + if (separate_results) { + components <- lapply(components, function(x) matrix(x, nrow = n, ncol = N)) + return(c(wis, components)) + } else { + return(wis) + } + } +} + + #' @title Absolute Error of the Median (Quantile-based Version) #' #' @description From 89f716142652a59d713f6e5000cd4e52d17db529 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 18:13:33 +0100 Subject: [PATCH 05/81] Add functions to check inputs for scoring functions that accept an interval format --- R/check-inputs-scoring-functions.R | 56 ++++++++++++++++++++++++++++++ man/assert_input_interval.Rd | 31 +++++++++++++++++ man/check_input_interval.Rd | 31 +++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 man/assert_input_interval.Rd create mode 100644 man/check_input_interval.Rd diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index 350a3af4f..195ff9fe8 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -85,6 +85,62 @@ check_input_quantile <- function(observed, predicted, quantile) { } +#' @title Assert that inputs are correct for interval-based forecast +#' @description Function assesses whether the inputs correspond to the +#' requirements for scoring interval-based forecasts. +#' @param observed Input to be checked. Should be a numeric vector with the +#' observed values of size n +#' @param lower Input to be checked. Should be a numeric vector of size n that +#' holds the predicted value for the lower bounds of the prediction intervals. +#' @param upper Input to be checked. Should be a numeric vector of size n that +#' holds the predicted value for the upper bounds of the prediction intervals. +#' @param range Input to be checked. Should be a vector of size n that +#' denotes the interval range in percent. E.g. a value of 50 denotes a +#' (25%, 75%) prediction interval. +#' @importFrom rlang warn +#' @inherit document_assert_functions return +#' @keywords internal +assert_input_interval <- function(observed, lower, upper, range) { + + assert_numeric_vector(observed, min.len = 1) + n <- length(observed) + assert_numeric_vector(lower, len = n) + assert_numeric_vector(upper, len = n) + assert_numeric_vector(range, len = n, lower = 0, upper = 100) + + diff <- upper - lower + if (any(diff < 0)) { + stop( + "All values in `upper` need to be greater than or equal to ", + "the corresponding values in `lower`" + ) + } + if (any(range > 0 & range < 1, na.rm = TRUE)) { + msg <- paste( + "Found interval ranges between 0 and 1. Are you sure that's right? An", + "interval range of 0.5 e.g. implies a (49.75%, 50.25%) prediction", + "interval. If you want to score a (25%, 75%) prediction interval, set", + "`interval_range = 50`." + ) + rlang::warn( + message = msg, .frequency = "once", + .frequency_id = "small_interval_range" + ) + } + return(invisible(NULL)) +} + + +#' @title Check that inputs are correct for interval-based forecast +#' @inherit assert_input_interval params description +#' @inherit check_input_sample return description +#' @keywords check-inputs +check_input_interval <- function(observed, lower, upper, range) { + result <- check_try(assert_input_quantile(observed, lower, upper, range)) + return(result) +} + + #' @title Assert that inputs are correct for binary forecast #' @description Function assesses whether the inputs correspond to the #' requirements for scoring binary forecasts. diff --git a/man/assert_input_interval.Rd b/man/assert_input_interval.Rd new file mode 100644 index 000000000..b8d2d93d0 --- /dev/null +++ b/man/assert_input_interval.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check-inputs-scoring-functions.R +\name{assert_input_interval} +\alias{assert_input_interval} +\title{Assert that inputs are correct for interval-based forecast} +\usage{ +assert_input_interval(observed, lower, upper, range) +} +\arguments{ +\item{observed}{Input to be checked. Should be a numeric vector with the +observed values of size n} + +\item{lower}{Input to be checked. Should be a numeric vector of size n that +holds the predicted value for the lower bounds of the prediction intervals.} + +\item{upper}{Input to be checked. Should be a numeric vector of size n that +holds the predicted value for the upper bounds of the prediction intervals.} + +\item{range}{Input to be checked. Should be a vector of size n that +denotes the interval range in percent. E.g. a value of 50 denotes a +(25\%, 75\%) prediction interval.} +} +\value{ +Returns NULL invisibly if the assertion was successful and throws an +error otherwise. +} +\description{ +Function assesses whether the inputs correspond to the +requirements for scoring interval-based forecasts. +} +\keyword{internal} diff --git a/man/check_input_interval.Rd b/man/check_input_interval.Rd new file mode 100644 index 000000000..faa9e4db5 --- /dev/null +++ b/man/check_input_interval.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check-inputs-scoring-functions.R +\name{check_input_interval} +\alias{check_input_interval} +\title{Check that inputs are correct for interval-based forecast} +\usage{ +check_input_interval(observed, lower, upper, range) +} +\arguments{ +\item{observed}{Input to be checked. Should be a numeric vector with the +observed values of size n} + +\item{lower}{Input to be checked. Should be a numeric vector of size n that +holds the predicted value for the lower bounds of the prediction intervals.} + +\item{upper}{Input to be checked. Should be a numeric vector of size n that +holds the predicted value for the upper bounds of the prediction intervals.} + +\item{range}{Input to be checked. Should be a vector of size n that +denotes the interval range in percent. E.g. a value of 50 denotes a +(25\%, 75\%) prediction interval.} +} +\value{ +Returns TRUE if the check was successful and a string with an +error message otherwise +} +\description{ +Function assesses whether the inputs correspond to the +requirements for scoring interval-based forecasts. +} +\keyword{check-inputs} From a98b0c756fb9724002fbe0eb93e0a6249f156e90 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 21:40:52 +0100 Subject: [PATCH 06/81] Simplify error handling in `interval_score()` --- R/metrics-range.R | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/R/metrics-range.R b/R/metrics-range.R index 6c25a878d..a1185e1ba 100644 --- a/R/metrics-range.R +++ b/R/metrics-range.R @@ -101,31 +101,7 @@ interval_score <- function(observed, weigh = TRUE, separate_results = FALSE) { - # error handling - not sure how I can make this better - present <- c( - methods::hasArg("observed"), methods::hasArg("lower"), - methods::hasArg("upper"), methods::hasArg("interval_range") - ) - if (!all(present)) { - stop( - "need all arguments 'observed', 'lower', 'upper' and 'interval_range' in function 'interval_score()'" # nolint - ) - } - assert_not_null( - observed = observed, lower = lower, upper = upper, - interval_range = interval_range - ) - assert_equal_length(observed, lower, interval_range, upper) - - if (any(interval_range < 0, na.rm = TRUE)) { - stop("interval ranges must be positive") - } - if (any(interval_range > 0 & interval_range < 1, na.rm = TRUE)) { - msg <- paste("Found interval ranges between 0 and 1. Are you sure that's right?", - "An interval range of 0.5 e.g. implies a (49.75%, 50.25%) prediction interval.", - "If you want to score a (25%, 75%) prediction interval, set interval_range = 50.") - rlang::warn(message = msg, .frequency = "once", .frequency_id = "small_interval_range") - } + assert_input_interval(observed, lower, upper, interval_range) # calculate alpha from the interval range alpha <- (100 - interval_range) / 100 From 83edaf81ca803aba6dc7876b3bc45aaa24becc39 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 21:41:22 +0100 Subject: [PATCH 07/81] correct input check for interval format and update tests that were failing --- R/check-inputs-scoring-functions.R | 11 +++++++---- tests/testthat/test-interval_score.R | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index 195ff9fe8..d2511402f 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -102,11 +102,14 @@ check_input_quantile <- function(observed, predicted, quantile) { #' @keywords internal assert_input_interval <- function(observed, lower, upper, range) { - assert_numeric_vector(observed, min.len = 1) + assert(check_numeric_vector(observed, min.len = 1)) n <- length(observed) - assert_numeric_vector(lower, len = n) - assert_numeric_vector(upper, len = n) - assert_numeric_vector(range, len = n, lower = 0, upper = 100) + assert(check_numeric_vector(lower, len = n)) + assert(check_numeric_vector(upper, len = n)) + assert( + check_numeric_vector(range, len = 1, lower = 0, upper = 100), + check_numeric_vector(range, len = n, lower = 0, upper = 100) + ) diff <- upper - lower if (any(diff < 0)) { diff --git a/tests/testthat/test-interval_score.R b/tests/testthat/test-interval_score.R index 4a69c7539..2a75c6fdb 100644 --- a/tests/testthat/test-interval_score.R +++ b/tests/testthat/test-interval_score.R @@ -411,7 +411,7 @@ test_that("Quantlie score and interval score yield the same result, weigh = FALS for (alpha in alphas) { lower <- qnorm(alpha / 2, rnorm(10, mean = 1:10)) - upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 1:10)) + upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 11:20)) w <- FALSE is <- interval_score( @@ -451,7 +451,7 @@ test_that("Quantlie score and interval score yield the same result, weigh = TRUE for (alpha in alphas) { lower <- qnorm(alpha / 2, rnorm(10, mean = 1:10)) - upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 1:10)) + upper <- qnorm((1 - alpha / 2), rnorm(10, mean = 11:20)) w <- TRUE is <- interval_score( From b6083d7d6e80821030983657e056b5849875496c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 22:06:16 +0100 Subject: [PATCH 08/81] Add requirement to input check for quantile scores that quantiles be unique --- R/check-inputs-scoring-functions.R | 10 ++++++++-- man/assert_input_quantile.Rd | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index d2511402f..607489667 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -50,14 +50,20 @@ check_input_sample <- function(observed, predicted) { #' @param quantile Input to be checked. Should be a vector of size N that #' denotes the quantile levels corresponding to the columns of the prediction #' matrix. +#' @param unique_quantiles Input to be checked. Should be TRUE (default) or +#' FALSE. Whether the quantile levels are required to be unique or not. #' @importFrom checkmate assert assert_numeric check_matrix #' @inherit document_assert_functions return #' @keywords internal -assert_input_quantile <- function(observed, predicted, quantile) { +assert_input_quantile <- function(observed, predicted, quantile, + unique_quantiles = TRUE) { assert_numeric(observed, min.len = 1) n_obs <- length(observed) - assert_numeric(quantile, min.len = 1, lower = 0, upper = 1) + assert_numeric( + quantile, min.len = 1, lower = 0, upper = 1, + unique = unique_quantiles + ) n_quantiles <- length(quantile) if (n_obs == 1) { assert( diff --git a/man/assert_input_quantile.Rd b/man/assert_input_quantile.Rd index 87247c0ff..c9a499136 100644 --- a/man/assert_input_quantile.Rd +++ b/man/assert_input_quantile.Rd @@ -4,7 +4,7 @@ \alias{assert_input_quantile} \title{Assert that inputs are correct for quantile-based forecast} \usage{ -assert_input_quantile(observed, predicted, quantile) +assert_input_quantile(observed, predicted, quantile, unique_quantiles = TRUE) } \arguments{ \item{observed}{Input to be checked. Should be a numeric vector with the @@ -19,6 +19,9 @@ vector of size N.} \item{quantile}{Input to be checked. Should be a vector of size N that denotes the quantile levels corresponding to the columns of the prediction matrix.} + +\item{unique_quantiles}{Input to be checked. Should be TRUE (default) or +FALSE. Whether the quantile levels are required to be unique or not.} } \value{ Returns NULL invisibly if the assertion was successful and throws an From 0d05879608392e1f63bee652984b0a6af458f389 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 22:23:49 +0100 Subject: [PATCH 09/81] Add requirement to input check for quantile scores that length of the quantile must be equal to the length of predictions if there is only one observation --- R/check-inputs-scoring-functions.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index 607489667..9833d0108 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -52,7 +52,7 @@ check_input_sample <- function(observed, predicted) { #' matrix. #' @param unique_quantiles Input to be checked. Should be TRUE (default) or #' FALSE. Whether the quantile levels are required to be unique or not. -#' @importFrom checkmate assert assert_numeric check_matrix +#' @importFrom checkmate assert assert_numeric check_matrix check_vector #' @inherit document_assert_functions return #' @keywords internal assert_input_quantile <- function(observed, predicted, quantile, @@ -72,6 +72,7 @@ assert_input_quantile <- function(observed, predicted, quantile, check_matrix(predicted, mode = "numeric", nrows = n_obs, ncols = n_quantiles) ) + assert(check_vector(quantile, len = length(predicted))) } else { assert( check_matrix(predicted, mode = "numeric", From 2c908a0256a64324efe8ddfb7314d7f1541615b3 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 22:36:52 +0100 Subject: [PATCH 10/81] Change `bias_quantile()` to work with a data.table internally. Foolishly hoping this is a bit easier / cleaner... --- NAMESPACE | 1 + R/metrics-quantile.R | 45 +++++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index f1235f87b..f97c8ec45 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -81,6 +81,7 @@ importFrom(checkmate,check_data_frame) importFrom(checkmate,check_function) importFrom(checkmate,check_matrix) importFrom(checkmate,check_numeric) +importFrom(checkmate,check_vector) importFrom(checkmate,test_factor) importFrom(checkmate,test_list) importFrom(checkmate,test_numeric) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 92b2a2528..72549a09a 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -125,34 +125,27 @@ wis <- function(observed, #' @keywords metric bias_quantile <- function(observed, predicted, quantile) { - # check that predictions and quantile have the same length - if (!length(predicted) == length(quantile)) { - stop("`predicted` and `quantile` must have the same length") - } - if (anyNA(predicted)) { - quantile <- quantile[!is.na(predicted)] - predicted <- predicted[!is.na(predicted)] - } + assert_input_quantile(observed, predicted, quantile) - if (anyNA(quantile)) { - quantile <- quantile[!is.na(quantile)] - predicted <- predicted[!is.na(quantile)] - } + dt <- data.table( + observed = observed, + predicted = predicted, + quantile = quantile + ) + dt <- dt[!is.na(quantile) & !is.na(predicted)] + dt <- dt[order(quantile)] - # if there is no input, return NA - if (length(quantile) == 0 || length(predicted) == 0) { + if (nrow(dt) == 0) { return(NA_real_) } - check_quantiles(quantile) - - if (!all(diff(predicted) >= 0)) { - stop("predictions must be increasing with quantiles") + if (!all(diff(dt$predicted) >= 0)) { + stop("Predictions must not be decreasing with increasing quantile level") } - if (0.5 %in% quantile) { - median_prediction <- predicted[quantile == 0.5] + if (0.5 %in% dt$quantile) { + median_prediction <- dt[quantile == 0.5]$predicted } else { # if median is not available, compute as mean of two innermost quantiles message( @@ -160,25 +153,25 @@ bias_quantile <- function(observed, predicted, quantile) { " in order to compute bias." ) median_prediction <- - 0.5 * predicted[quantile == max(quantile[quantile < 0.5])] + - 0.5 * predicted[quantile == min(quantile[quantile > 0.5])] + 0.5 * dt[quantile == max(quantile[quantile < 0.5])]$predicted + + 0.5 * dt[quantile == min(quantile[quantile > 0.5])]$predicted } if (observed == median_prediction) { bias <- 0 return(bias) } else if (observed < median_prediction) { - if (observed < min(predicted)) { + if (observed < min(dt$predicted)) { bias <- 1 } else { - q <- max(quantile[predicted <= observed]) + q <- max(dt[predicted <= observed]$quantile) bias <- 1 - 2 * q } } else if (observed > median_prediction) { - if (observed > max(predicted)) { + if (observed > max(dt$predicted)) { bias <- -1 } else { - q <- min(quantile[predicted >= observed]) + q <- min(dt[predicted >= observed]$quantile) bias <- 1 - 2 * q } } From d56eedd45731b7cc5f2695d4812425ff2c3685c3 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 3 Nov 2023 22:52:19 +0100 Subject: [PATCH 11/81] Make bias_quantile work with matrices and multiple observed values as well by introducing a new function bias_quantile_single --- R/metrics-quantile.R | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 72549a09a..c758dc8da 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -128,13 +128,27 @@ bias_quantile <- function(observed, predicted, quantile) { assert_input_quantile(observed, predicted, quantile) + n <- length(observed) + N <- length(quantile) + dt <- data.table( - observed = observed, - predicted = predicted, + forecast_id = rep(1:n, each = N), + observed = rep(observed, each = N), + predicted = as.vector(t(predicted)), quantile = quantile - ) + )[order(forecast_id, quantile)] + + dt <- dt[, .(bias = bias_quantile_single(.SD)), by = forecast_id] + + return(dt$bias) +} + + +bias_quantile_single <- function(dt) { + dt <- dt[!is.na(quantile) & !is.na(predicted)] - dt <- dt[order(quantile)] + + observed <- unique(dt$observed) if (nrow(dt) == 0) { return(NA_real_) From 4beb3a811534e516fa854136d2a92ff5b42fac60 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 10:09:17 +0100 Subject: [PATCH 12/81] Update input check for scores in interval format to handle NA values --- R/check-inputs-scoring-functions.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index 9833d0108..0e4467e3c 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -119,6 +119,7 @@ assert_input_interval <- function(observed, lower, upper, range) { ) diff <- upper - lower + diff <- diff[!is.na(diff)] if (any(diff < 0)) { stop( "All values in `upper` need to be greater than or equal to ", From 6b6a8c25f74b621c2074efb499a6a82a2db863dd Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 10:10:09 +0100 Subject: [PATCH 13/81] Update examples and vignette such that examples don't have any more instances where the lower bound of an interval is higher than an upper bound --- R/metrics-range.R | 4 ++-- man/interval_score.Rd | 4 ++-- vignettes/scoring-forecasts-directly.Rmd | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/metrics-range.R b/R/metrics-range.R index a1185e1ba..5263d8962 100644 --- a/R/metrics-range.R +++ b/R/metrics-range.R @@ -63,7 +63,7 @@ #' interval_range <- rep(90, 30) #' alpha <- (100 - interval_range) / 100 #' lower <- qnorm(alpha / 2, rnorm(30, mean = 1:30)) -#' upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 1:30)) +#' upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 11:40)) #' #' interval_score( #' observed = observed, @@ -73,7 +73,7 @@ #' ) #' #' # gives a warning, as the interval_range should likely be 50 instead of 0.5 -#' interval_score(observed = 4, upper = 2, lower = 8, interval_range = 0.5) +#' interval_score(observed = 4, upper = 8, lower = 2, interval_range = 0.5) #' #' # example with missing values and separate results #' interval_score( diff --git a/man/interval_score.Rd b/man/interval_score.Rd index 9232fde21..9c0f4c567 100644 --- a/man/interval_score.Rd +++ b/man/interval_score.Rd @@ -80,7 +80,7 @@ observed <- rnorm(30, mean = 1:30) interval_range <- rep(90, 30) alpha <- (100 - interval_range) / 100 lower <- qnorm(alpha / 2, rnorm(30, mean = 1:30)) -upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 1:30)) +upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 11:40)) interval_score( observed = observed, @@ -90,7 +90,7 @@ interval_score( ) # gives a warning, as the interval_range should likely be 50 instead of 0.5 -interval_score(observed = 4, upper = 2, lower = 8, interval_range = 0.5) +interval_score(observed = 4, upper = 8, lower = 2, interval_range = 0.5) # example with missing values and separate results interval_score( diff --git a/vignettes/scoring-forecasts-directly.Rmd b/vignettes/scoring-forecasts-directly.Rmd index d7a68736f..9272f5d27 100644 --- a/vignettes/scoring-forecasts-directly.Rmd +++ b/vignettes/scoring-forecasts-directly.Rmd @@ -207,7 +207,7 @@ observed <- rnorm(30, mean = 1:30) interval_range <- 90 alpha <- (100 - interval_range) / 100 lower <- qnorm(alpha / 2, rnorm(30, mean = 1:30)) -upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 1:30)) +upper <- qnorm((1 - alpha / 2), rnorm(30, mean = 11:40)) interval_score( observed = observed, From ff544357cfda00868d8183f5ba3ac603d9c1de7d Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 10:11:03 +0100 Subject: [PATCH 14/81] update and expand tests for bias_quantile --- tests/testthat/test-bias.R | 85 +++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-bias.R b/tests/testthat/test-bias.R index a8444707d..b1e59fd6d 100644 --- a/tests/testthat/test-bias.R +++ b/tests/testthat/test-bias.R @@ -67,18 +67,75 @@ test_that("bias_sample() works as expected", { expect_equal(scoringutils, scoringutils2) }) -test_that("bias_quantile() handles NA values", { + +test_that("bias_quantile() works as expected", { + predicted <- c(1, 2, 3) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + 0 + ) + predicted <- c(0, 1, 2) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -0.8 + ) + + predicted <- c( + 705.500, 1127.000, 4006.250, 4341.500, 4709.000, 4821.996, + 5340.500, 5451.000, 5703.500, 6087.014, 6329.500, 6341.000, + 6352.500, 6594.986, 6978.500, 7231.000, 7341.500, 7860.004, + 7973.000, 8340.500, 8675.750, 11555.000, 11976.500 + ) + + quantile <- c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) + + observed <- 8062 + expect_equal(bias_quantile(observed, predicted, quantile), -0.8) +}) + +test_that("bias_quantile handles matrix input", { + observed <- seq(10, 0, length.out = 4) + predicted <- matrix(1:12, ncol = 3) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed, predicted, quantiles), + c(-1.0, -0.8, 0.8, 1.0) + ) +}) + + +test_that("bias_quantile() handles vector that is too long", { predicted <- c(NA, 1, 2, 3) quantiles <- c(0.1, 0.5, 0.9) expect_error( bias_quantile(observed = 2, predicted, quantiles), - "`predicted` and `quantile` must have the same length" + "Assertion on 'quantile' failed: Must have length 4, but has length 3." ) }) -test_that("bias_quantile() returns NA if no predictions", { - expect_true(is.na(bias_quantile(observed = 2, numeric(0), numeric(0)))) +test_that("bias_quantile() handles NA values", { + predicted <- c(NA, 1, 2) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -0.8 + ) + predicted <- c(0, 1, 2) + quantiles <- c(0.1, 0.5, NA) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -1 + ) +}) + +test_that("bias_quantile() errors if no predictions", { + expect_error( + bias_quantile(observed = 2, numeric(0), numeric(0)), + "Assertion on 'quantile' failed: Must have length >= 1, but has length 0" + ) }) test_that("bias_quantile() returns correct bias if value below the median", { @@ -125,8 +182,10 @@ test_that("bias_quantile(): quantiles must be between 0 and 1", { # Failing example quantiles <- c(-0.1, 0.3, 0.5, 0.8) - expect_error(bias_quantile(observed = 3, predicted, quantiles), - "quantiles must be between 0 and 1") + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Assertion on 'quantile' failed: Element 1 is not >= 0." + ) # Passing counter example quantiles <- c(0.1, 0.3, 0.5, 0.8) @@ -138,8 +197,10 @@ test_that("bias_quantile(): quantiles must be increasing", { # Failing example quantiles <- c(0.8, 0.3, 0.5, 0.9) - expect_error(bias_quantile(observed = 3, predicted, quantiles), - "quantiles must be increasing") + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Predictions must not be decreasing with increasing quantile level" + ) # Passing counter example quantiles <- c(0.3, 0.5, 0.8, 0.9) @@ -152,7 +213,7 @@ test_that("bias_quantile(): predictions must be increasing", { expect_error( bias_quantile(observed = 3, predicted, quantiles), - "predictions must be increasing" + "Predictions must not be decreasing with increasing quantile level" ) expect_silent(bias_quantile( observed = 3, 1:4, quantiles)) }) @@ -162,8 +223,10 @@ test_that("bias_quantile(): quantiles must be unique", { # Failing example quantiles <- c(0.3, 0.3, 0.5, 0.8) - expect_error(bias_quantile(observed = 3, predicted, quantiles), - "quantiles must be increasing") + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Assertion on 'quantile' failed: Contains duplicated values, position 2." + ) # Passing example quantiles <- c(0.3, 0.5, 0.8, 0.9) From adb95210fea30ca6bfccc433a5c11a4d5022dc4f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 16:11:36 +0100 Subject: [PATCH 15/81] Add coverage function that works on raw data instead of scores --- NAMESPACE | 3 ++ R/add_coverage.R | 95 +++++++++++++++++++++++++++++++++++++++++ R/utils_data_handling.R | 2 +- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 R/add_coverage.R diff --git a/NAMESPACE b/NAMESPACE index f97c8ec45..9603ab566 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +S3method(add_coverage_raw_data,default) +S3method(add_coverage_raw_data,scoringutils_quantile) S3method(plot,scoringutils_available_forecasts) S3method(print,scoringutils_check) S3method(quantile_to_interval,data.frame) @@ -16,6 +18,7 @@ S3method(validate,scoringutils_quantile) S3method(validate,scoringutils_sample) export(abs_error) export(add_coverage) +export(add_coverage_raw_data) export(add_pairwise_comparison) export(ae_median_quantile) export(ae_median_sample) diff --git a/R/add_coverage.R b/R/add_coverage.R new file mode 100644 index 000000000..ea2f89e66 --- /dev/null +++ b/R/add_coverage.R @@ -0,0 +1,95 @@ +#' @export +add_coverage_raw_data <- function(data, + by = NULL, + ranges = c(50, 90)) { + UseMethod("add_coverage_raw_data") +} + +#' @export +add_coverage_raw_data.default <- function(data, + by = NULL, + ranges = c(50, 90)) { + data <- validate(data) + add_coverage_raw_data(data, by = by, ranges = ranges) +} + +#' @export +add_coverage_raw_data.scoringutils_quantile <- function(data, + by, + ranges) { + stored_attributes <- get_scoringutils_attributes(data) + data <- remove_na_observed_predicted(data) + + if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { + by <- stored_attributes[["scoringutils_by"]] + } else if (is.null(by)) { + # Need to check this again. + # (mentioned in https://github.com/epiforecasts/scoringutils/issues/346) + by <- get_forecast_unit(data) + } + + interval_data <- quantile_to_interval(data, format = "wide") + interval_data[, coverage := ifelse(observed <= upper & observed >= lower, 1, 0)] # nolint + interval_data[, coverage_deviation := coverage - range / 100] + + summarised <- interval_data[, .(coverage = mean(coverage), + coverage_deviation = mean(coverage_deviation)), + by = c(by, "range")][range %in% ranges] + + cast_formula <- + paste( + paste(by, collapse = "+"), + "~", + "paste0('coverage_', range)" + ) + + coverages <- dcast( + summarised, + value.var = "coverage", + formula = cast_formula + ) + + data_with_coverage <- merge(data, coverages, by = by) + data_with_coverage <- assign_attributes( + data_with_coverage, stored_attributes + ) + + return(data_with_coverage[]) +} + +#' @export +add_coverage_raw_data.scoringutils_sample <- function(data, + by, + ranges) { + stored_attributes <- get_scoringutils_attributes(data) + data <- remove_na_observed_predicted(data) + if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { + by <- stored_attributes[["scoringutils_by"]] + } else if (is.null(by)) { + # Need to check this again. + # (mentioned in https://github.com/epiforecasts/scoringutils/issues/346) + by <- get_forecast_unit(data) + } + + lower_quantiles <- (100 - ranges) / 200 + upper_quantiles <- 1 - lower_quantiles + quantiles <- sort(c(lower_quantiles, upper_quantiles)) + + quantile_format <- sample_to_quantile(data, quantiles = quantiles, type = 7) + + coverages <- add_coverage_raw_data.scoringutils_quantile( + quantile_format, + by = by, + ranges = ranges + ) + + coverages <- unique( + coverages[, c("quantile", "predicted", "observed") := NULL] + ) + + data_with_coverage <- merge(data, coverages, by = by) + data_with_coverage <- assign_attributes( + data_with_coverage, stored_attributes + ) + return(data_with_coverage[]) +} diff --git a/R/utils_data_handling.R b/R/utils_data_handling.R index d0677ca34..71cd4bf1f 100644 --- a/R/utils_data_handling.R +++ b/R/utils_data_handling.R @@ -101,7 +101,7 @@ merge_pred_and_obs <- function(forecasts, observations, sample_to_quantile <- function(data, quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95), type = 7) { - data <- data.table::as.data.table(data) + data <- copy(data) reserved_columns <- c("predicted", "sample_id") by <- setdiff(colnames(data), reserved_columns) From bba589abb55e7e66f42682aa380f583dd4b7e273 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 17:45:14 +0100 Subject: [PATCH 16/81] Add function documentation --- NAMESPACE | 1 + R/add_coverage.R | 52 ++++++++++++++++++++++++++--- man/add_coverage_raw_data.Rd | 63 ++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 man/add_coverage_raw_data.Rd diff --git a/NAMESPACE b/NAMESPACE index 9603ab566..ef370078d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method(add_coverage_raw_data,default) S3method(add_coverage_raw_data,scoringutils_quantile) +S3method(add_coverage_raw_data,scoringutils_sample) S3method(plot,scoringutils_available_forecasts) S3method(print,scoringutils_check) S3method(quantile_to_interval,data.frame) diff --git a/R/add_coverage.R b/R/add_coverage.R index ea2f89e66..239c27244 100644 --- a/R/add_coverage.R +++ b/R/add_coverage.R @@ -1,3 +1,40 @@ +#' @title Add Coverage of Central Prediction Intervals to Forecasts +#' +#' @description Adds a column with the coverage of central prediction intervals +#' to a data.table with forecasts either in a quantile or in a sample-based +#' format (following the input requirements of `score()`). +#' +#' Coverage for a given interval range is defined as the proportion of +#' observations that fall within the corresponding central prediction intervals. +#' Central prediction intervals are symmetric around the median and and formed +#' by two quantiles that denote the lower and upper bound. For example, the 50% +#' central prediction interval is the interval between the 0.25 and 0.75 +#' quantiles of the predictive distribution. +#' +#' The coverage values that are added are computed according to the values +#' specified in `by`. If, for example, `by = "model"`, then there will be one +#' coverage value for every model. If `by = c("model", "target_type")`, then +#' there will be one coverage value for every combination of model and target +#' type. +#' +#' @inheritParams score +#' @param by character vector with column names to add the coverage for. +#' @param ranges numeric vector of the ranges of the central prediction intervals +#' for which coverage values shall be added. Ranges should be given as +#' percentages. For example, `ranges = c(50, 90)` +#' will add coverage values for the 50% and 90% central prediction intervals ( +#' corresponding to the 0.05, 0.25, 0.75 and 0.95 quantiles of the predictive +#' distribution). +#' @return a data.table with with columns added for the +#' coverage of the central prediction intervals. While the overall data.table +#' is still unsummarised, note that for the coverage columns some level of +#' summary is present according to the value specified in `by`. +#' @examples +#' library(magrittr) # pipe operator +#' example_quantile %>% +#' add_coverage_raw_data(by = c("model", "target_type")) +#' @export +#' @keywords scoring #' @export add_coverage_raw_data <- function(data, by = NULL, @@ -5,6 +42,11 @@ add_coverage_raw_data <- function(data, UseMethod("add_coverage_raw_data") } +#' @description +#' `add_coverage_raw_data.default()` validates the input data, +#' checks the forecast type and calls `add_coverage_raw_data()` again to +#' dispatch to the appropriate method. +#' @rdname add_coverage_raw_data #' @export add_coverage_raw_data.default <- function(data, by = NULL, @@ -13,10 +55,11 @@ add_coverage_raw_data.default <- function(data, add_coverage_raw_data(data, by = by, ranges = ranges) } +#' @rdname add_coverage_raw_data #' @export add_coverage_raw_data.scoringutils_quantile <- function(data, - by, - ranges) { + by = NULL, + ranges = c(50, 90)) { stored_attributes <- get_scoringutils_attributes(data) data <- remove_na_observed_predicted(data) @@ -57,10 +100,11 @@ add_coverage_raw_data.scoringutils_quantile <- function(data, return(data_with_coverage[]) } +#' @rdname add_coverage_raw_data #' @export add_coverage_raw_data.scoringutils_sample <- function(data, - by, - ranges) { + by = NULL, + ranges = c(50, 90)) { stored_attributes <- get_scoringutils_attributes(data) data <- remove_na_observed_predicted(data) if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { diff --git a/man/add_coverage_raw_data.Rd b/man/add_coverage_raw_data.Rd new file mode 100644 index 000000000..214290e81 --- /dev/null +++ b/man/add_coverage_raw_data.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_coverage.R +\name{add_coverage_raw_data} +\alias{add_coverage_raw_data} +\alias{add_coverage_raw_data.default} +\alias{add_coverage_raw_data.scoringutils_quantile} +\alias{add_coverage_raw_data.scoringutils_sample} +\title{Add Coverage of Central Prediction Intervals to Forecasts} +\usage{ +add_coverage_raw_data(data, by = NULL, ranges = c(50, 90)) + +\method{add_coverage_raw_data}{default}(data, by = NULL, ranges = c(50, 90)) + +\method{add_coverage_raw_data}{scoringutils_quantile}(data, by = NULL, ranges = c(50, 90)) + +\method{add_coverage_raw_data}{scoringutils_sample}(data, by = NULL, ranges = c(50, 90)) +} +\arguments{ +\item{data}{A data.frame or data.table with predicted and observed values.} + +\item{by}{character vector with column names to add the coverage for.} + +\item{ranges}{numeric vector of the ranges of the central prediction intervals +for which coverage values shall be added. Ranges should be given as +percentages. For example, \code{ranges = c(50, 90)} +will add coverage values for the 50\% and 90\% central prediction intervals ( +corresponding to the 0.05, 0.25, 0.75 and 0.95 quantiles of the predictive +distribution).} +} +\value{ +a data.table with with columns added for the +coverage of the central prediction intervals. While the overall data.table +is still unsummarised, note that for the coverage columns some level of +summary is present according to the value specified in \code{by}. +} +\description{ +Adds a column with the coverage of central prediction intervals +to a data.table with forecasts either in a quantile or in a sample-based +format (following the input requirements of \code{score()}). + +Coverage for a given interval range is defined as the proportion of +observations that fall within the corresponding central prediction intervals. +Central prediction intervals are symmetric around the median and and formed +by two quantiles that denote the lower and upper bound. For example, the 50\% +central prediction interval is the interval between the 0.25 and 0.75 +quantiles of the predictive distribution. + +The coverage values that are added are computed according to the values +specified in \code{by}. If, for example, \code{by = "model"}, then there will be one +coverage value for every model. If \code{by = c("model", "target_type")}, then +there will be one coverage value for every combination of model and target +type. + +\code{add_coverage_raw_data.default()} validates the input data, +checks the forecast type and calls \code{add_coverage_raw_data()} again to +dispatch to the appropriate method. +} +\examples{ +library(magrittr) # pipe operator +example_quantile \%>\% + add_coverage_raw_data(by = c("model", "target_type")) +} +\keyword{scoring} From fb037472c908cdf3a0894ad63667bc4e6d02fe3c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 4 Nov 2023 18:28:43 +0100 Subject: [PATCH 17/81] Fix sample_to_quantile() error to handle data.frame inputs --- R/utils_data_handling.R | 6 +++++- tests/testthat/test-utils_data_handling.R | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/R/utils_data_handling.R b/R/utils_data_handling.R index 71cd4bf1f..cb9470e87 100644 --- a/R/utils_data_handling.R +++ b/R/utils_data_handling.R @@ -101,7 +101,11 @@ merge_pred_and_obs <- function(forecasts, observations, sample_to_quantile <- function(data, quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95), type = 7) { - data <- copy(data) + if (!is.data.table(data)) { + data <- data.table::as.data.table(data) + } else { + data <- copy(data) + } reserved_columns <- c("predicted", "sample_id") by <- setdiff(colnames(data), reserved_columns) diff --git a/tests/testthat/test-utils_data_handling.R b/tests/testthat/test-utils_data_handling.R index 6e53cdbaa..e627485ab 100644 --- a/tests/testthat/test-utils_data_handling.R +++ b/tests/testthat/test-utils_data_handling.R @@ -72,7 +72,7 @@ test_that("sample_to_quantiles works", { predicted = rep(2:11, each = 2) + c(0, 2) ) - quantile2 <- scoringutils::sample_to_quantile(samples, quantiles = c(0.25, 0.75)) + quantile2 <- sample_to_quantile(samples, quantiles = c(0.25, 0.75)) expect_equal(quantile, as.data.frame(quantile2)) From e3b80b0f48abb15663c92719855b352163674f3d Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 6 Nov 2023 14:11:17 +0100 Subject: [PATCH 18/81] Create first draft of score.scoringutils_quantile() that works with arbitrary metrics --- NAMESPACE | 1 + R/data.R | 8 ++++ R/score.R | 57 +++++++++++++++++++++++++ data/metrics_quantile.rda | Bin 0 -> 6157 bytes inst/create-list-available-forecasts.R | 6 ++- man/metrics_sample.Rd | 10 +++++ man/score.Rd | 3 ++ 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 data/metrics_quantile.rda diff --git a/NAMESPACE b/NAMESPACE index ef370078d..7a806c3be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ S3method(score,default) S3method(score,scoringutils_binary) S3method(score,scoringutils_point) S3method(score,scoringutils_quantile) +S3method(score,scoringutils_quantile_new) S3method(score,scoringutils_sample) S3method(validate,default) S3method(validate,scoringutils_binary) diff --git a/R/data.R b/R/data.R index 520a44cac..9c5569646 100644 --- a/R/data.R +++ b/R/data.R @@ -211,3 +211,11 @@ #' - "se_mean" = [se_mean_sample()] #' @keywords info "metrics_sample" + +#' Default metrics for quantile-based forecasts. +#' +#' A named list with functions: +#' - "wis" = [wis()] +#' - "bias" = [bias_quantile()] +#' @keywords info +"metrics_sample" diff --git a/R/score.R b/R/score.R index 4e235ade3..e4290287f 100644 --- a/R/score.R +++ b/R/score.R @@ -257,3 +257,60 @@ score.scoringutils_quantile <- function(data, metrics = NULL, ...) { return(scores[]) } + + +#' @rdname score +#' @export +score.scoringutils_quantile_new <- function(data, metrics = metrics_quantile, ...) { + data <- validate(data) + data <- remove_na_observed_predicted(data) + forecast_unit <- attr(data, "forecast_unit") + metrics <- validate_metrics(metrics) + + # Extract the arguments passed in ... + args <- list(...) + + # transpose the forecasts that belong to the same forecast unit + # make sure the quantiles and predictions are ordered in the same way + d_transposed <- data[, .(predicted = list(predicted[order(quantile)]), + observed = unique(observed), + quantile = list(quantile[order(quantile)]), + N = length(quantile)), by = forecast_unit] + + # split according to quantile lengths and do calculations for different + # quantile lengths separately. The function `wis()` assumes that all + # forecasts have the same quantiles + d_split <- split(d_transposed, d_transposed$N) + + split_result <- lapply(d_split, function(data) { + # create a matrix out of the list of predicted values and quantiles + observed <- data$observed + predicted <- do.call(rbind, data$predicted) + quantile <- unlist(unique(data$quantile)) + data[, c("observed", "predicted", "quantile", "N") := NULL] + + # for each metric, compute score + lapply(seq_along(metrics), function(i, ...) { + metric_name <- names(metrics[i]) + fun <- metrics[[i]] + matching_args <- filter_function_args(fun, args) + + if ("separate_results" %in% names(matching_args) && + matching_args$separate_results) { + metric_name <- c(metric_name, "dispersion", "underprediction", "overprediction") + } + + data[, eval(metric_name) := do.call( + fun, c(list(observed), list(predicted), list(quantile), matching_args) + )] + return() + }, + ...) + return(data) + }) + + data <- rbindlist(split_result) + setattr(data, "metric_names", names(metrics)) + + return(data[]) +} diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda new file mode 100644 index 0000000000000000000000000000000000000000..88945fc57c6d2801e975ab595888b9ce73cd221b GIT binary patch literal 6157 zcmV+o81m;rT4*^jL0KkKSvv~9DF98ifB*mg|NsC0|NsC0|NsC0|NsC0{}2EF`~Uy{ z*lXWi{eR#Z-SgSJ?bmGQyX|}DMQEWxL8<^zx6isEL0Rv&eeZk$=l}%R0LRnN6pGtX zAyk@b2Q^2)4}wxnL857W|BPf6+O zYI=r7k5Qx4$)nWro}k5fmK0iX>H4^U_T00006fCE4P01TQ9G(sUX zjT(B1=nYMv83f6unqY&{F*16aP+_T~O)x!EBNHZ%Q^-a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CnzHf+_fjR=8)ThNpEL;BFLy|-LQ fNM~G11#TxY`a?*N3RMCA|BJaIoG3^gg Date: Tue, 7 Nov 2023 18:11:13 +0100 Subject: [PATCH 19/81] Create functions to compute interval coverage for quantile- and sample-based forecasts --- NAMESPACE | 3 +++ R/metrics-quantile.R | 44 ++++++++++++++++++++++++++++++++++++++++++++ R/metrics-sample.R | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index ef370078d..351b44194 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,6 +34,8 @@ export(correlation) export(crps_sample) export(dss_sample) export(get_duplicate_forecasts) +export(interval_coverage_quantile) +export(interval_coverage_sample) export(interval_score) export(log_shift) export(logs_binary) @@ -79,6 +81,7 @@ importFrom(checkmate,assert_data_frame) importFrom(checkmate,assert_data_table) importFrom(checkmate,assert_factor) importFrom(checkmate,assert_list) +importFrom(checkmate,assert_number) importFrom(checkmate,assert_numeric) importFrom(checkmate,check_atomic_vector) importFrom(checkmate,check_data_frame) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index c758dc8da..6c4fa6215 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -63,6 +63,50 @@ wis <- function(observed, } +#' @title Interval Coverage (For Quantile-Based Forecasts) +#' @description Check whether the observed value is within a given central +#' prediction interval. The prediction interval is defined by a lower and an +#' upper bound formed by a pair of predictive quantiles. For example, a 50% +#' prediction interval is formed by the 0.25 and 0.75 quantiles of the +#' predictive distribution. +#' @inheritParams wis +#' @param range A single number with the range of the prediction interval in +#' percent (e.g. 50 for a 50% prediction interval) for which you want to compute +#' coverage. +#' @importFrom checkmate assert_number +#' @return A vector of length n with TRUE if the observed value is within the +#' corresponding prediction interval and FALSE otherwise. +#' @name interval_coverage +#' @export +#' @examples +#' observed <- c(1, -15, 22) +#' predicted <- rbind( +#' c(-1, 0, 1, 2, 3), +#' c(-2, 1, 2, 2, 4), +#' c(-2, 0, 3, 3, 4) +#' ) +#' quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) +#' interval_coverage_quantile(observed, predicted, quantile) +interval_coverage_quantile <- function(observed, predicted, quantile, range = 50) { + assert_input_quantile(observed, predicted, quantile) + assert_number(range) + necessary_quantiles <- c((100 - range) / 2, 100 - (100 - range) / 2) / 100 + if (!all(necessary_quantiles %in% quantile)) { + rlang::warn( + "To compute the coverage for a range of ", range, "%, the quantiles ", + necessary_quantiles, " are required. Returnting `NA`.") + return(NA) + } + r <- range + reformatted <- scoringutils:::quantile_to_interval(observed, predicted, quantile) + reformatted <- reformatted[range %in% r] + reformatted[, coverage := ifelse( + observed >= lower & observed <= upper, TRUE, FALSE + )] + return(reformatted$coverage) +} + + #' @title Determines Bias of Quantile Forecasts #' #' @description diff --git a/R/metrics-sample.R b/R/metrics-sample.R index 67291bffa..723f2e233 100644 --- a/R/metrics-sample.R +++ b/R/metrics-sample.R @@ -283,3 +283,39 @@ mad_sample <- function(observed = NULL, predicted, ...) { sharpness <- apply(predicted, MARGIN = 1, mad, ...) return(sharpness) } + + +#' @title Interval Coverage +#' @description To compute coverage for sample-based forecasts, +#' predictive samples are converted first into predictive quantiles using the +#' sample quantiles. +#' @importFrom checkmate assert_number +#' @rdname interval_coverage +#' @export +#' @examples +#' interval_coverage_sample(observed, predicted, quantile) +interval_coverage_sample <- function(observed, predicted, range = 50) { + assert_input_sample(observed, predicted) + assert_number(range) + necessary_quantiles <- c((100 - range) / 2, 100 - (100 - range) / 2) / 100 + + # this could be its own function, sample_to_quantile.numeric + # ========================================================== + n <- length(observed) + N <- length(predicted) / n + dt <- data.table( + observed = rep(observed, each = N), + predicted = as.vector(t(predicted)) + ) + quantile_dt <- sample_to_quantile(dt, necessary_quantiles) + # ========================================================== + + # this could call interval_coverage_quantile instead + # ========================================================== + interval_dt <- scoringutils:::quantile_to_interval(quantile_dt, format = "wide") + interval_dt[, coverage := ifelse( + observed >= lower & observed <= upper, TRUE, FALSE + )] + # ========================================================== + return(interval_dt$coverage) +} From 069b094087db75bc210eb5e972cf25b75870669e Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 7 Nov 2023 18:23:15 +0100 Subject: [PATCH 20/81] Fix typos / check issues --- R/metrics-quantile.R | 2 +- R/metrics-sample.R | 4 ++-- man/interval_coverage.Rd | 49 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 man/interval_coverage.Rd diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 6c4fa6215..018d9d323 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -98,7 +98,7 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 return(NA) } r <- range - reformatted <- scoringutils:::quantile_to_interval(observed, predicted, quantile) + reformatted <- quantile_to_interval(observed, predicted, quantile) reformatted <- reformatted[range %in% r] reformatted[, coverage := ifelse( observed >= lower & observed <= upper, TRUE, FALSE diff --git a/R/metrics-sample.R b/R/metrics-sample.R index 723f2e233..73026bfcf 100644 --- a/R/metrics-sample.R +++ b/R/metrics-sample.R @@ -293,7 +293,7 @@ mad_sample <- function(observed = NULL, predicted, ...) { #' @rdname interval_coverage #' @export #' @examples -#' interval_coverage_sample(observed, predicted, quantile) +#' interval_coverage_sample(observed, predicted) interval_coverage_sample <- function(observed, predicted, range = 50) { assert_input_sample(observed, predicted) assert_number(range) @@ -312,7 +312,7 @@ interval_coverage_sample <- function(observed, predicted, range = 50) { # this could call interval_coverage_quantile instead # ========================================================== - interval_dt <- scoringutils:::quantile_to_interval(quantile_dt, format = "wide") + interval_dt <- quantile_to_interval(quantile_dt, format = "wide") interval_dt[, coverage := ifelse( observed >= lower & observed <= upper, TRUE, FALSE )] diff --git a/man/interval_coverage.Rd b/man/interval_coverage.Rd new file mode 100644 index 000000000..8fbfc67d1 --- /dev/null +++ b/man/interval_coverage.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics-quantile.R, R/metrics-sample.R +\name{interval_coverage} +\alias{interval_coverage} +\alias{interval_coverage_quantile} +\alias{interval_coverage_sample} +\title{Interval Coverage (For Quantile-Based Forecasts)} +\usage{ +interval_coverage_quantile(observed, predicted, quantile, range = 50) + +interval_coverage_sample(observed, predicted, range = 50) +} +\arguments{ +\item{observed}{A vector with observed values of size n} + +\item{predicted}{vector of size n with the predicted values} + +\item{quantile}{vector with quantile levels of size N} + +\item{range}{A single number with the range of the prediction interval in +percent (e.g. 50 for a 50\% prediction interval) for which you want to compute +coverage.} +} +\value{ +A vector of length n with TRUE if the observed value is within the +corresponding prediction interval and FALSE otherwise. +} +\description{ +Check whether the observed value is within a given central +prediction interval. The prediction interval is defined by a lower and an +upper bound formed by a pair of predictive quantiles. For example, a 50\% +prediction interval is formed by the 0.25 and 0.75 quantiles of the +predictive distribution. + +To compute coverage for sample-based forecasts, +predictive samples are converted first into predictive quantiles using the +sample quantiles. +} +\examples{ +observed <- c(1, -15, 22) +predicted <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) +interval_coverage_quantile(observed, predicted, quantile) +interval_coverage_sample(observed, predicted) +} From c3803dd78b454b1fab0ebdbd3e04aba9d5355662 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 7 Nov 2023 18:31:17 +0100 Subject: [PATCH 21/81] Delete coverage function based on raw data --- NAMESPACE | 4 - R/add_coverage.R | 139 ----------------------------------- man/add_coverage_raw_data.Rd | 63 ---------------- 3 files changed, 206 deletions(-) delete mode 100644 R/add_coverage.R delete mode 100644 man/add_coverage_raw_data.Rd diff --git a/NAMESPACE b/NAMESPACE index 351b44194..b1224bbec 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,5 @@ # Generated by roxygen2: do not edit by hand -S3method(add_coverage_raw_data,default) -S3method(add_coverage_raw_data,scoringutils_quantile) -S3method(add_coverage_raw_data,scoringutils_sample) S3method(plot,scoringutils_available_forecasts) S3method(print,scoringutils_check) S3method(quantile_to_interval,data.frame) @@ -19,7 +16,6 @@ S3method(validate,scoringutils_quantile) S3method(validate,scoringutils_sample) export(abs_error) export(add_coverage) -export(add_coverage_raw_data) export(add_pairwise_comparison) export(ae_median_quantile) export(ae_median_sample) diff --git a/R/add_coverage.R b/R/add_coverage.R deleted file mode 100644 index 239c27244..000000000 --- a/R/add_coverage.R +++ /dev/null @@ -1,139 +0,0 @@ -#' @title Add Coverage of Central Prediction Intervals to Forecasts -#' -#' @description Adds a column with the coverage of central prediction intervals -#' to a data.table with forecasts either in a quantile or in a sample-based -#' format (following the input requirements of `score()`). -#' -#' Coverage for a given interval range is defined as the proportion of -#' observations that fall within the corresponding central prediction intervals. -#' Central prediction intervals are symmetric around the median and and formed -#' by two quantiles that denote the lower and upper bound. For example, the 50% -#' central prediction interval is the interval between the 0.25 and 0.75 -#' quantiles of the predictive distribution. -#' -#' The coverage values that are added are computed according to the values -#' specified in `by`. If, for example, `by = "model"`, then there will be one -#' coverage value for every model. If `by = c("model", "target_type")`, then -#' there will be one coverage value for every combination of model and target -#' type. -#' -#' @inheritParams score -#' @param by character vector with column names to add the coverage for. -#' @param ranges numeric vector of the ranges of the central prediction intervals -#' for which coverage values shall be added. Ranges should be given as -#' percentages. For example, `ranges = c(50, 90)` -#' will add coverage values for the 50% and 90% central prediction intervals ( -#' corresponding to the 0.05, 0.25, 0.75 and 0.95 quantiles of the predictive -#' distribution). -#' @return a data.table with with columns added for the -#' coverage of the central prediction intervals. While the overall data.table -#' is still unsummarised, note that for the coverage columns some level of -#' summary is present according to the value specified in `by`. -#' @examples -#' library(magrittr) # pipe operator -#' example_quantile %>% -#' add_coverage_raw_data(by = c("model", "target_type")) -#' @export -#' @keywords scoring -#' @export -add_coverage_raw_data <- function(data, - by = NULL, - ranges = c(50, 90)) { - UseMethod("add_coverage_raw_data") -} - -#' @description -#' `add_coverage_raw_data.default()` validates the input data, -#' checks the forecast type and calls `add_coverage_raw_data()` again to -#' dispatch to the appropriate method. -#' @rdname add_coverage_raw_data -#' @export -add_coverage_raw_data.default <- function(data, - by = NULL, - ranges = c(50, 90)) { - data <- validate(data) - add_coverage_raw_data(data, by = by, ranges = ranges) -} - -#' @rdname add_coverage_raw_data -#' @export -add_coverage_raw_data.scoringutils_quantile <- function(data, - by = NULL, - ranges = c(50, 90)) { - stored_attributes <- get_scoringutils_attributes(data) - data <- remove_na_observed_predicted(data) - - if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { - by <- stored_attributes[["scoringutils_by"]] - } else if (is.null(by)) { - # Need to check this again. - # (mentioned in https://github.com/epiforecasts/scoringutils/issues/346) - by <- get_forecast_unit(data) - } - - interval_data <- quantile_to_interval(data, format = "wide") - interval_data[, coverage := ifelse(observed <= upper & observed >= lower, 1, 0)] # nolint - interval_data[, coverage_deviation := coverage - range / 100] - - summarised <- interval_data[, .(coverage = mean(coverage), - coverage_deviation = mean(coverage_deviation)), - by = c(by, "range")][range %in% ranges] - - cast_formula <- - paste( - paste(by, collapse = "+"), - "~", - "paste0('coverage_', range)" - ) - - coverages <- dcast( - summarised, - value.var = "coverage", - formula = cast_formula - ) - - data_with_coverage <- merge(data, coverages, by = by) - data_with_coverage <- assign_attributes( - data_with_coverage, stored_attributes - ) - - return(data_with_coverage[]) -} - -#' @rdname add_coverage_raw_data -#' @export -add_coverage_raw_data.scoringutils_sample <- function(data, - by = NULL, - ranges = c(50, 90)) { - stored_attributes <- get_scoringutils_attributes(data) - data <- remove_na_observed_predicted(data) - if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { - by <- stored_attributes[["scoringutils_by"]] - } else if (is.null(by)) { - # Need to check this again. - # (mentioned in https://github.com/epiforecasts/scoringutils/issues/346) - by <- get_forecast_unit(data) - } - - lower_quantiles <- (100 - ranges) / 200 - upper_quantiles <- 1 - lower_quantiles - quantiles <- sort(c(lower_quantiles, upper_quantiles)) - - quantile_format <- sample_to_quantile(data, quantiles = quantiles, type = 7) - - coverages <- add_coverage_raw_data.scoringutils_quantile( - quantile_format, - by = by, - ranges = ranges - ) - - coverages <- unique( - coverages[, c("quantile", "predicted", "observed") := NULL] - ) - - data_with_coverage <- merge(data, coverages, by = by) - data_with_coverage <- assign_attributes( - data_with_coverage, stored_attributes - ) - return(data_with_coverage[]) -} diff --git a/man/add_coverage_raw_data.Rd b/man/add_coverage_raw_data.Rd deleted file mode 100644 index 214290e81..000000000 --- a/man/add_coverage_raw_data.Rd +++ /dev/null @@ -1,63 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/add_coverage.R -\name{add_coverage_raw_data} -\alias{add_coverage_raw_data} -\alias{add_coverage_raw_data.default} -\alias{add_coverage_raw_data.scoringutils_quantile} -\alias{add_coverage_raw_data.scoringutils_sample} -\title{Add Coverage of Central Prediction Intervals to Forecasts} -\usage{ -add_coverage_raw_data(data, by = NULL, ranges = c(50, 90)) - -\method{add_coverage_raw_data}{default}(data, by = NULL, ranges = c(50, 90)) - -\method{add_coverage_raw_data}{scoringutils_quantile}(data, by = NULL, ranges = c(50, 90)) - -\method{add_coverage_raw_data}{scoringutils_sample}(data, by = NULL, ranges = c(50, 90)) -} -\arguments{ -\item{data}{A data.frame or data.table with predicted and observed values.} - -\item{by}{character vector with column names to add the coverage for.} - -\item{ranges}{numeric vector of the ranges of the central prediction intervals -for which coverage values shall be added. Ranges should be given as -percentages. For example, \code{ranges = c(50, 90)} -will add coverage values for the 50\% and 90\% central prediction intervals ( -corresponding to the 0.05, 0.25, 0.75 and 0.95 quantiles of the predictive -distribution).} -} -\value{ -a data.table with with columns added for the -coverage of the central prediction intervals. While the overall data.table -is still unsummarised, note that for the coverage columns some level of -summary is present according to the value specified in \code{by}. -} -\description{ -Adds a column with the coverage of central prediction intervals -to a data.table with forecasts either in a quantile or in a sample-based -format (following the input requirements of \code{score()}). - -Coverage for a given interval range is defined as the proportion of -observations that fall within the corresponding central prediction intervals. -Central prediction intervals are symmetric around the median and and formed -by two quantiles that denote the lower and upper bound. For example, the 50\% -central prediction interval is the interval between the 0.25 and 0.75 -quantiles of the predictive distribution. - -The coverage values that are added are computed according to the values -specified in \code{by}. If, for example, \code{by = "model"}, then there will be one -coverage value for every model. If \code{by = c("model", "target_type")}, then -there will be one coverage value for every combination of model and target -type. - -\code{add_coverage_raw_data.default()} validates the input data, -checks the forecast type and calls \code{add_coverage_raw_data()} again to -dispatch to the appropriate method. -} -\examples{ -library(magrittr) # pipe operator -example_quantile \%>\% - add_coverage_raw_data(by = c("model", "target_type")) -} -\keyword{scoring} From 96e295c6c89a74b60fcb50e7a7dbc5a95143a259 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 7 Nov 2023 19:52:27 +0100 Subject: [PATCH 22/81] correct error with warning by reverting to old `warning()` :( --- R/metrics-quantile.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 018d9d323..5f45426ab 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -92,7 +92,7 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 assert_number(range) necessary_quantiles <- c((100 - range) / 2, 100 - (100 - range) / 2) / 100 if (!all(necessary_quantiles %in% quantile)) { - rlang::warn( + warning( "To compute the coverage for a range of ", range, "%, the quantiles ", necessary_quantiles, " are required. Returnting `NA`.") return(NA) From c81c14c9070dc75072ffcd4834a368e0fbddbe33 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Wed, 8 Nov 2023 15:15:47 +0100 Subject: [PATCH 23/81] Create helper function `run_safely()` to safely execute another function --- NAMESPACE | 1 + R/utils.R | 50 +++++++++++++++++++++++++ data/metrics_quantile.rda | Bin 6157 -> 6444 bytes inst/create-list-available-forecasts.R | 4 +- man/run_safely.Rd | 35 +++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 man/run_safely.Rd diff --git a/NAMESPACE b/NAMESPACE index d4c50d141..f29d00f38 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -57,6 +57,7 @@ export(plot_ranges) export(plot_score_table) export(plot_wis) export(quantile_score) +export(run_safely) export(sample_to_quantile) export(score) export(se_mean_sample) diff --git a/R/utils.R b/R/utils.R index c0c0a34e1..551d2e7d8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -200,3 +200,53 @@ remove_scoringutils_class <- function(object) { } return(object) } + +#' @title Run a function safely +#' @description This is a wrapper function designed to run a function safely +#' when it is not completely clear what arguments coulld be passed to the +#' function. +#' +#' All named arguments in `...` that are not accepted by `fun` are removed. +#' All unnamed arguments are passed on to the function. In case `fun` errors, +#' the error will be converted to a warning and `run_safely` returns `NULL`. +#' +#' `run_safely` can be useful when constructing functions to be used as +#' metrics in [score()]. +#' +#' @param ... Arguments to pass to `fun` +#' @param fun A function to execute +#' @return The result of `fun` or `NULL` if `fun` errors +#' @export +#' @examples +#' f <- function(x) {x} +#' run_safely(2, fun = f) +#' run_safely(2, y = 3, fun = f) +#' run_safely(fun = f) +#' run_safely(y = 3, fun = f) +run_safely <- function(..., fun) { + args <- list(...) + # Check if the function accepts ... as an argument + if ("..." %in% names(formals(fun))) { + valid_args <- args + } else if (is.null(names(args))) { + # if no arguments are named, just pass all arguments on + valid_args <- args + } else { + # Identify the arguments that fun() accepts + possible_args <- names(formals(fun)) + # keep valid arguments as well as unnamed arguments + valid_args <- args[names(args) == "" | names(args) %in% possible_args] + } + + result <- try(do.call(fun, valid_args)) + + if (inherits(result, "try-error")) { + msg <- conditionMessage(attr(result, "condition")) + warning( + "Function execution failed, returnin NULL. Error: \n", + msg + ) + return(NULL) + } + return(result) +} diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index 88945fc57c6d2801e975ab595888b9ce73cd221b..bd1f387a60be5cc544406be3245785bd7b590eaf 100644 GIT binary patch literal 6444 zcmZvYWmppo!$wDsnrwt4B{q-|($YD`=te@6cB4T+Ku|z(Fk-|*OKb=u9zu|oZcrE{ zC`c%wAg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KgnV6fpeD$B&+PktCtFJtc9H88SE!o99@if@V!v5sn5p z3|J=-qd>$2Gqh|burLdi!NZZZi6rkh6u%3wllN{4{}=h}@Fr6gkkB~f4N z3{I_>Z|8w7f(ojrxc%*$5QSA9qBe!0s?u?ZQRgGm?Lru$541@m|PD7WPCUi$sVgUMj>wD43w29@~Tj3)vSdR)Dp`= z0i#ouc2naGYHQU^TLwNLYM&oAlT#iP4W3O9$0wNc}2lYP^0nr)p635< zRyG?B-Mh@R=gQm7)q%{|^j5^4bjfM0XOD9#%>D+t*JA{=&%Nvy?M?r3A+`Tm&d=*% zOv)Q*ciU_3-^$U@#=6_^sdO~R@~$qAXtwSAR7CnzHf+_fjR=8)ThNpEL;BFLy|-LQ fNM~G11#TxY`a?*N3RMCA|BJaIoG3^gg Date: Wed, 8 Nov 2023 15:28:15 +0100 Subject: [PATCH 24/81] Update `run_safely()` and add tests --- R/utils.R | 5 +++-- tests/testthat/test-utils.R | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 551d2e7d8..3de1a9eb8 100644 --- a/R/utils.R +++ b/R/utils.R @@ -238,15 +238,16 @@ run_safely <- function(..., fun) { valid_args <- args[names(args) == "" | names(args) %in% possible_args] } - result <- try(do.call(fun, valid_args)) + result <- try(do.call(fun, valid_args), silent = TRUE) if (inherits(result, "try-error")) { msg <- conditionMessage(attr(result, "condition")) warning( - "Function execution failed, returnin NULL. Error: \n", + "Function execution failed, returning NULL. Error: ", msg ) return(NULL) } return(result) } + diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index a909c7d46..5d8b37c3f 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -36,6 +36,19 @@ test_that("get_protected_columns() returns the correct result", { }) +test_that("run_safely() works as expected", { + f <- function(x) {x} + expect_equal(run_safely(2, fun = f), 2) + expect_equal(run_safely(2, y = 3, fun = f), 2) + expect_warning( + run_safely(fun = f), + 'Function execution failed, returning NULL. Error: argument "x" is missing, with no default', + fixed = TRUE + ) + expect_equal(suppressWarnings(run_safely(y = 3, fun = f)), NULL) +}) + + # test_that("prediction_is_quantile() correctly identifies quantile predictions", { # data <- data.frame( # predicted = 1:3, From bd8984b9459f6c8d4bf310cbbb6f36ff6f4ff4cd Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Wed, 8 Nov 2023 15:29:18 +0100 Subject: [PATCH 25/81] Update `metrics_quantile` to include coverage --- data/metrics_quantile.rda | Bin 6444 -> 6149 bytes inst/create-list-available-forecasts.R | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index bd1f387a60be5cc544406be3245785bd7b590eaf..c0217df2cd94171bd8e299d949b5b94cabfc853c 100644 GIT binary patch literal 6149 zcmV+g82aZzT4*^jL0KkKS@Y!M6aY$M|NsC0|NsC0|NsC0|Ly<(|Nr?1|Nr~{|Nr`E z3Hk4R{D0sYz49(CZJvFvTkZoRT2ZYAr~plQ_d!TYcKU4hKmY&=Xbc+q8yjJhO#mNe z33zDuJq_^E6x8-nqF|KpdPb+FO%do~Q}s^+RN9+Nqtx|1M$|S;DB7MWrS!7V zq5uE@0000000E!?02!zxlqOPQX`!GE8X9_rjG6!d8fl0C001=500003KmZy500000 z00000i6kINlM_ut(?ru~r|GI`h#sR)X#-PDG|{G-X`!Gr(V)-+Kn(*xGynhwng9R* zXaE2J^nuT)h8+^1c-}?=0lTtBBB@i%mz{*`uBJy3tUbe-C0wZl&vw2yJFwVn%((hyo68Ei{s*A8L#pk^Dv2qW z>e3i)P8QC84Y8_G5s>5&6jc>eF&5szokla2;eW5)7XUEfaP-EqS{;+9`&&X`%wEc; zlps`!y20J=vTK{#CL?^iMEZDmlU&L&o7y7bnZPoi<|k5k!d9g7EJi^uHE$=jjpqc|%af1LZ-uf3Kv09j1H%!uF~ z9%RfhhkI@41FGfEZ)wM|g-vchdDrN0!fH&LjXP~j_hE)AJM?Tsj6y~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|0^h@(llZu7vUGB`~wDWwd&Dsn6CmjuEP-vB}o|5Gjs+ zjw(6N!HxBNVi{1c>fu^A*tEY?c6vl7Gl<-hE%Qjd)Ay&9yS3M@+c4fhZl?P6iqfTK yx<`dTbD>$QIS>EqqXzcCE@^Z%aY5k@vux*iL7lpPfd$Q#^Ek(buATu%i1>dUtg!_E diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index f47fe1084..66d5b26c2 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -25,7 +25,7 @@ usethis::use_data(metrics_sample, overwrite = TRUE) metrics_quantile <- list( "wis" = wis, "bias" = bias_quantile, - "coverage_50" = function(...) {interval_coverage_quantile(..., range = 50)}, - "coverage_90" = function(...) {interval_coverage_quantile(..., range = 90)}, + "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)}, + "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} ) usethis::use_data(metrics_quantile, overwrite = TRUE) From 7e9fbdbb4619987f879c4bee8eebf6213c31b953 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 9 Nov 2023 13:26:32 +0100 Subject: [PATCH 26/81] rework bias_quantile to work with vectors and matrices again instead of data.table --- R/metrics-quantile.R | 78 +++++++++++++++++++++++--------------- tests/testthat/test-bias.R | 4 ++ 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 5f45426ab..4f3774a96 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -149,6 +149,7 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 #' which predictions were made. If this does not contain the median (0.5) then #' the median is imputed as being the mean of the two innermost quantiles. #' @inheritParams bias_range +#' @param na.rm logical. Should missing values be removed? #' @return scalar with the quantile bias for a single quantile prediction #' @author Nikos Bosse \email{nikosbosse@@gmail.com} #' @examples @@ -167,69 +168,84 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 #' bias_quantile(observed, predicted, quantile) #' @export #' @keywords metric - -bias_quantile <- function(observed, predicted, quantile) { - +bias_quantile <- function(observed, predicted, quantile, na.rm = TRUE) { assert_input_quantile(observed, predicted, quantile) - n <- length(observed) N <- length(quantile) - - dt <- data.table( - forecast_id = rep(1:n, each = N), - observed = rep(observed, each = N), - predicted = as.vector(t(predicted)), - quantile = quantile - )[order(forecast_id, quantile)] - - dt <- dt[, .(bias = bias_quantile_single(.SD)), by = forecast_id] - - return(dt$bias) + if (is.null(dim(predicted))) { + dim(predicted) <- c(n, N) + } + bias <- sapply(1:n, function(i) { + bias_quantile_single_vector(observed[i], predicted[i,], quantile, na.rm) + }) + return(bias) } -bias_quantile_single <- function(dt) { +#' Compute Bias for a Single Vector of Quantile Predictions +#' @description Internal function to compute bias for a single observed value, +#' a vector of predicted values and a vector of quantiles. +#' @param observed scalar with the observed value +#' @param predicted vector of length N corresponding to the number of quantiles +#' that holds predictions +#' @param quantile vector of corresponding size N with the quantile levels for +#' which predictions were made. If this does not contain the median (0.5) then +#' the median is imputed as being the mean of the two innermost quantiles. +#' @inheritParams bias_quantile +#' @return scalar with the quantile bias for a single quantile prediction +bias_quantile_single_vector <- function(observed, predicted, quantile, na.rm) { - dt <- dt[!is.na(quantile) & !is.na(predicted)] + assert_number(observed) + # other checks should have happend before - observed <- unique(dt$observed) + predicted_has_NAs <- anyNA(predicted) + quantile_has_NAs <- anyNA(quantile) - if (nrow(dt) == 0) { - return(NA_real_) + if(any(predicted_has_NAs, quantile_has_NAs)) { + if (!na.rm) { + return(NA_real_) + } else { + quantile <- quantile[!is.na(predicted)] + predicted <- predicted[!is.na(predicted)] + predicted <- predicted[!is.na(quantile)] + quantile <- quantile[!is.na(quantile)] + } } - if (!all(diff(dt$predicted) >= 0)) { + order <- order(quantile) + predicted <- predicted[order] + if (!all(diff(predicted) >= 0)) { stop("Predictions must not be decreasing with increasing quantile level") } - if (0.5 %in% dt$quantile) { - median_prediction <- dt[quantile == 0.5]$predicted + if (0.5 %in% quantile) { + median_prediction <- predicted[quantile == 0.5] } else { - # if median is not available, compute as mean of two innermost quantiles + # if median is not available, compute as mean of two innermost quantile message( - "Median not available, computing as mean of two innermost quantiles", + "Median not available, computing as mean of two innermost quantile", " in order to compute bias." ) median_prediction <- - 0.5 * dt[quantile == max(quantile[quantile < 0.5])]$predicted + - 0.5 * dt[quantile == min(quantile[quantile > 0.5])]$predicted + 0.5 * predicted[quantile == max(quantile[quantile < 0.5])] + + 0.5 * predicted[quantile == min(quantile[quantile > 0.5])] } if (observed == median_prediction) { bias <- 0 return(bias) } else if (observed < median_prediction) { - if (observed < min(dt$predicted)) { + if (observed < min(predicted)) { bias <- 1 } else { - q <- max(dt[predicted <= observed]$quantile) + q <- max(quantile[predicted <= observed]) bias <- 1 - 2 * q } } else if (observed > median_prediction) { - if (observed > max(dt$predicted)) { + if (observed > max(predicted)) { bias <- -1 } else { - q <- min(dt[predicted >= observed]$quantile) + q <- min(quantile[predicted >= observed]) bias <- 1 - 2 * q } } diff --git a/tests/testthat/test-bias.R b/tests/testthat/test-bias.R index b1e59fd6d..42eefa34f 100644 --- a/tests/testthat/test-bias.R +++ b/tests/testthat/test-bias.R @@ -129,6 +129,10 @@ test_that("bias_quantile() handles NA values", { bias_quantile(observed = 2, predicted, quantiles), -1 ) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles, na.rm = FALSE), + NA_real_ + ) }) test_that("bias_quantile() errors if no predictions", { From e596c4f4a55858df8daa4ed3dbd4402d23237f4f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 9 Nov 2023 13:28:57 +0100 Subject: [PATCH 27/81] Update `metrics_quantile` + some documentation --- R/data.R | 4 +++- data/metrics_quantile.rda | Bin 6149 -> 11747 bytes man/bias_quantile.Rd | 4 +++- man/bias_quantile_single_vector.Rd | 27 +++++++++++++++++++++++++++ man/metrics_quantile.Rd | 22 ++++++++++++++++++++++ man/metrics_sample.Rd | 10 ---------- 6 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 man/bias_quantile_single_vector.Rd create mode 100644 man/metrics_quantile.Rd diff --git a/R/data.R b/R/data.R index 9c5569646..48548ffed 100644 --- a/R/data.R +++ b/R/data.R @@ -217,5 +217,7 @@ #' A named list with functions: #' - "wis" = [wis()] #' - "bias" = [bias_quantile()] +#' - "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)} #nolint +#' - "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} #nolint #' @keywords info -"metrics_sample" +"metrics_quantile" diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index c0217df2cd94171bd8e299d949b5b94cabfc853c..f1e231d773161dc0df58ab5efd8fb8ca1a0741fc 100644 GIT binary patch literal 11747 zcmV<9EgaH9T4*^jL0KkKSuAMxy8y#1fB*mg|NsC0|NsC0|NsC0|NsC0|Np=L|Nrf8 z|NsC0|Nr1NTzrS6-R^?%&vz(B-+9(<+vlCbfabk7GcT?-H`~s|wdZA}JE$6orfRCT z-OhHI?%#YipaP7P*@EZAPW#iFpK<2S01rR_000UF0049*ytLwa7k4}Cc-R7>6dLqs zb-mr^qLKjjkop+_^V0B1BoQ#083RBXWB>q$CMoJ>qY1Q)H9Rz_{-)BWrl#1Y8dLR8 z(^UN)ik?qY@CiJV^)hLM^))>-o~G1zliC#gsgu%po~infdQVKJsM<}G^*p0#sM=vo zU6Ovw^s6C+8cCPqdL2Br~+!2=Ub8)Bw-{rh_M_Y@h~*r~n3l&;V!;D9``_pa-ZuKr#RTM5G`z5M%&NF)>W1vYx5r z#Z8p-+NYq?B6>AFBSzF|w2x7t>SQ!+BTWDR003wJWDNiS0iXZ?007VfNPOUc%1VHL z=wk?>??3&3sYrp!K}?m@3S=*vjD$){%;ExMp%5WdFU87pJb?7E?0Ce*K<3fj$Ch`W z6W!EFT#=A0pnGJrKo3R#a5I2o&8X8q`+{q__ysDdZPFb%6zXGjcBCY+-TWd>uh&ya`)hBq}k zMiai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ET&nSPldL#B;Ql zt_wM!2iDrBPkoKQ^E8t8^!-t|wmW{5xS8U#LM0p5HzXQRH*0}5#@iy6-JRp!?R#y0 z{aBk=y+=7ZUac&5+^HC9RNAt|fFeP3gki%E$@n?0_%$>Vtr!_$qvMbf1R{b}LBME* z+QN1>p>YKPh&z$86XD1kG1T=Rmab1U!ys%_Lol6+Z0e#5EVh}1{R6}hd?A^sw(r5# zsjwQv`;hh?c)9!^_>oWJwpi?+20@l z07oICMc*`77>L@AMi?Puu(F)Eqg%2<5R57}wZhatlfID`cy|sQeA?>)RkF&j6?Qh8 z0N;@`HP)%*_YTtkN4K`VfGx9j+eCZwpFQkFzqIM`ur)JM;~FL|HZJEX94fod2gHpA zIXRP24|F!I5}8B`_C?3_Qu;~cU}N;T2zK{&bXMl)BTQ6!2neD`OgQs{sYa7FX*}hx X4>phrbUm&hcm6Kqig2MJ=gGz>sKyLa diff --git a/man/bias_quantile.Rd b/man/bias_quantile.Rd index 4cbeb0338..a5f4b6492 100644 --- a/man/bias_quantile.Rd +++ b/man/bias_quantile.Rd @@ -4,7 +4,7 @@ \alias{bias_quantile} \title{Determines Bias of Quantile Forecasts} \usage{ -bias_quantile(observed, predicted, quantile) +bias_quantile(observed, predicted, quantile, na.rm = TRUE) } \arguments{ \item{observed}{a single observed value} @@ -15,6 +15,8 @@ that holds predictions} \item{quantile}{vector of corresponding size with the quantile levels for which predictions were made. If this does not contain the median (0.5) then the median is imputed as being the mean of the two innermost quantiles.} + +\item{na.rm}{logical. Should missing values be removed?} } \value{ scalar with the quantile bias for a single quantile prediction diff --git a/man/bias_quantile_single_vector.Rd b/man/bias_quantile_single_vector.Rd new file mode 100644 index 000000000..26ac893b5 --- /dev/null +++ b/man/bias_quantile_single_vector.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics-quantile.R +\name{bias_quantile_single_vector} +\alias{bias_quantile_single_vector} +\title{Compute Bias for a Single Vector of Quantile Predictions} +\usage{ +bias_quantile_single_vector(observed, predicted, quantile, na.rm) +} +\arguments{ +\item{observed}{scalar with the observed value} + +\item{predicted}{vector of length N corresponding to the number of quantiles +that holds predictions} + +\item{quantile}{vector of corresponding size N with the quantile levels for +which predictions were made. If this does not contain the median (0.5) then +the median is imputed as being the mean of the two innermost quantiles.} + +\item{na.rm}{logical. Should missing values be removed?} +} +\value{ +scalar with the quantile bias for a single quantile prediction +} +\description{ +Internal function to compute bias for a single observed value, +a vector of predicted values and a vector of quantiles. +} diff --git a/man/metrics_quantile.Rd b/man/metrics_quantile.Rd new file mode 100644 index 000000000..e96dcc836 --- /dev/null +++ b/man/metrics_quantile.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{metrics_quantile} +\alias{metrics_quantile} +\title{Default metrics for quantile-based forecasts.} +\format{ +An object of class \code{list} of length 4. +} +\usage{ +metrics_quantile +} +\description{ +A named list with functions: +\itemize{ +\item "wis" = \code{\link[=wis]{wis()}} +\item "bias" = \code{\link[=bias_quantile]{bias_quantile()}} +\item "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)} #nolint +\item "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} #nolint +} +} +\keyword{info} diff --git a/man/metrics_sample.Rd b/man/metrics_sample.Rd index 90aa265f7..5231f4ae7 100644 --- a/man/metrics_sample.Rd +++ b/man/metrics_sample.Rd @@ -5,13 +5,9 @@ \alias{metrics_sample} \title{Default metrics for sample-based forecasts.} \format{ -An object of class \code{list} of length 7. - An object of class \code{list} of length 7. } \usage{ -metrics_sample - metrics_sample } \description{ @@ -26,11 +22,5 @@ A named list with functions: \item "ae_median" = \code{\link[=ae_median_sample]{ae_median_sample()}} \item "se_mean" = \code{\link[=se_mean_sample]{se_mean_sample()}} } - -A named list with functions: -\itemize{ -\item "wis" = \code{\link[=wis]{wis()}} -\item "bias" = \code{\link[=bias_quantile]{bias_quantile()}} -} } \keyword{info} From 4ea595204b187a2f374d9303537f67bf2263ed22 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 9 Nov 2023 14:27:30 +0100 Subject: [PATCH 28/81] add three functions for overprediction, underprediction and dispersion --- NAMESPACE | 3 +++ R/metrics-quantile.R | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index f29d00f38..fab2e17d3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -29,6 +29,7 @@ export(bias_sample) export(brier_score) export(correlation) export(crps_sample) +export(dispersion) export(dss_sample) export(get_duplicate_forecasts) export(interval_coverage_quantile) @@ -42,6 +43,7 @@ export(make_NA) export(make_na) export(merge_pred_and_obs) export(new_scoringutils) +export(overprediction) export(pairwise_comparison) export(pit) export(pit_sample) @@ -67,6 +69,7 @@ export(summarise_scores) export(summarize_scores) export(theme_scoringutils) export(transform_forecasts) +export(underprediction) export(validate) export(validate_general) export(wis) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 4f3774a96..e7e6fbfed 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -62,6 +62,27 @@ wis <- function(observed, } } +#' @export +#' @rdname wis +dispersion <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + wis(observed, predicted, quantile, separate_results = TRUE)$dispersion +} + +#' @export +#' @rdname wis +overprediction <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + wis(observed, predicted, quantile, separate_results = TRUE)$overprediction +} + +#' @export +#' @rdname wis +underprediction <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + wis(observed, predicted, quantile, separate_results = TRUE)$underprediction +} + #' @title Interval Coverage (For Quantile-Based Forecasts) #' @description Check whether the observed value is within a given central From 4c075674c25bb3d632b880069b3dbf0c4b519123 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 9 Nov 2023 15:41:34 +0100 Subject: [PATCH 29/81] Update `metrics_quantile` --- data/metrics_quantile.rda | Bin 11747 -> 6730 bytes inst/create-list-available-forecasts.R | 3 +++ 2 files changed, 3 insertions(+) diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index f1e231d773161dc0df58ab5efd8fb8ca1a0741fc..2f2607933179842f7fcdb9c19e8ef140fe59117d 100644 GIT binary patch literal 6730 zcmV-Q8nxv@T4*^jL0KkKStp_Q;{aPpfB*mg|NsC0|NsC0|NQ^||Nr@i|Nr~{|Nj5~ zG2|Oqxfj>VBmCQ1sGz6GKKI(@g=RKmnsoG-5OWGyuqHq3Hm@ z8Z-ug(@jJwJyX$6(z(#=6O$<#m zG#NB#XwYQSOc8|B6GluSN>eF>n5U+YVj43@10ZPAL690502%-^0D6D`$N&HafDHkl z000000000D0x2qFn^by7rYY((O+k}Jm?lO~LNw4aF*MT?Mg%fo1kr?fModjK4Ff>J zWW-=hO)v?B(GZGZ55a_r0}$;w($Wz)v`B&}|8e3=hA6 zl$OenA3A^YYL}h z6AMfnf}$vhs-d>J=H8riX{Q(de_UpWQN74)Q6)yDLFOCYXU}yX*UbRV9d>4_6fCEr zav){|jNnJlk`ZVbJo2`ZIR@374u3P6s#fq+Udpgw)K>T&T=3lHbHOzvBp!+Zd7S4z z8bGpU6Rd0v8P`;hQ^mqii0QU91!E{~$V;&h8-CbMKGz~x$$%`YTxGt^u;sRiL9$lo zKK9_;w0Lc>)p{)K@@&p@)bl zq?mQ+V^&UO31JCP4p3?DEYY5im*Ux@%b=>19Ugm*({XDXDBR!&1#lmWV z>5yyFA0-K|oXyA%b_CWyY{|QWTyt}(qL-TOSSCj^F5Sy)=DUu!`&oC~ciYU|AT<#L z?p(&0@T_Ts^N?U5v5f4D8VpS{hhh(vA_z_{NUykZO=47}LPwB@!SV&jmFcDGXTmZx z^y%9Am^~@Ckc_VL-RP^%5?~penUqL_REU5ifUyxnJ|>rovCG%~JU{R4Gx)MO&JZCK z*QId#^aHSo%lHu$d0ARTpr(M5Sbd3IAwm#+`Vi-g?#K)QM8c6L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;x z!L_yG@Kc`CRr|jWdB*%6Z{_(t-&^x*Eb?&=CYHl*()k^=hDV#Z(6-^)($Yow%`3Os z=5d-&m3dDCtlv9BU&{5byVNI-`O^z%F?;20BQdc1G~ zcW=aWni*=Sb6&p#{4d1&@4oj;&%XbKnOUM}Z_UNGv1zQPJ+|%{t31d~Jh_cCv-dCd zT<31g$M!Cy^jr9ux43!!kIx~`BkkGmrQP?1PNRjX;+3#=9e46ocGfv`ll!TBnO~Ct z?4`@%!CQZO4ta zl}}?$8cd&JMxWY-pN(bOztYJ0J*$g Date: Thu, 9 Nov 2023 15:42:26 +0100 Subject: [PATCH 30/81] remove hack in the new `score.scoringutils_quantile_new` proposal that deals with the wis components --- R/score.R | 5 ----- 1 file changed, 5 deletions(-) diff --git a/R/score.R b/R/score.R index e4290287f..3d1dc7f07 100644 --- a/R/score.R +++ b/R/score.R @@ -295,11 +295,6 @@ score.scoringutils_quantile_new <- function(data, metrics = metrics_quantile, .. fun <- metrics[[i]] matching_args <- filter_function_args(fun, args) - if ("separate_results" %in% names(matching_args) && - matching_args$separate_results) { - metric_name <- c(metric_name, "dispersion", "underprediction", "overprediction") - } - data[, eval(metric_name) := do.call( fun, c(list(observed), list(predicted), list(quantile), matching_args) )] From 32239bf8220db7edad5584afcc4a55255dc0cd9d Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Thu, 9 Nov 2023 15:42:59 +0100 Subject: [PATCH 31/81] Update documentation for `wis()` and its components --- R/metrics-quantile.R | 92 +++++++++++++++++++++++++++++++++++++- man/metrics_quantile.Rd | 2 +- man/wis.Rd | 98 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 188 insertions(+), 4 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index e7e6fbfed..f3598690e 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -2,13 +2,92 @@ # Metrics with a many-to-one relationship between input and score ################################################################################ -#' Weighted Interval Score +#' Weighted Interval Score (WIS) +#' @description +#' The WIS is a proper scoring rule used to evaluate forecasts in an interval- / +#' quantile-based format. See Bracher et al. (2021). Smaller values are better. +#' +#' As the name suggest the score assumes that a forecast comes in the form of +#' one or multiple central prediction intervals. A prediction interval is +#' characterised by a lower and an upper bound formed by a pair of predictive +#' quantiles. For example, a 50% central prediction interval is formed by the +#' 0.25 and 0.75 quantiles of the predictive distribution. +#' +#' **Interval score** +#' +#' The interval score (IS) is the sum of three components: +#' overprediction, underprediction and dispersion. For a single prediction +#' interval only one of the components is non-zero. If for a single prediction +#' interval the observed value is below the lower bound, then the interval +#' score is equal to the absolute difference between the lower bound and the +#' observed value ("underprediction"). "Overprediction" is defined analogously. +#' If the observed value falls within the bounds of the prediction interval, +#' then the interval score is equal to the width of the prediction interval, +#' i.e. the difference between the upper and lower bound. For a single interval, +#' we therefore have: +#' +#' \deqn{ +#' \textrm{IS} = (\textrm{upper} - \textrm{lower}) + \frac{2}{\alpha}(\textrm{lower} +#' - \textrm{observed}) * +#' \mathbf{1}(\textrm{observed} < \textrm{lower}) + +#' \frac{2}{\alpha}(\textrm{observed} - \textrm{upper}) * +#' \mathbf{1}(\textrm{observed} > \textrm{upper}) +#' }{ +#' score = (upper - lower) + 2/alpha * (lower - observed) * +#' 1(observed < lower) + 2/alpha * (observed - upper) * +#' 1(observed > upper) +#' } +#' where \eqn{\mathbf{1}()}{1()} is the indicator function and +#' indicates how much is outside the prediction interval. +#' \eqn{\alpha}{alpha} is the decimal value that indicates how much is outside +#' the prediction interval. For a 90% prediction interval, for example, +#' \eqn{\alpha}{alpha} is equal to 0.1. No specific distribution is assumed, +#' but the range has to be symmetric (i.e you can't use the 0.1 quantile +#' as the lower bound and the 0.7 quantile as the upper). +#' Non-symmetric quantiles can be scored using the function [quantile_score()]. +#' +#' Usually the interval score is weighted by a factor that makes sure that the +#' average score across an increasing number of equally spaced +#' quantiles, converges to the continuous ranked probability score (CRPS). This +#' weighted score is called the weihted interval score (WIS). +#' The weight commonly used is \eqn{\alpha / 2}{alpha / 2}. +#' +#' **Quantile score** +#' +#' In addition to the interval score, there also exists a quantile score (QS) +#' (see [quantile_score()]), which is equal to the so-called pinball loss. +#' The quantile score can be computed for a single quantile (whereas the +#' interval score requires two quantiles that form an interval). However, +#' the intuitive decomposition into overprediction, underprediction and +#' dispersion does not exist for the quantile score. +#' +#' **Two versions of the weighted interval score** +#' +#' There are two ways to conceptualise the weighted interval score across +#' several quantiles / prediction intervals and the median. +#' +#' In one view, you would treat the WIS as the average of quantile scores (and +#' the median as 0.5-quantile) (this is the default for `wis()`). In another +#' view, you would treat the WIS as the average of several interval scores + +#' the difference between observed value and median forecast. The effect of +#' that is that in contrast to the first view, the median has twice as much +#' weight (because it is weighted like a prediction interval, rather than like +#' a single quantile). Both are valid ways to conceptualise the WIS and you +#' can control the behvaviour with the `count_median_twice`-argument. +#' +#' **WIS components**: +#' WIS components can be computed individually using the functions +#' `overprediction`, `underprediction`, and `dispersion.` +#' #' @inheritParams interval_score #' @param predicted vector of size n with the predicted values #' @param quantile vector with quantile levels of size N #' @param count_median_twice if TRUE, count the median twice in the score #' @param na.rm if TRUE, ignore NA values when computing the score #' @importFrom stats weighted.mean +#' @return +#' `wis()`: a numeric vector with WIS values (one per observation), or a list +#' with separate entries if `separate_results` is `TRUE`. #' @export wis <- function(observed, predicted, @@ -62,6 +141,9 @@ wis <- function(observed, } } + +#' @return +#' `dispersion()`: a numeric vector with dispersion values (one per observation) #' @export #' @rdname wis dispersion <- function(observed, predicted, quantile) { @@ -69,6 +151,10 @@ dispersion <- function(observed, predicted, quantile) { wis(observed, predicted, quantile, separate_results = TRUE)$dispersion } + +#' @return +#' `overprediction()`: a numeric vector with overprediction values (one per +#' observation) #' @export #' @rdname wis overprediction <- function(observed, predicted, quantile) { @@ -76,6 +162,10 @@ overprediction <- function(observed, predicted, quantile) { wis(observed, predicted, quantile, separate_results = TRUE)$overprediction } + +#' @return +#' `underprediction()`: a numeric vector with underprediction values (one per +#' observation) #' @export #' @rdname wis underprediction <- function(observed, predicted, quantile) { diff --git a/man/metrics_quantile.Rd b/man/metrics_quantile.Rd index e96dcc836..9fda39f03 100644 --- a/man/metrics_quantile.Rd +++ b/man/metrics_quantile.Rd @@ -5,7 +5,7 @@ \alias{metrics_quantile} \title{Default metrics for quantile-based forecasts.} \format{ -An object of class \code{list} of length 4. +An object of class \code{list} of length 7. } \usage{ metrics_quantile diff --git a/man/wis.Rd b/man/wis.Rd index fbf8bc6f7..a76b3c35f 100644 --- a/man/wis.Rd +++ b/man/wis.Rd @@ -2,7 +2,10 @@ % Please edit documentation in R/metrics-quantile.R \name{wis} \alias{wis} -\title{Weighted Interval Score} +\alias{dispersion} +\alias{overprediction} +\alias{underprediction} +\title{Weighted Interval Score (WIS)} \usage{ wis( observed, @@ -13,6 +16,12 @@ wis( count_median_twice = FALSE, na.rm = TRUE ) + +dispersion(observed, predicted, quantile) + +overprediction(observed, predicted, quantile) + +underprediction(observed, predicted, quantile) } \arguments{ \item{observed}{A vector with observed values of size n} @@ -36,6 +45,91 @@ Default: \code{TRUE}.} \item{na.rm}{if TRUE, ignore NA values when computing the score} } +\value{ +\code{wis()}: a numeric vector with WIS values (one per observation), or a list +with separate entries if \code{separate_results} is \code{TRUE}. + +\code{dispersion()}: a numeric vector with dispersion values (one per observation) + +\code{overprediction()}: a numeric vector with overprediction values (one per +observation) + +\code{underprediction()}: a numeric vector with underprediction values (one per +observation) +} \description{ -Weighted Interval Score +The WIS is a proper scoring rule used to evaluate forecasts in an interval- / +quantile-based format. See Bracher et al. (2021). Smaller values are better. + +As the name suggest the score assumes that a forecast comes in the form of +one or multiple central prediction intervals. A prediction interval is +characterised by a lower and an upper bound formed by a pair of predictive +quantiles. For example, a 50\% central prediction interval is formed by the +0.25 and 0.75 quantiles of the predictive distribution. + +\strong{Interval score} + +The interval score (IS) is the sum of three components: +overprediction, underprediction and dispersion. For a single prediction +interval only one of the components is non-zero. If for a single prediction +interval the observed value is below the lower bound, then the interval +score is equal to the absolute difference between the lower bound and the +observed value ("underprediction"). "Overprediction" is defined analogously. +If the observed value falls within the bounds of the prediction interval, +then the interval score is equal to the width of the prediction interval, +i.e. the difference between the upper and lower bound. For a single interval, +we therefore have: + +\deqn{ +\textrm{IS} = (\textrm{upper} - \textrm{lower}) + \frac{2}{\alpha}(\textrm{lower} + - \textrm{observed}) * +\mathbf{1}(\textrm{observed} < \textrm{lower}) + +\frac{2}{\alpha}(\textrm{observed} - \textrm{upper}) * +\mathbf{1}(\textrm{observed} > \textrm{upper}) +}{ +score = (upper - lower) + 2/alpha * (lower - observed) * +1(observed < lower) + 2/alpha * (observed - upper) * +1(observed > upper) +} +where \eqn{\mathbf{1}()}{1()} is the indicator function and +indicates how much is outside the prediction interval. +\eqn{\alpha}{alpha} is the decimal value that indicates how much is outside +the prediction interval. For a 90\% prediction interval, for example, +\eqn{\alpha}{alpha} is equal to 0.1. No specific distribution is assumed, +but the range has to be symmetric (i.e you can't use the 0.1 quantile +as the lower bound and the 0.7 quantile as the upper). +Non-symmetric quantiles can be scored using the function \code{\link[=quantile_score]{quantile_score()}}. + +Usually the interval score is weighted by a factor that makes sure that the +average score across an increasing number of equally spaced +quantiles, converges to the continuous ranked probability score (CRPS). This +weighted score is called the weihted interval score (WIS). +The weight commonly used is \eqn{\alpha / 2}{alpha / 2}. + +\strong{Quantile score} + +In addition to the interval score, there also exists a quantile score (QS) +(see \code{\link[=quantile_score]{quantile_score()}}), which is equal to the so-called pinball loss. +The quantile score can be computed for a single quantile (whereas the +interval score requires two quantiles that form an interval). However, +the intuitive decomposition into overprediction, underprediction and +dispersion does not exist for the quantile score. + +\strong{Two versions of the weighted interval score} + +There are two ways to conceptualise the weighted interval score across +several quantiles / prediction intervals and the median. + +In one view, you would treat the WIS as the average of quantile scores (and +the median as 0.5-quantile) (this is the default for \code{wis()}). In another +view, you would treat the WIS as the average of several interval scores + +the difference between observed value and median forecast. The effect of +that is that in contrast to the first view, the median has twice as much +weight (because it is weighted like a prediction interval, rather than like +a single quantile). Both are valid ways to conceptualise the WIS and you +can control the behvaviour with the \code{count_median_twice}-argument. + +\strong{WIS components}: +WIS components can be computed individually using the functions +\code{overprediction}, \code{underprediction}, and \code{dispersion.} } From 31271d33e8a8a091d40f3e9eda150beb8d44db4f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 12:23:23 +0100 Subject: [PATCH 32/81] Add new function, `interval_coverage_deviation_quantile()` - I know the name is terrible --- NAMESPACE | 1 + R/metrics-quantile.R | 86 +++++++++++++++++++++ man/interval_coverage_deviation_quantile.Rd | 70 +++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 man/interval_coverage_deviation_quantile.Rd diff --git a/NAMESPACE b/NAMESPACE index fab2e17d3..32259fd85 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ export(crps_sample) export(dispersion) export(dss_sample) export(get_duplicate_forecasts) +export(interval_coverage_deviation_quantile) export(interval_coverage_quantile) export(interval_coverage_sample) export(interval_score) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index f3598690e..4df7cdcaf 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -218,6 +218,92 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 } +#' @title Interval Coverage Deviation (For Quantile-Based Forecasts) +#' @description Check the agreement between desired and actual interval coverage +#' of a forecast. +#' +#' The function is similar to [interval_coverage_quantile()], +#' but looks at all provided prediction intervals instead of only one. It +#' compares nominal coverage (i.e. the desired coverage) with the actual +#' observed coverage. +#' +#' A central symmetric prediction interval is defined by a lower and an +#' upper bound formed by a pair of predictive quantiles. For example, a 50% +#' prediction interval is formed by the 0.25 and 0.75 quantiles of the +#' predictive distribution. Ideally, a forecaster should aim to cover about +#' 50% of all observed values with their 50% prediction intervals, 90% of all +#' observed values with their 90% prediction intervals, and so on. +#' +#' For every prediction interval, the deviation is computed as the difference +#' between the observed coverage and the nominal coverage +#' For a single observed value and a single prediction interval, +#' coverage is always either 0 or 1. This is not the case for a single observed +#' value and multiple prediction intervals, but it still doesn't make that much +#' sense to compare nominal (desired) coverage and actual coverage for a single +#' observation. In that sense coverage deviation only really starts to make +#' sense as a metric when averaged across multiple observations). +#' +#' Positive values of coverage deviation are an indication for underconfidence, +#' i.e. the forecaster could likely have issued a narrower forecast. Negative +#' values are an indication for overconfidence, i.e. the forecasts were too +#' narrow. +#' +#' \deqn{ +#' \textrm{coverage deviation} = +#' \mathbf{1}(\textrm{observed value falls within interval} - +#' \textrm{nominal coverage}) +#' }{ +#' coverage deviation = +#' 1(observed value falls within interval) - nominal coverage +#' } +#' The coverage deviation is then averaged across all prediction intervals. +#' The median is ignored when computing coverage deviation. +#' @inheritParams wis +#' @return A numeric vector of length n with the coverage deviation for each +#' forecast (comprising one or multiple prediction intervals). +#' @export +#' @examples +#' observed <- c(1, -15, 22) +#' predicted <- rbind( +#' c(-1, 0, 1, 2, 3), +#' c(-2, 1, 2, 2, 4), +#' c(-2, 0, 3, 3, 4) +#' ) +#' quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) +#' interval_coverage_deviation_quantile(observed, predicted, quantile) +interval_coverage_deviation_quantile <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + + # transform available quantiles into central interval ranges + boundary <- ifelse(quantile <= 0.5, "lower", "upper") + available_ranges <- ifelse( + boundary == "lower", + (1 - 2 * quantile) * 100, + (2 * quantile - 1) * 100 + ) + available_ranges <- unique(available_ranges) + necessary_quantiles <- unique(c( + (100 - available_ranges) / 2, + 100 - (100 - available_ranges) / 2) / 100 + ) + if (!all(necessary_quantiles %in% quantile)) { + warning( + "To compute coverage deviation, all quantiles must belong to central ", + "symmetric prediction intervals. Returnting `NA`.") + return(NA) + } + + reformatted <- quantile_to_interval(observed, predicted, quantile)[range != 0] + reformatted[, coverage := ifelse( + observed >= lower & observed <= upper, TRUE, FALSE + )] + reformatted[, coverage_deviation := coverage - range / 100] + out <- reformatted[, .(coverage_deviation = mean(coverage_deviation)), + by = c("forecast_id")] + return(out$coverage_deviation) +} + + #' @title Determines Bias of Quantile Forecasts #' #' @description diff --git a/man/interval_coverage_deviation_quantile.Rd b/man/interval_coverage_deviation_quantile.Rd new file mode 100644 index 000000000..a1398d468 --- /dev/null +++ b/man/interval_coverage_deviation_quantile.Rd @@ -0,0 +1,70 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/metrics-quantile.R +\name{interval_coverage_deviation_quantile} +\alias{interval_coverage_deviation_quantile} +\title{Interval Coverage Deviation (For Quantile-Based Forecasts)} +\usage{ +interval_coverage_deviation_quantile(observed, predicted, quantile) +} +\arguments{ +\item{observed}{A vector with observed values of size n} + +\item{predicted}{vector of size n with the predicted values} + +\item{quantile}{vector with quantile levels of size N} +} +\value{ +A numeric vector of length n with the coverage deviation for each +forecast (comprising one or multiple prediction intervals). +} +\description{ +Check the agreement between desired and actual interval coverage +of a forecast. + +The function is similar to \code{\link[=interval_coverage_quantile]{interval_coverage_quantile()}}, +but looks at all provided prediction intervals instead of only one. It +compares nominal coverage (i.e. the desired coverage) with the actual +observed coverage. + +A central symmetric prediction interval is defined by a lower and an +upper bound formed by a pair of predictive quantiles. For example, a 50\% +prediction interval is formed by the 0.25 and 0.75 quantiles of the +predictive distribution. Ideally, a forecaster should aim to cover about +50\% of all observed values with their 50\% prediction intervals, 90\% of all +observed values with their 90\% prediction intervals, and so on. + +For every prediction interval, the deviation is computed as the difference +between the observed coverage and the nominal coverage +For a single observed value and a single prediction interval, +coverage is always either 0 or 1. This is not the case for a single observed +value and multiple prediction intervals, but it still doesn't make that much +sense to compare nominal (desired) coverage and actual coverage for a single +observation. In that sense coverage deviation only really starts to make +sense as a metric when averaged across multiple observations). + +Positive values of coverage deviation are an indication for underconfidence, +i.e. the forecaster could likely have issued a narrower forecast. Negative +values are an indication for overconfidence, i.e. the forecasts were too +narrow. + +\deqn{ +\textrm{coverage deviation} = +\mathbf{1}(\textrm{observed value falls within interval} - +\textrm{nominal coverage}) +}{ +coverage deviation = +1(observed value falls within interval) - nominal coverage +} +The coverage deviation is then averaged across all prediction intervals. +The median is ignored when computing coverage deviation. +} +\examples{ +observed <- c(1, -15, 22) +predicted <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) +interval_coverage_deviation_quantile(observed, predicted, quantile) +} From 9c9f286b29da7b826946a6dfbd2596d6f2b5cefd Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 13:21:02 +0100 Subject: [PATCH 33/81] Create a new helper function to compute ranges of central prediction intervals from quantiles --- R/metrics-quantile.R | 16 +++++++--------- R/utils_data_handling.R | 28 +++++++++++++++++++++++----- man/get_range_from_quantile.Rd | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 man/get_range_from_quantile.Rd diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 4df7cdcaf..0fee05438 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -275,21 +275,19 @@ interval_coverage_deviation_quantile <- function(observed, predicted, quantile) assert_input_quantile(observed, predicted, quantile) # transform available quantiles into central interval ranges - boundary <- ifelse(quantile <= 0.5, "lower", "upper") - available_ranges <- ifelse( - boundary == "lower", - (1 - 2 * quantile) * 100, - (2 * quantile - 1) * 100 - ) - available_ranges <- unique(available_ranges) + available_ranges <- unique(get_range_from_quantile(quantile)) + + # check if all necessary quantiles are available necessary_quantiles <- unique(c( (100 - available_ranges) / 2, 100 - (100 - available_ranges) / 2) / 100 ) if (!all(necessary_quantiles %in% quantile)) { + missing <- necessary_quantiles[!necessary_quantiles %in% quantile] warning( - "To compute coverage deviation, all quantiles must belong to central ", - "symmetric prediction intervals. Returnting `NA`.") + "To compute coverage deviation, all quantiles must form central ", + "symmetric prediction intervals. Missing quantiles: ", + toString(missing), ". Returning `NA`.") return(NA) } diff --git a/R/utils_data_handling.R b/R/utils_data_handling.R index cb9470e87..f1dc27201 100644 --- a/R/utils_data_handling.R +++ b/R/utils_data_handling.R @@ -216,11 +216,7 @@ quantile_to_interval.data.frame <- function(dt, } dt[, boundary := ifelse(quantile <= 0.5, "lower", "upper")] - dt[, range := ifelse( - boundary == "lower", - round((1 - 2 * quantile) * 100, 10), - round((2 * quantile - 1) * 100, 10) - )] + dt[, range := get_range_from_quantile(quantile)] # add median quantile median <- dt[quantile == 0.5, ] @@ -311,3 +307,25 @@ sample_to_range_long <- function(data, return(data[]) } + +#' Get Range Belonging to a Quantile +#' @description Every quantile can be thought of either as the lower or the +#' upper bound of a symmetric central prediction interval. This helper function +#' returns the range of the central prediction interval to which the quantile +#' belongs. +#' +#' Due to numeric instability that sometimes occurred in the past, ranges are +#' rounded to 10 decimal places. This is not a problem for the vast majority of +#' use cases, but it is something to be aware of. +#' @param quantile a numeric vector of quantile levels of size N +#' @return a numeric vector of interval ranges of size N +#' @keywords internal +get_range_from_quantile <- function(quantile) { + boundary <- ifelse(quantile <= 0.5, "lower", "upper") + range <- ifelse( + boundary == "lower", + round((1 - 2 * quantile) * 100, digits = 10), + round((2 * quantile - 1) * 100, digits = 10) + ) + return(range) +} diff --git a/man/get_range_from_quantile.Rd b/man/get_range_from_quantile.Rd new file mode 100644 index 000000000..eca15af36 --- /dev/null +++ b/man/get_range_from_quantile.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_data_handling.R +\name{get_range_from_quantile} +\alias{get_range_from_quantile} +\title{Get Range Belonging to a Quantile} +\usage{ +get_range_from_quantile(quantile) +} +\arguments{ +\item{quantile}{a numeric vector of quantile levels of size N} +} +\value{ +a numeric vector of interval ranges of size N +} +\description{ +Every quantile can be thought of either as the lower or the +upper bound of a symmetric central prediction interval. This helper function +returns the range of the central prediction interval to which the quantile +belongs. + +Due to numeric instability that sometimes occurred in the past, ranges are +rounded to 10 decimal places. This is not a problem for the vast majority of +use cases, but it is something to be aware of. +} +\keyword{internal} From b883dd8e91f1ad6db781ae32aadd67fbd1d8b248 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 13:21:22 +0100 Subject: [PATCH 34/81] Update `metrics_quantile` --- data/metrics_quantile.rda | Bin 6730 -> 15100 bytes inst/create-list-available-forecasts.R | 3 ++- man/metrics_quantile.Rd | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index 2f2607933179842f7fcdb9c19e8ef140fe59117d..e8be29ea39e171f8a6ff0c021e5171c107222e1e 100644 GIT binary patch literal 15100 zcmV(KT-?)Ll6ihA|yWxZDbIiP#AU9nJov>Y*>&EID2 zx7)czSQU+|JD5pc+MPG7m1EKGbGSa;fC9$0H(icU?|f7Q-*jBNjb<_rbN~PYl>h($ z0Gk5X8UllRx=3gNxu_o}tER52MFlDmNd}&VgOz*kci%-f)iQze;vP!3+#(M9ud;AS zBp@c3fEq>s69$Q(G#Mt))I5_D#F$MdlxCC0riPdasguYiGH7JcGgHz}42`H$Z8Xu6 zF;5}sGy~Ko)YH_{1k)43o`$BFfh33kLrnlCngqa&0ihZc{XspFX*`&T?FNL&lnpaT z+Cxl0$Z4jBsMFLm4^u&-%4vdWrqm6n4K!(!)X)Zi&;V!yWd;c#riq|sPdzGnn+i9n z>PNH`$n^$|8X9^}DD+3DVj466G-zZ18VvvjfMfs-Gynhq0009(00000sj5hcPg79! zPe}BbWSTupN2p;uNs;P3MnKt37>pr;VKYEO5N4nn27u7hKxw8Lh58;yeih|l>h$Kzin2<`Nd`o=i~bbCQ3KWg)B|+~Z+YDRvH`Qd457HgchIdW2g#u% z0{!}G185_LA@y+j(hn3w(u10y(TX>gB2In<2nNb8OJ07ZJMkqHx5(RI^iZ`nAYneL z;Hieq4T$}fVQP|VN|2Cbfg(v~=WJ6BN0myyE+bga0`(Cqk-QjZm?;Fc=J0DHbW|0iy`1dx@X#}9~ z2P!xRAFT1W$#jB%ctp+W=eZAjL)u{JI=ii)N#>&Y$B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C*vY|%8LJg6SC6#J!1yy5dNe*pz?qkSx=F<{Ei)mbr zn_SlLyL@9wb!}TxNJ0}K#D8RK02!k-En^U&>535uB53fypv3d32r5tjb?y30z0wGF zd&GFY-+ToM<+>AKcB1e?Y3b_jnj7l?OE%E^k|Kl^2ZAUsMC2vEUQE0B^T0wa+#9|UHwr2Nu?w$p~*S4d)>m>Z{EbvC`*@`KM zm}HU+3eY!;YNS;M7_e7y7p~#7ShY1>xt}J%sUV&wmj)?huR%Vsi^-G%c4kG!Mdm>) z$kNa!3(LjEF>K_`WBE0fReF1oGcu8YT5lZCUA#o1(n+Ypeix$67>Xe!(%*p!<7i^a z+3ZlzNwpTBgNh^E-#EZzWuxy1&b8Xuqr2IL;?Ud7!n8}XJ)O#zB5@4Cm6`$AV{h} zuP~!0Ct1+s;;V$Q3sD1e(UxowW3kEVw^2?}*dNi)?%&q*S)C5Y@Nl~NZHf`h%VTE~N8#(?1x z@wnp&5FR29CJi0Da7jo=FXGW+!edorZ4v(n1Lx&LjVzK<>xaOkC0*&G=z|n5{iXHk96Eq@B0)#>l3W6~JqI&;d z>-&E4Z~6cC)|r_u#hkW8oAB82`YsOdEPBwlVHw&k@~HFTy8(_iiW>JkM+hP`E@I26 z-k+Xg{2ud#WW9dxccmYt%C;9_R_)?!pb_C6Kmb$2!ME8_tGr6K_$}s zFk_NNz_GXwhS1d2Vj|cNK`_vy2{dm)5J@2!D`enHESEsd&lmuS&ko$>1NWrt_LpUi zFLy^iu2~v(u=M+F_tF2q8kZjCCzH+HRR0{>_4ZQl#tx5Hr2(8^#_q(6FU~aV!@V)16=qu*>{^z^cPl-@2ae-doWEggT| zdQR5Jrd4}E*sD+rz!vXF7o=eOUQv;8%)Rsgg8oj5y`bhi37NL9j% gBU&zft(vd8!C=r(^+S&&C%^G`BvXY60(u{QFkCG$1ONa4 diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index 21a2c8682..e69745e2a 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -29,6 +29,7 @@ metrics_quantile <- list( "dispersion" = dispersion, "bias" = bias_quantile, "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)}, - "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} + "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)}, + "coverage_deviation" = \(...) {interval_coverage_deviation_quantile(...)} ) usethis::use_data(metrics_quantile, overwrite = TRUE) diff --git a/man/metrics_quantile.Rd b/man/metrics_quantile.Rd index 9fda39f03..edf32a8ff 100644 --- a/man/metrics_quantile.Rd +++ b/man/metrics_quantile.Rd @@ -5,7 +5,7 @@ \alias{metrics_quantile} \title{Default metrics for quantile-based forecasts.} \format{ -An object of class \code{list} of length 7. +An object of class \code{list} of length 8. } \usage{ metrics_quantile From 7b629192caf917ca02254c0c7f8c75741df6df29 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 13:30:45 +0100 Subject: [PATCH 35/81] Small update to `metrics_quantile` + fixing a typo --- R/metrics-quantile.R | 2 +- data/metrics_quantile.rda | Bin 15100 -> 12404 bytes inst/create-list-available-forecasts.R | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 0fee05438..186d057cc 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -205,7 +205,7 @@ interval_coverage_quantile <- function(observed, predicted, quantile, range = 50 if (!all(necessary_quantiles %in% quantile)) { warning( "To compute the coverage for a range of ", range, "%, the quantiles ", - necessary_quantiles, " are required. Returnting `NA`.") + necessary_quantiles, " are required. Returning `NA`.") return(NA) } r <- range diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index e8be29ea39e171f8a6ff0c021e5171c107222e1e..2d9413756a7778a95643a11ae205d5b927d3574d 100644 GIT binary patch literal 12404 zcmV-)FpJMZT4*^jL0KkKS)kq?y#Un9|NsC0|NsC0|N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feb6}mw$?A0u&Edwy(NhvymAyDznVvH?f4!XvnGDR2C;j7bb6$gW8qWfR*3}h0 zBrYuWQg{BbWKHr3GbQmN^FCyXNpWMx{8`^hJnT8|E5v(MIn~kI+J1`2neSGY(bdkw zyR0@bIX1L(bohR*Ho|Z9_J5n-+ew41@%?|hag`cgTP5<;&cAERhM8=c6Bt7?J?KJt z5P|#ws9=qH{Rz)g=qZ8V6gM12KTl`5x#ExKxd42iCSdLLWzL^t2v7WBc$&0~)eM1Z zh{6Smt4l`KWF&$hC|FUTL=8s}Q8L(u6Ce^Lk_AMR(^QtC)(KRQg{35I6`am)v284q zbaiJrX0pc)a3D%VoN6Kz2{O=9LYomJB526uNru8{=?DxGj0GYg4h9pEq=X8$Zp3xF zUAJb=X6&kDnoXUpMJ1&ut7Ju{9NRh^VNtQuU1gAOg4X$HwS;7BBN=e!OSXK^iTgbc ew{C)lWkLd`?jQo!!{-3iLONcMpG&P diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index e69745e2a..2778a22c4 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -30,6 +30,6 @@ metrics_quantile <- list( "bias" = bias_quantile, "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)}, "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)}, - "coverage_deviation" = \(...) {interval_coverage_deviation_quantile(...)} + "coverage_deviation" = interval_coverage_deviation_quantile ) usethis::use_data(metrics_quantile, overwrite = TRUE) From c6747640f19598af8880a71fdf92f51435becc07 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 15:20:33 +0100 Subject: [PATCH 36/81] update `ae_median_quantile()` and documentation associated to `wis()` and other functions with the same arguments --- R/metrics-quantile.R | 59 ++++++++++----------- man/ae_median_quantile.Rd | 30 +++++------ man/interval_coverage.Rd | 9 +++- man/interval_coverage_deviation_quantile.Rd | 9 +++- man/wis.Rd | 13 +++-- 5 files changed, 66 insertions(+), 54 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 186d057cc..ecd356d7e 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -80,14 +80,20 @@ #' `overprediction`, `underprediction`, and `dispersion.` #' #' @inheritParams interval_score -#' @param predicted vector of size n with the predicted values +#' @param observed numeric vector of size n with the observed values +#' @param predicted numeric nxN matrix of predictive +#' quantiles, n (number of rows) being the number of forecasts (corresponding +#' to the number of observed values) and N +#' (number of columns) the number of quantiles per forecast. +#' If `observed` is just a single number, then predicted can just be a +#' vector of size N. #' @param quantile vector with quantile levels of size N #' @param count_median_twice if TRUE, count the median twice in the score #' @param na.rm if TRUE, ignore NA values when computing the score #' @importFrom stats weighted.mean #' @return -#' `wis()`: a numeric vector with WIS values (one per observation), or a list -#' with separate entries if `separate_results` is `TRUE`. +#' `wis()`: a numeric vector with WIS values of size n (one per observation), +#' or a list with separate entries if `separate_results` is `TRUE`. #' @export wis <- function(observed, predicted, @@ -616,48 +622,39 @@ wis_one_to_one <- function(observed, #' @title Absolute Error of the Median (Quantile-based Version) -#' #' @description -#' Absolute error of the median calculated as -#' +#' Compute the absolute error of the median calculated as #' \deqn{ -#' \textrm{abs}(\textrm{observed} - \textrm{prediction}) +#' \textrm{abs}(\textrm{observed} - \textrm{median prediction}) #' }{ #' abs(observed - median_prediction) #' } -#' -#' The function was created for internal use within [score()], but can also -#' used as a standalone function. -#' -#' @param predicted numeric vector with predictions, corresponding to the -#' quantiles in a second vector, `quantiles`. -#' @param quantiles numeric vector that denotes the quantile for the values -#' in `predicted`. Only those predictions where `quantiles == 0.5` will -#' be kept. If `quantiles` is `NULL`, then all `predicted` and -#' `observed` will be used (this is then the same as [abs_error()]) -#' @return vector with the scoring values +#' The median prediction is the predicted value for which quantile == 0.5, +#' the function therefore requires 0.5 to be among the quantile levels in +#' `quantile`. +#' @inheritParams wis +#' @return numeric vector of length N with the absolute error of the median #' @seealso [ae_median_sample()], [abs_error()] #' @importFrom stats median -#' @inheritParams ae_median_sample #' @examples #' observed <- rnorm(30, mean = 1:30) #' predicted_values <- rnorm(30, mean = 1:30) #' ae_median_quantile(observed, predicted_values, quantiles = 0.5) #' @export #' @keywords metric - -ae_median_quantile <- function(observed, predicted, quantiles = NULL) { - if (!is.null(quantiles)) { - if (!any(quantiles == 0.5) && !anyNA(quantiles)) { - return(NA_real_) - warning( - "in order to compute the absolute error of the median, `0.5` must be ", - "among the quantiles given. Maybe you want to use `abs_error()`?" - ) - } - observed <- observed[quantiles == 0.5] - predicted <- predicted[quantiles == 0.5] +ae_median_quantile <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + if (!any(quantiles == 0.5)) { + warning( + "in order to compute the absolute error of the median, `0.5` must be ", + "among the quantiles given. Returning `NA`." + ) + return(NA_real_) + } + if (is.null(dim(predicted))) { + predicted <- matrix(predicted, nrow = 1) } + predicted <- predicted[, quantile == 0.5] abs_error_median <- abs(observed - predicted) return(abs_error_median) } diff --git a/man/ae_median_quantile.Rd b/man/ae_median_quantile.Rd index 841850235..e85400121 100644 --- a/man/ae_median_quantile.Rd +++ b/man/ae_median_quantile.Rd @@ -4,33 +4,33 @@ \alias{ae_median_quantile} \title{Absolute Error of the Median (Quantile-based Version)} \usage{ -ae_median_quantile(observed, predicted, quantiles = NULL) +ae_median_quantile(observed, predicted, quantile) } \arguments{ -\item{observed}{A vector with observed values of size n} +\item{observed}{numeric vector of size n with the observed values} -\item{predicted}{numeric vector with predictions, corresponding to the -quantiles in a second vector, \code{quantiles}.} +\item{predicted}{numeric nxN matrix of predictive +quantiles, n (number of rows) being the number of forecasts (corresponding +to the number of observed values) and N +(number of columns) the number of quantiles per forecast. +If \code{observed} is just a single number, then predicted can just be a +vector of size N.} -\item{quantiles}{numeric vector that denotes the quantile for the values -in \code{predicted}. Only those predictions where \code{quantiles == 0.5} will -be kept. If \code{quantiles} is \code{NULL}, then all \code{predicted} and -\code{observed} will be used (this is then the same as \code{\link[=abs_error]{abs_error()}})} +\item{quantile}{vector with quantile levels of size N} } \value{ -vector with the scoring values +numeric vector of length N with the absolute error of the median } \description{ -Absolute error of the median calculated as - +Compute the absolute error of the median calculated as \deqn{ - \textrm{abs}(\textrm{observed} - \textrm{prediction}) + \textrm{abs}(\textrm{observed} - \textrm{median prediction}) }{ abs(observed - median_prediction) } - -The function was created for internal use within \code{\link[=score]{score()}}, but can also -used as a standalone function. +The median prediction is the predicted value for which quantile == 0.5, +the function therefore requires 0.5 to be among the quantile levels in +\code{quantile}. } \examples{ observed <- rnorm(30, mean = 1:30) diff --git a/man/interval_coverage.Rd b/man/interval_coverage.Rd index 8fbfc67d1..74256cc77 100644 --- a/man/interval_coverage.Rd +++ b/man/interval_coverage.Rd @@ -11,9 +11,14 @@ interval_coverage_quantile(observed, predicted, quantile, range = 50) interval_coverage_sample(observed, predicted, range = 50) } \arguments{ -\item{observed}{A vector with observed values of size n} +\item{observed}{numeric vector of size n with the observed values} -\item{predicted}{vector of size n with the predicted values} +\item{predicted}{numeric nxN matrix of predictive +quantiles, n (number of rows) being the number of forecasts (corresponding +to the number of observed values) and N +(number of columns) the number of quantiles per forecast. +If \code{observed} is just a single number, then predicted can just be a +vector of size N.} \item{quantile}{vector with quantile levels of size N} diff --git a/man/interval_coverage_deviation_quantile.Rd b/man/interval_coverage_deviation_quantile.Rd index a1398d468..9a6029ec7 100644 --- a/man/interval_coverage_deviation_quantile.Rd +++ b/man/interval_coverage_deviation_quantile.Rd @@ -7,9 +7,14 @@ interval_coverage_deviation_quantile(observed, predicted, quantile) } \arguments{ -\item{observed}{A vector with observed values of size n} +\item{observed}{numeric vector of size n with the observed values} -\item{predicted}{vector of size n with the predicted values} +\item{predicted}{numeric nxN matrix of predictive +quantiles, n (number of rows) being the number of forecasts (corresponding +to the number of observed values) and N +(number of columns) the number of quantiles per forecast. +If \code{observed} is just a single number, then predicted can just be a +vector of size N.} \item{quantile}{vector with quantile levels of size N} } diff --git a/man/wis.Rd b/man/wis.Rd index a76b3c35f..057e9d04a 100644 --- a/man/wis.Rd +++ b/man/wis.Rd @@ -24,9 +24,14 @@ overprediction(observed, predicted, quantile) underprediction(observed, predicted, quantile) } \arguments{ -\item{observed}{A vector with observed values of size n} +\item{observed}{numeric vector of size n with the observed values} -\item{predicted}{vector of size n with the predicted values} +\item{predicted}{numeric nxN matrix of predictive +quantiles, n (number of rows) being the number of forecasts (corresponding +to the number of observed values) and N +(number of columns) the number of quantiles per forecast. +If \code{observed} is just a single number, then predicted can just be a +vector of size N.} \item{quantile}{vector with quantile levels of size N} @@ -46,8 +51,8 @@ Default: \code{TRUE}.} \item{na.rm}{if TRUE, ignore NA values when computing the score} } \value{ -\code{wis()}: a numeric vector with WIS values (one per observation), or a list -with separate entries if \code{separate_results} is \code{TRUE}. +\code{wis()}: a numeric vector with WIS values of size n (one per observation), +or a list with separate entries if \code{separate_results} is \code{TRUE}. \code{dispersion()}: a numeric vector with dispersion values (one per observation) From 27d4a78e9009b6b9c3d1b4ad6e83173662ec29dc Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 15:27:33 +0100 Subject: [PATCH 37/81] add input checks to `ae_median_sample()` and `se_mean_sample()` --- R/metrics-sample.R | 12 ++++++------ man/abs_error.Rd | 10 +++++++--- man/se_mean_sample.Rd | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/R/metrics-sample.R b/R/metrics-sample.R index 73026bfcf..96a3ee0ce 100644 --- a/R/metrics-sample.R +++ b/R/metrics-sample.R @@ -102,12 +102,11 @@ bias_sample <- function(observed, predicted) { #' @keywords metric ae_median_sample <- function(observed, predicted) { + assert_input_sample(observed, predicted) median_predictions <- apply( - as.matrix(predicted), MARGIN = 1, FUN = median # this is rowwise + as.matrix(predicted), MARGIN = 1, FUN = median # this is row-wise ) - ae_median <- abs(observed - median_predictions) - return(ae_median) } @@ -118,11 +117,11 @@ ae_median_sample <- function(observed, predicted) { #' Squared error of the mean calculated as #' #' \deqn{ -#' \textrm{mean}(\textrm{observed} - \textrm{prediction})^2 +#' \textrm{mean}(\textrm{observed} - \textrm{mean prediction})^2 #' }{ -#' mean(observed - mean_prediction)^2 +#' mean(observed - mean prediction)^2 #' } -#' +#' The mean prediction is calculated as the mean of the predictive samples. #' @param observed A vector with observed values of size n #' @param predicted nxN matrix of predictive samples, n (number of rows) being #' the number of data points and N (number of columns) the number of Monte @@ -137,6 +136,7 @@ ae_median_sample <- function(observed, predicted) { #' @keywords metric se_mean_sample <- function(observed, predicted) { + assert_input_sample(observed, predicted) mean_predictions <- rowMeans(as.matrix(predicted)) se_mean <- (observed - mean_predictions)^2 diff --git a/man/abs_error.Rd b/man/abs_error.Rd index 099937bfd..197703193 100644 --- a/man/abs_error.Rd +++ b/man/abs_error.Rd @@ -7,10 +7,14 @@ abs_error(observed, predicted) } \arguments{ -\item{observed}{A vector with observed values of size n} +\item{observed}{numeric vector of size n with the observed values} -\item{predicted}{numeric vector with predictions, corresponding to the -quantiles in a second vector, \code{quantiles}.} +\item{predicted}{numeric nxN matrix of predictive +quantiles, n (number of rows) being the number of forecasts (corresponding +to the number of observed values) and N +(number of columns) the number of quantiles per forecast. +If \code{observed} is just a single number, then predicted can just be a +vector of size N.} } \value{ vector with the absolute error diff --git a/man/se_mean_sample.Rd b/man/se_mean_sample.Rd index d7c7d332f..08a6d5d16 100644 --- a/man/se_mean_sample.Rd +++ b/man/se_mean_sample.Rd @@ -20,10 +20,11 @@ vector with the scoring values Squared error of the mean calculated as \deqn{ - \textrm{mean}(\textrm{observed} - \textrm{prediction})^2 + \textrm{mean}(\textrm{observed} - \textrm{mean prediction})^2 }{ - mean(observed - mean_prediction)^2 + mean(observed - mean prediction)^2 } +The mean prediction is calculated as the mean of the predictive samples. } \examples{ observed <- rnorm(30, mean = 1:30) From e2618cdeaa43347114f6fdbdfbab9abb8ba85ec7 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Fri, 10 Nov 2023 15:54:55 +0100 Subject: [PATCH 38/81] Update documentation for `metrics_quantile` and remove # no lint from other data documentation (seems it was ignored anyway) --- R/data.R | 21 +++++++++++++-------- man/example_binary.Rd | 2 +- man/example_continuous.Rd | 2 +- man/example_point.Rd | 2 +- man/example_quantile.Rd | 2 +- man/example_quantile_forecasts_only.Rd | 2 +- man/example_truth_only.Rd | 2 +- man/metrics_quantile.Rd | 9 +++++++-- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/R/data.R b/R/data.R index 48548ffed..c57e044d8 100644 --- a/R/data.R +++ b/R/data.R @@ -19,7 +19,7 @@ #' \item{model}{name of the model that generated the forecasts} #' \item{horizon}{forecast horizon in weeks} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_quantile" @@ -44,7 +44,7 @@ #' \item{model}{name of the model that generated the forecasts} #' \item{horizon}{forecast horizon in weeks} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_point" @@ -69,7 +69,7 @@ #' \item{predicted}{predicted value} #' \item{sample_id}{id for the corresponding sample} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_continuous" @@ -124,7 +124,7 @@ #' \item{horizon}{forecast horizon in weeks} #' \item{predicted}{predicted value} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_binary" @@ -147,7 +147,7 @@ #' \item{model}{name of the model that generated the forecasts} #' \item{horizon}{forecast horizon in weeks} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_quantile_forecasts_only" @@ -167,7 +167,7 @@ #' \item{observed}{observed values} #' \item{location_name}{name of the country for which a prediction was made} #' } -#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +#' @source \url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} "example_truth_only" #' Summary information for selected metrics @@ -216,8 +216,13 @@ #' #' A named list with functions: #' - "wis" = [wis()] +#' - "overprediction" = [overprediction()] +#' - "underprediction" = [underprediction()] +#' - "dispersion" = [dispersion()] #' - "bias" = [bias_quantile()] -#' - "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)} #nolint -#' - "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} #nolint +#' - "coverage_50" = \(...) {run_safely(..., range = 50, fun = [interval_coverage_quantile][interval_coverage_quantile()])} +#' - "coverage_90" = \(...) {run_safely(..., range = 90, fun = [interval_coverage_quantile][interval_coverage_quantile()])} +#' - "coverage_deviation" = [interval_coverage_deviation_quantile()], +#' - "ae_median" = [ae_median_quantile()] #' @keywords info "metrics_quantile" diff --git a/man/example_binary.Rd b/man/example_binary.Rd index e7042d6b2..47797b8cd 100644 --- a/man/example_binary.Rd +++ b/man/example_binary.Rd @@ -19,7 +19,7 @@ A data frame with 346 rows and 10 columns: } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_binary diff --git a/man/example_continuous.Rd b/man/example_continuous.Rd index d1fba390e..354ebc5d6 100644 --- a/man/example_continuous.Rd +++ b/man/example_continuous.Rd @@ -20,7 +20,7 @@ A data frame with 13,429 rows and 10 columns: } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_continuous diff --git a/man/example_point.Rd b/man/example_point.Rd index 62af0e44f..1eb734b76 100644 --- a/man/example_point.Rd +++ b/man/example_point.Rd @@ -19,7 +19,7 @@ A data frame with } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_point diff --git a/man/example_quantile.Rd b/man/example_quantile.Rd index 00250e6d0..2582907e9 100644 --- a/man/example_quantile.Rd +++ b/man/example_quantile.Rd @@ -20,7 +20,7 @@ A data frame with } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_quantile diff --git a/man/example_quantile_forecasts_only.Rd b/man/example_quantile_forecasts_only.Rd index 3fcaf2722..d789ed1e0 100644 --- a/man/example_quantile_forecasts_only.Rd +++ b/man/example_quantile_forecasts_only.Rd @@ -18,7 +18,7 @@ A data frame with 7,581 rows and 9 columns: } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_quantile_forecasts_only diff --git a/man/example_truth_only.Rd b/man/example_truth_only.Rd index 46453ba97..f8ae05afa 100644 --- a/man/example_truth_only.Rd +++ b/man/example_truth_only.Rd @@ -15,7 +15,7 @@ A data frame with 140 rows and 5 columns: } } \source{ -\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} # nolint +\url{https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/} } \usage{ example_truth_only diff --git a/man/metrics_quantile.Rd b/man/metrics_quantile.Rd index edf32a8ff..f17e06048 100644 --- a/man/metrics_quantile.Rd +++ b/man/metrics_quantile.Rd @@ -14,9 +14,14 @@ metrics_quantile A named list with functions: \itemize{ \item "wis" = \code{\link[=wis]{wis()}} +\item "overprediction" = \code{\link[=overprediction]{overprediction()}} +\item "underprediction" = \code{\link[=underprediction]{underprediction()}} +\item "dispersion" = \code{\link[=dispersion]{dispersion()}} \item "bias" = \code{\link[=bias_quantile]{bias_quantile()}} -\item "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)} #nolint -\item "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)} #nolint +\item "coverage_50" = \(...) {run_safely(..., range = 50, fun = \link[=interval_coverage_quantile]{interval_coverage_quantile})} +\item "coverage_90" = \(...) {run_safely(..., range = 90, fun = \link[=interval_coverage_quantile]{interval_coverage_quantile})} +\item "coverage_deviation" = \code{\link[=interval_coverage_deviation_quantile]{interval_coverage_deviation_quantile()}}, +\item "ae_median" = \code{\link[=ae_median_quantile]{ae_median_quantile()}} } } \keyword{info} From 2ef9a52948b21967bfd1e89842315b747923e2d9 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 11 Nov 2023 16:18:11 +0100 Subject: [PATCH 39/81] Correct error in ae_median_quantile, update data file and documentation --- R/metrics-quantile.R | 2 +- data/metrics_quantile.rda | Bin 12404 -> 13133 bytes man/metrics_quantile.Rd | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index ecd356d7e..2ee3a7aa0 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -644,7 +644,7 @@ wis_one_to_one <- function(observed, #' @keywords metric ae_median_quantile <- function(observed, predicted, quantile) { assert_input_quantile(observed, predicted, quantile) - if (!any(quantiles == 0.5)) { + if (!any(quantile == 0.5)) { warning( "in order to compute the absolute error of the median, `0.5` must be ", "among the quantiles given. Returning `NA`." diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index 2d9413756a7778a95643a11ae205d5b927d3574d..70a00a9329468320b53b2c7e803ec070df6b33a9 100644 GIT binary patch literal 13133 zcmV-TGqTJ=T4*^jL0KkKS?0UNbpYU7fB*mg|NsC0|NsC0|NsC0|NsC0|NsC0|Nrm* z|NH;{|Nr1UK7Fn4ohP4Yc>C+mwv@a(y@92B|16HJXX#AIL*f?)=XL4?rL zCX9_V84WQs8Vv>k0LiAFp@`E7kT6X!Mwu{%O&Vknq)KXNDi2d?Xw6SivY7^&G-x!_ zN2t>wnvYTH05*_%jDe<1fb^OMo}kg7$j|}l41hEm8Udz&0MGydrkIaV0i$XNltBO{ zfuIS238nU$fav*A3 z#^4}QNQy{E$RY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nsNk6L3if*V?+2uZV)S zBUEFY`|LT~%ac6(1gTmJYPT&bMo)b>IuZGr-2S5t*>)z=n^rJVJmHl za1~$6l9$&X@p(nUBgx43FVI$$?dv^Hlqep0Dk7?jPkddc0q8AS=J_}Ab_^7@3mNEp z6E_IR`^7HXibtzIL-1eaME-1qi%S~0FLV1ai(B1qe>3mFcXIDG7Q5V3$T3-on897DV$)_SMhg=&uypw z-}HFguju>!|7-R1bM*O%^QGnbSxyFit6Qn!)ZG7ex@qm)OkG#%_jfu7BrmCt<*@@r zYa;tYJv|ShfexDLdOit-tmJtdokdMTi!surd`Ln`4ng^^x(~n^A*O$iE1rM@N5^NC z>j7#=#pq=@@h!I7ZMNHOw%c_jn(1;j`LUbMj7DbOJ=`uv?O}AY@>H3>L`u?pm z_5Wn&K0&tIZ!zp+wKKOf@HGyP)o)ft=IaaiwuCP;aU)@L=pMI^>dkl;+;W}%9|O*y zwo*a*~Wy%~}t;}4UEl2H~p8L=|ubYJ)Uv0(jXz{YTZ%S4|#k^W0 zsp4xikzsixexzsN)4Q_^+RJ`H^=i;{wxY!wA~c-KhfvIlM>RDi?y%W&2($4 zK7FN!uYv4hehu!AKRLT-Z#5jIr996?;QRPICBJ!4=A#9i&i6FI-SmV5AriYv7@}41 z^VdBx`bfW9@_KUq#Qta=tMv0v{r?C7@~HEVQ_tr87u4^w(CD{7vyG5iBO;qsr&_Ye zO=cP+Em-Cnb%Bx=U}PnYnzGfIWnqnwMpK&9V^L`}VPH_@47rT3+HFDwkc&X1K?o9{ zl0qR7^0->VXwv44q^j84Z3foHml4>9VGKiX5F*54#!8yE4a05~vEstlmkbMw=(UZL mbj5J_p8vu6A1~Ya!l3Jc3i`Pf9bZHL;_gVN3KA3>!`Gmg#}{P) diff --git a/man/metrics_quantile.Rd b/man/metrics_quantile.Rd index f17e06048..ea444ee7e 100644 --- a/man/metrics_quantile.Rd +++ b/man/metrics_quantile.Rd @@ -5,7 +5,7 @@ \alias{metrics_quantile} \title{Default metrics for quantile-based forecasts.} \format{ -An object of class \code{list} of length 8. +An object of class \code{list} of length 9. } \usage{ metrics_quantile From 7e635eb06e7f25b95726768c5311adaa0549d3b4 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 11 Nov 2023 16:18:54 +0100 Subject: [PATCH 40/81] Correct an issue with `pit()` where this still relies on the computation of coverage_deviation per quantile as a metric --- R/pit.R | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/R/pit.R b/R/pit.R index 2e00e4b90..ee5e09c7c 100644 --- a/R/pit.R +++ b/R/pit.R @@ -189,18 +189,10 @@ pit <- function(data, data <- remove_na_observed_predicted(data) forecast_type <- get_forecast_type(data) - # if prediction type is quantile, simply extract coverage values from - # score and returned a list with named vectors if (forecast_type == "quantile") { - coverage <- - score(data, metrics = "quantile_coverage") - - coverage <- summarise_scores(coverage, - by = unique(c(by, "quantile")) - ) - # remove all existing attributes and class - coverage <- remove_scoringutils_class(coverage) - + data[, quantile_coverage := (observed <= predicted)] + coverage <- data[, .(quantile_coverage = mean(quantile_coverage)), + by = c(unique(c(by, "quantile")))] coverage <- coverage[order(quantile), .( quantile = c(quantile, 1), @@ -208,7 +200,6 @@ pit <- function(data, ), by = c(get_forecast_unit(coverage)) ] - return(coverage[]) } From 77fcde492473bf235d0779658fd5db9d7a0072bd Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sat, 11 Nov 2023 16:19:46 +0100 Subject: [PATCH 41/81] commit previously forgotten change in `metrics_quantile` --- inst/create-list-available-forecasts.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index 2778a22c4..fcac2950c 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -30,6 +30,7 @@ metrics_quantile <- list( "bias" = bias_quantile, "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)}, "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)}, - "coverage_deviation" = interval_coverage_deviation_quantile + "coverage_deviation" = interval_coverage_deviation_quantile, + "ae_median" = ae_median_quantile ) usethis::use_data(metrics_quantile, overwrite = TRUE) From 295eb518aab76737d5681c99473159b075c74090 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 14:59:12 +0100 Subject: [PATCH 42/81] Fix issues with ae_median_sample(), ae_median_quantile() and se_mean_sample() --- R/metrics-quantile.R | 4 ++-- R/metrics-sample.R | 4 ++-- man/ae_median_quantile.Rd | 4 ++-- man/ae_median_sample.Rd | 2 +- man/se_mean_sample.Rd | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index 2ee3a7aa0..a321b21bf 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -638,8 +638,8 @@ wis_one_to_one <- function(observed, #' @importFrom stats median #' @examples #' observed <- rnorm(30, mean = 1:30) -#' predicted_values <- rnorm(30, mean = 1:30) -#' ae_median_quantile(observed, predicted_values, quantiles = 0.5) +#' predicted_values <- matrix(rnorm(30, mean = 1:30)) +#' ae_median_quantile(observed, predicted_values, quantile = 0.5) #' @export #' @keywords metric ae_median_quantile <- function(observed, predicted, quantile) { diff --git a/R/metrics-sample.R b/R/metrics-sample.R index 96a3ee0ce..803fb4c4e 100644 --- a/R/metrics-sample.R +++ b/R/metrics-sample.R @@ -96,7 +96,7 @@ bias_sample <- function(observed, predicted) { #' @importFrom stats median #' @examples #' observed <- rnorm(30, mean = 1:30) -#' predicted_values <- rnorm(30, mean = 1:30) +#' predicted_values <- matrix(rnorm(30, mean = 1:30)) #' ae_median_sample(observed, predicted_values) #' @export #' @keywords metric @@ -130,7 +130,7 @@ ae_median_sample <- function(observed, predicted) { #' @seealso [squared_error()] #' @examples #' observed <- rnorm(30, mean = 1:30) -#' predicted_values <- rnorm(30, mean = 1:30) +#' predicted_values <- matrix(rnorm(30, mean = 1:30)) #' se_mean_sample(observed, predicted_values) #' @export #' @keywords metric diff --git a/man/ae_median_quantile.Rd b/man/ae_median_quantile.Rd index e85400121..d96965c7c 100644 --- a/man/ae_median_quantile.Rd +++ b/man/ae_median_quantile.Rd @@ -34,8 +34,8 @@ the function therefore requires 0.5 to be among the quantile levels in } \examples{ observed <- rnorm(30, mean = 1:30) -predicted_values <- rnorm(30, mean = 1:30) -ae_median_quantile(observed, predicted_values, quantiles = 0.5) +predicted_values <- matrix(rnorm(30, mean = 1:30)) +ae_median_quantile(observed, predicted_values, quantile = 0.5) } \seealso{ \code{\link[=ae_median_sample]{ae_median_sample()}}, \code{\link[=abs_error]{abs_error()}} diff --git a/man/ae_median_sample.Rd b/man/ae_median_sample.Rd index d446b3300..1e420fcc4 100644 --- a/man/ae_median_sample.Rd +++ b/man/ae_median_sample.Rd @@ -27,7 +27,7 @@ Absolute error of the median calculated as } \examples{ observed <- rnorm(30, mean = 1:30) -predicted_values <- rnorm(30, mean = 1:30) +predicted_values <- matrix(rnorm(30, mean = 1:30)) ae_median_sample(observed, predicted_values) } \seealso{ diff --git a/man/se_mean_sample.Rd b/man/se_mean_sample.Rd index 08a6d5d16..c2101d4df 100644 --- a/man/se_mean_sample.Rd +++ b/man/se_mean_sample.Rd @@ -28,7 +28,7 @@ The mean prediction is calculated as the mean of the predictive samples. } \examples{ observed <- rnorm(30, mean = 1:30) -predicted_values <- rnorm(30, mean = 1:30) +predicted_values <- matrix(rnorm(30, mean = 1:30)) se_mean_sample(observed, predicted_values) } \seealso{ From 88fcdce4efcd8d7fbc3571fc024ab7dcc3357b02 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 15:01:59 +0100 Subject: [PATCH 43/81] Change "interval_score" to "wis" as a metric name. Comment out code for now that cannot be run anymore. --- R/pairwise-comparisons.R | 6 +++--- R/plot.R | 32 ++++++++++++++-------------- R/summarise_scores.R | 2 +- man/add_coverage.Rd | 2 +- man/compare_two_models.Rd | 2 +- man/pairwise_comparison.Rd | 2 +- man/pairwise_comparison_one_group.Rd | 2 +- man/plot_interval_coverage.Rd | 8 +++---- man/plot_ranges.Rd | 16 +++++++------- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/R/pairwise-comparisons.R b/R/pairwise-comparisons.R index f23316254..eab561adb 100644 --- a/R/pairwise-comparisons.R +++ b/R/pairwise-comparisons.R @@ -28,7 +28,7 @@ #' #' @param scores A data.table of scores as produced by [score()]. #' @param metric A character vector of length one with the metric to do the -#' comparison on. The default is "auto", meaning that either "interval_score", +#' comparison on. The default is "auto", meaning that either "wis", #' "crps", or "brier_score" will be selected where available. #' @param by character vector with names of columns present in the input #' data.frame. `by` determines how pairwise comparisons will be computed. @@ -366,8 +366,8 @@ compare_two_models <- function(scores, #' @keywords internal infer_rel_skill_metric <- function(scores) { - if ("interval_score" %in% colnames(scores)) { - rel_skill_metric <- "interval_score" + if ("wis" %in% colnames(scores)) { + rel_skill_metric <- "wis" } else if ("crps" %in% colnames(scores)) { rel_skill_metric <- "crps" } else if ("brier_score" %in% colnames(scores)) { diff --git a/R/plot.R b/R/plot.R index f90be0599..59f0f6eca 100644 --- a/R/plot.R +++ b/R/plot.R @@ -221,7 +221,7 @@ plot_wis <- function(scores, #' produced by [score()] or [summarise_scores()]. Note that "range" must be included #' in the `by` argument when running [summarise_scores()] #' @param y The variable from the scores you want to show on the y-Axis. -#' This could be something like "interval_score" (the default) or "dispersion" +#' This could be something like "wis" (the default) or "dispersion" #' @param x The variable from the scores you want to show on the x-Axis. #' Usually this will be "model" #' @param colour Character vector of length one used to determine a variable @@ -233,18 +233,18 @@ plot_wis <- function(scores, #' @export #' @examples #' library(ggplot2) -#' scores <- score(example_quantile) -#' scores <- summarise_scores(scores, by = c("model", "target_type", "range")) +#' # scores <- score(example_quantile) +#' # scores <- summarise_scores(scores, by = c("model", "target_type", "range")) #' -#' plot_ranges(scores, x = "model") + -#' facet_wrap(~target_type, scales = "free") +#' # plot_ranges(scores, x = "model") + +#' # facet_wrap(~target_type, scales = "free") #' #' # visualise dispersion instead of interval score -#' plot_ranges(scores, y = "dispersion", x = "model") + -#' facet_wrap(~target_type) +#' # plot_ranges(scores, y = "dispersion", x = "model") + +#' # facet_wrap(~target_type) plot_ranges <- function(scores, - y = "interval_score", + y = "wis", x = "model", colour = "range") { plot <- ggplot( @@ -296,7 +296,7 @@ plot_ranges <- function(scores, #' @export #' @examples #' scores <- score(example_quantile) -#' scores <- summarise_scores(scores, by = c("model", "target_type", "range")) +#' scores <- summarise_scores(scores, by = c("model", "target_type")) #' #' plot_heatmap(scores, x = "target_type", metric = "bias") @@ -582,10 +582,10 @@ make_na <- make_NA #' @importFrom data.table dcast #' @export #' @examples -#' data.table::setDTthreads(1) # only needed to avoid issues on CRAN -#' scores <- score(example_quantile) -#' scores <- summarise_scores(scores, by = c("model", "range")) -#' plot_interval_coverage(scores) +#' # data.table::setDTthreads(1) # only needed to avoid issues on CRAN +#' # scores <- score(example_quantile) +#' # scores <- summarise_scores(scores, by = c("model", "range")) +#' # plot_interval_coverage(scores) plot_interval_coverage <- function(scores, colour = "model") { @@ -638,9 +638,9 @@ plot_interval_coverage <- function(scores, #' @importFrom data.table dcast #' @export #' @examples -#' scores <- score(example_quantile) -#' scores <- summarise_scores(scores, by = c("model", "quantile")) -#' plot_quantile_coverage(scores) +#' # scores <- score(example_quantile) +#' # scores <- summarise_scores(scores, by = c("model", "quantile")) +#' # plot_quantile_coverage(scores) plot_quantile_coverage <- function(scores, colour = "model") { diff --git a/R/summarise_scores.R b/R/summarise_scores.R index e62bac789..40666b1f3 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -331,7 +331,7 @@ check_summary_params <- function(scores, #' @examples #' library(magrittr) # pipe operator #' score(example_quantile) %>% -#' add_coverage(by = c("model", "target_type")) %>% +#' # add_coverage(by = c("model", "target_type")) %>% #' summarise_scores(by = c("model", "target_type")) %>% #' summarise_scores(fun = signif, digits = 2) #' @export diff --git a/man/add_coverage.Rd b/man/add_coverage.Rd index 33990a3bc..507db1a4a 100644 --- a/man/add_coverage.Rd +++ b/man/add_coverage.Rd @@ -33,7 +33,7 @@ the unit of a single forecast. \examples{ library(magrittr) # pipe operator score(example_quantile) \%>\% - add_coverage(by = c("model", "target_type")) \%>\% + # add_coverage(by = c("model", "target_type")) \%>\% summarise_scores(by = c("model", "target_type")) \%>\% summarise_scores(fun = signif, digits = 2) } diff --git a/man/compare_two_models.Rd b/man/compare_two_models.Rd index 39780292e..1d4686a1c 100644 --- a/man/compare_two_models.Rd +++ b/man/compare_two_models.Rd @@ -22,7 +22,7 @@ compare_two_models( \item{name_model2}{character, name of the model to compare against} \item{metric}{A character vector of length one with the metric to do the -comparison on. The default is "auto", meaning that either "interval_score", +comparison on. The default is "auto", meaning that either "wis", "crps", or "brier_score" will be selected where available.} \item{one_sided}{Boolean, default is \code{FALSE}, whether two conduct a one-sided diff --git a/man/pairwise_comparison.Rd b/man/pairwise_comparison.Rd index 9288e77fb..d30be1197 100644 --- a/man/pairwise_comparison.Rd +++ b/man/pairwise_comparison.Rd @@ -25,7 +25,7 @@ splitting) and the pairwise comparisons will be computed separately for the split data.frames.} \item{metric}{A character vector of length one with the metric to do the -comparison on. The default is "auto", meaning that either "interval_score", +comparison on. The default is "auto", meaning that either "wis", "crps", or "brier_score" will be selected where available.} \item{baseline}{character vector of length one that denotes the baseline diff --git a/man/pairwise_comparison_one_group.Rd b/man/pairwise_comparison_one_group.Rd index a7d902f15..df59b1472 100644 --- a/man/pairwise_comparison_one_group.Rd +++ b/man/pairwise_comparison_one_group.Rd @@ -10,7 +10,7 @@ pairwise_comparison_one_group(scores, metric, baseline, by, ...) \item{scores}{A data.table of scores as produced by \code{\link[=score]{score()}}.} \item{metric}{A character vector of length one with the metric to do the -comparison on. The default is "auto", meaning that either "interval_score", +comparison on. The default is "auto", meaning that either "wis", "crps", or "brier_score" will be selected where available.} \item{baseline}{character vector of length one that denotes the baseline diff --git a/man/plot_interval_coverage.Rd b/man/plot_interval_coverage.Rd index 9c7da16fe..6c4c3e985 100644 --- a/man/plot_interval_coverage.Rd +++ b/man/plot_interval_coverage.Rd @@ -21,8 +21,8 @@ ggplot object with a plot of interval coverage Plot interval coverage } \examples{ -data.table::setDTthreads(1) # only needed to avoid issues on CRAN -scores <- score(example_quantile) -scores <- summarise_scores(scores, by = c("model", "range")) -plot_interval_coverage(scores) +# data.table::setDTthreads(1) # only needed to avoid issues on CRAN +# scores <- score(example_quantile) +# scores <- summarise_scores(scores, by = c("model", "range")) +# plot_interval_coverage(scores) } diff --git a/man/plot_ranges.Rd b/man/plot_ranges.Rd index a4a999ff2..27922b3c0 100644 --- a/man/plot_ranges.Rd +++ b/man/plot_ranges.Rd @@ -4,7 +4,7 @@ \alias{plot_ranges} \title{Plot Metrics by Range of the Prediction Interval} \usage{ -plot_ranges(scores, y = "interval_score", x = "model", colour = "range") +plot_ranges(scores, y = "wis", x = "model", colour = "range") } \arguments{ \item{scores}{A data.frame of scores based on quantile forecasts as @@ -12,7 +12,7 @@ produced by \code{\link[=score]{score()}} or \code{\link[=summarise_scores]{summ in the \code{by} argument when running \code{\link[=summarise_scores]{summarise_scores()}}} \item{y}{The variable from the scores you want to show on the y-Axis. -This could be something like "interval_score" (the default) or "dispersion"} +This could be something like "wis" (the default) or "dispersion"} \item{x}{The variable from the scores you want to show on the x-Axis. Usually this will be "model"} @@ -31,13 +31,13 @@ sharpness / dispersion changes by range. } \examples{ library(ggplot2) -scores <- score(example_quantile) -scores <- summarise_scores(scores, by = c("model", "target_type", "range")) +# scores <- score(example_quantile) +# scores <- summarise_scores(scores, by = c("model", "target_type", "range")) -plot_ranges(scores, x = "model") + - facet_wrap(~target_type, scales = "free") +# plot_ranges(scores, x = "model") + +# facet_wrap(~target_type, scales = "free") # visualise dispersion instead of interval score -plot_ranges(scores, y = "dispersion", x = "model") + - facet_wrap(~target_type) +# plot_ranges(scores, y = "dispersion", x = "model") + +# facet_wrap(~target_type) } From 337ea1f41ddf1a51193c1ecfac52d48d5a23f0ff Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 15:03:42 +0100 Subject: [PATCH 44/81] Replace score.scoringutils_quantile() with new function --- NAMESPACE | 2 +- R/score.R | 4 ++-- R/score_quantile.R | 2 +- R/z_globalVariables.R | 1 + man/score.Rd | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 32259fd85..ba1aa11be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,7 @@ S3method(score,default) S3method(score,scoringutils_binary) S3method(score,scoringutils_point) S3method(score,scoringutils_quantile) -S3method(score,scoringutils_quantile_new) +S3method(score,scoringutils_quantile_old) S3method(score,scoringutils_sample) S3method(validate,default) S3method(validate,scoringutils_binary) diff --git a/R/score.R b/R/score.R index 3d1dc7f07..fb82f6568 100644 --- a/R/score.R +++ b/R/score.R @@ -233,7 +233,7 @@ score.scoringutils_sample <- function(data, metrics = metrics_sample, ...) { #' @rdname score #' @export -score.scoringutils_quantile <- function(data, metrics = NULL, ...) { +score.scoringutils_quantile_old <- function(data, metrics = NULL, ...) { data <- validate(data) data <- remove_na_observed_predicted(data) forecast_unit <- attr(data, "forecast_unit") @@ -261,7 +261,7 @@ score.scoringutils_quantile <- function(data, metrics = NULL, ...) { #' @rdname score #' @export -score.scoringutils_quantile_new <- function(data, metrics = metrics_quantile, ...) { +score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { data <- validate(data) data <- remove_na_observed_predicted(data) forecast_unit <- attr(data, "forecast_unit") diff --git a/R/score_quantile.R b/R/score_quantile.R index f2da97f04..e0a3fb11c 100644 --- a/R/score_quantile.R +++ b/R/score_quantile.R @@ -113,7 +113,7 @@ score_quantile <- function(data, # compute absolute error of the median if ("ae_median" %in% metrics) { quantile_data[, ae_median := ae_median_quantile( - observed, + unique(observed), predicted, quantile ), diff --git a/R/z_globalVariables.R b/R/z_globalVariables.R index b81fb3452..441501932 100644 --- a/R/z_globalVariables.R +++ b/R/z_globalVariables.R @@ -72,6 +72,7 @@ globalVariables(c( "var_of_interest", "variable", "weight", + "wis", "wis_component_name", "x", "y", diff --git a/man/score.Rd b/man/score.Rd index 5cf7a1b14..9ae7ebf37 100644 --- a/man/score.Rd +++ b/man/score.Rd @@ -6,8 +6,8 @@ \alias{score.scoringutils_binary} \alias{score.scoringutils_point} \alias{score.scoringutils_sample} +\alias{score.scoringutils_quantile_old} \alias{score.scoringutils_quantile} -\alias{score.scoringutils_quantile_new} \title{Evaluate forecasts in a data.frame format} \usage{ score(data, ...) @@ -20,9 +20,9 @@ score(data, ...) \method{score}{scoringutils_sample}(data, metrics = metrics_sample, ...) -\method{score}{scoringutils_quantile}(data, metrics = NULL, ...) +\method{score}{scoringutils_quantile_old}(data, metrics = NULL, ...) -\method{score}{scoringutils_quantile_new}(data, metrics = metrics_quantile, ...) +\method{score}{scoringutils_quantile}(data, metrics = metrics_quantile, ...) } \arguments{ \item{data}{A data.frame or data.table with predicted and observed values.} From 7e6dbe8b14f061ac256f606b66655bb6d03b0dc0 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 15:04:57 +0100 Subject: [PATCH 45/81] update available_metrics() to include wis and coverage_ values (this is temporary) --- R/utils.R | 3 ++- man/plot_heatmap.Rd | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 3de1a9eb8..0d160065e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,7 +5,8 @@ #' @keywords info available_metrics <- function() { - return(unique(scoringutils::metrics$Name)) + return(unique(c(scoringutils::metrics$Name, + "wis", "coverage_50", "coverage_90"))) } diff --git a/man/plot_heatmap.Rd b/man/plot_heatmap.Rd index 8b1aac549..837ef4243 100644 --- a/man/plot_heatmap.Rd +++ b/man/plot_heatmap.Rd @@ -29,7 +29,7 @@ different locations. } \examples{ scores <- score(example_quantile) -scores <- summarise_scores(scores, by = c("model", "target_type", "range")) +scores <- summarise_scores(scores, by = c("model", "target_type")) plot_heatmap(scores, x = "target_type", metric = "bias") } From 08dab31028a5383a2510086d261a24312189a10f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 15:05:25 +0100 Subject: [PATCH 46/81] Update vignette to update / comment out code that cannot be run anymore --- vignettes/scoringutils.Rmd | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/vignettes/scoringutils.Rmd b/vignettes/scoringutils.Rmd index 6b55c25b5..6411fad70 100644 --- a/vignettes/scoringutils.Rmd +++ b/vignettes/scoringutils.Rmd @@ -223,7 +223,6 @@ For quantile-based forecasts we are often interested in specific coverage-levels ```{r} score(example_quantile) %>% - add_coverage(ranges = c(50, 90), by = c("model", "target_type")) %>% summarise_scores(by = c("model", "target_type")) %>% summarise_scores(fun = signif, digits = 2) ``` @@ -304,20 +303,20 @@ example_quantile[quantile %in% seq(0.1, 0.9, 0.1), ] %>% facet_grid(model ~ target_type) ``` -Another way to look at calibration are interval coverage and quantile coverage. Interval coverage is the percentage of true values that fall inside a given central prediction interval. Quantile coverage is the percentage of observed values that fall below a given quantile level. + -In order to plot interval coverage, you need to include "range" in the `by` argument to `summarise_scores()`. The green area on the plot marks conservative behaviour, i.e. your empirical coverage is greater than it nominally need be (e.g. 55% of true values covered by all 50% central prediction intervals.) + -```{r} +```{r, eval=FALSE, include=FALSE} example_quantile %>% score() %>% summarise_scores(by = c("model", "range")) %>% plot_interval_coverage() ``` -To visualise quantile coverage, you need to include "quantile" in `by`. Again, the green area corresponds to conservative forecasts, where central prediction intervals would cover more than needed. + -```{r} +```{r, eval=FALSE, include=FALSE} example_quantile %>% score() %>% summarise_scores(by = c("model", "quantile")) %>% @@ -377,11 +376,11 @@ example_quantile %>% plot_correlation() ``` -### Scores by interval ranges + -If you would like to see how different forecast interval ranges contribute to average scores, you can visualise scores by interval range: + -```{r} +```{r, eval = FALSE, include = FALSE} example_quantile %>% score() %>% summarise_scores(by = c("model", "range", "target_type")) %>% @@ -400,8 +399,8 @@ example_integer %>% sample_to_quantile( quantiles = c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) ) %>% - score() %>% - add_coverage(by = c("model", "target_type")) + score() # %>% + # add_coverage(by = c("model", "target_type")) ``` ## Available metrics From f4d5d43286e52c444f313648e23a12870ea29d42 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 15:08:29 +0100 Subject: [PATCH 47/81] Fix test for ae_median_sample() --- tests/testthat/test-absolute_error.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-absolute_error.R b/tests/testthat/test-absolute_error.R index f61493b25..118a182d8 100644 --- a/tests/testthat/test-absolute_error.R +++ b/tests/testthat/test-absolute_error.R @@ -1,9 +1,7 @@ -test_that("absolute error (sample based) works", { +test_that("ae_median_sample works", { observed <- rnorm(30, mean = 1:30) predicted_values <- rnorm(30, mean = 1:30) - - scoringutils <- ae_median_sample(observed, predicted_values) - + scoringutils <- ae_median_sample(observed, matrix(predicted_values)) ae <- abs(observed - predicted_values) expect_equal(ae, scoringutils) }) From 9607615aed28edd6834f1e354fc9ac0239bba967 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 16:14:57 +0100 Subject: [PATCH 48/81] Update tests --- .../plot_correlation/plot-correlation.svg | 218 +++++++++++------- .../_snaps/plot_heatmap/plot-heatmap.svg | 162 +------------ .../plot-pairwise-comparison-pval.svg | 8 +- .../plot-pairwise-comparison.svg | 8 +- .../plot_score_table/plot-score-table.svg | 158 +++++++------ .../_snaps/plot_wis/plot-wis-flip.svg | 12 +- .../_snaps/plot_wis/plot-wis-no-relative.svg | 12 +- tests/testthat/_snaps/plot_wis/plot-wis.svg | 12 +- tests/testthat/test-interval_score.R | 50 ++-- tests/testthat/test-pairwise_comparison.R | 6 +- tests/testthat/test-plot_heatmap.R | 4 +- tests/testthat/test-score.R | 26 +-- tests/testthat/test-summarise_scores.R | 2 - 13 files changed, 292 insertions(+), 386 deletions(-) diff --git a/tests/testthat/_snaps/plot_correlation/plot-correlation.svg b/tests/testthat/_snaps/plot_correlation/plot-correlation.svg index f56619980..a33e8a207 100644 --- a/tests/testthat/_snaps/plot_correlation/plot-correlation.svg +++ b/tests/testthat/_snaps/plot_correlation/plot-correlation.svg @@ -25,104 +25,146 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1 -0.46 -1 -0.28 -0.15 -1 -0.94 -0.32 --0.03 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1 +0.94 +1 +0.28 +-0.03 +1 +0.46 +0.32 +0.15 +1 +0.11 +0.22 +-0.35 +0.11 1 --0.34 --0.12 --0.33 --0.25 -1 -0.11 -0.11 --0.35 -0.22 -0.06 -1 -0.99 -0.54 -0.34 -0.9 --0.38 -0.1 -1 +-0.21 +-0.15 +-0.21 +-0.09 +0.01 +1 +-0.41 +-0.32 +-0.36 +-0.09 +0.1 +0.37 +1 +-0.34 +-0.25 +-0.33 +-0.12 +0.06 +0.85 +0.64 +1 +0.99 +0.9 +0.34 +0.54 +0.1 +-0.25 +-0.41 +-0.38 +1 -interval_score -dispersion -underprediction -overprediction -coverage_deviation -bias -ae_median - - - +wis +overprediction +underprediction +dispersion +bias +coverage_50 +coverage_90 +coverage_deviation +ae_median + + + + - - - + + + + - - - + + + + - - - -ae_median -bias -coverage_deviation -overprediction -underprediction -dispersion -interval_score - -0.0 -0.5 + + + + +ae_median +coverage_deviation +coverage_90 +coverage_50 +bias +dispersion +underprediction +overprediction +wis + +0.0 +0.5 1.0 Correlation - - + + - - + + plot__correlation diff --git a/tests/testthat/_snaps/plot_heatmap/plot-heatmap.svg b/tests/testthat/_snaps/plot_heatmap/plot-heatmap.svg index 528aefb09..8c4222d9a 100644 --- a/tests/testthat/_snaps/plot_heatmap/plot-heatmap.svg +++ b/tests/testthat/_snaps/plot_heatmap/plot-heatmap.svg @@ -25,174 +25,20 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 --0.06 --0.06 --0.06 --0.06 --0.06 --0.06 --0.06 --0.06 --0.06 -0.06 --0.06 --0.06 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 --0.08 +0.1 -0.08 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.34 -0.07 -0.07 -0.07 -0.07 0.07 -0.07 -0.07 -0.07 -0.07 -0.07 -0.07 -0.07 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 --0.02 +0.34 -0.02 -0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 --0.01 diff --git a/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison-pval.svg b/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison-pval.svg index 22e2408dc..458487011 100644 --- a/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison-pval.svg +++ b/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison-pval.svg @@ -28,8 +28,8 @@ - + @@ -37,8 +37,8 @@ < 0.001 < 0.001 1 -0.298 < 0.001 +0.298 1 0.298 < 0.001 @@ -56,9 +56,9 @@ + - @@ -72,9 +72,9 @@ < 0.001 < 0.001 1 +< 0.001 < 0.001 < 0.001 -< 0.001 1 0.007 < 0.001 diff --git a/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison.svg b/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison.svg index 1ff397cfe..3a7599da4 100644 --- a/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison.svg +++ b/tests/testthat/_snaps/plot_pairwise_comparison/plot-pairwise-comparison.svg @@ -28,8 +28,8 @@ - + @@ -37,8 +37,8 @@ 1.37 1.59 1 -0.86 0.63 +0.86 1 1.16 0.73 @@ -56,9 +56,9 @@ + - @@ -72,9 +72,9 @@ 3.03 3.85 1 +0.26 0.62 0.79 -0.26 1 0.74 1.27 diff --git a/tests/testthat/_snaps/plot_score_table/plot-score-table.svg b/tests/testthat/_snaps/plot_score_table/plot-score-table.svg index 95f9fe247..25b15d296 100644 --- a/tests/testthat/_snaps/plot_score_table/plot-score-table.svg +++ b/tests/testthat/_snaps/plot_score_table/plot-score-table.svg @@ -25,62 +25,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -10000 -9000 -50 -10000 -2000 -2000 -30 -3000 -5000 -2000 -20 -2000 -7000 -5000 -9 -6000 -0.002 -0.05 --0.02 --0.06 -0.2 -0.008 --0.02 --0.04 -20000 -10000 -80 -10000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9000 +10000 +10000 +50 +5000 +7000 +6000 +9 +2000 +5000 +2000 +20 +2000 +2000 +3000 +30 +0.008 +0.2 +-0.04 +-0.02 +0.6 +0.5 +0.4 +0.5 +0.9 +0.9 +0.8 +0.9 +0.05 +0.002 +-0.06 +-0.02 +10000 +20000 +10000 +80 @@ -93,20 +109,24 @@ - - - + + + + - - - -interval_score -dispersion -underprediction -overprediction -coverage_deviation -bias -ae_median + + + + +wis +overprediction +underprediction +dispersion +bias +coverage_50 +coverage_90 +coverage_deviation +ae_median plot_score_table diff --git a/tests/testthat/_snaps/plot_wis/plot-wis-flip.svg b/tests/testthat/_snaps/plot_wis/plot-wis-flip.svg index 758a3c147..c315cf06d 100644 --- a/tests/testthat/_snaps/plot_wis/plot-wis-flip.svg +++ b/tests/testthat/_snaps/plot_wis/plot-wis-flip.svg @@ -25,14 +25,14 @@ - + - + - + @@ -43,16 +43,16 @@ - + - + - + diff --git a/tests/testthat/_snaps/plot_wis/plot-wis-no-relative.svg b/tests/testthat/_snaps/plot_wis/plot-wis-no-relative.svg index 987072ca4..fea309214 100644 --- a/tests/testthat/_snaps/plot_wis/plot-wis-no-relative.svg +++ b/tests/testthat/_snaps/plot_wis/plot-wis-no-relative.svg @@ -25,14 +25,14 @@ - + - + - + @@ -43,16 +43,16 @@ - + - + - + diff --git a/tests/testthat/_snaps/plot_wis/plot-wis.svg b/tests/testthat/_snaps/plot_wis/plot-wis.svg index 5328b4779..a2bdf8653 100644 --- a/tests/testthat/_snaps/plot_wis/plot-wis.svg +++ b/tests/testthat/_snaps/plot_wis/plot-wis.svg @@ -25,14 +25,14 @@ - + - + - + @@ -43,16 +43,16 @@ - + - + - + diff --git a/tests/testthat/test-interval_score.R b/tests/testthat/test-interval_score.R index 2a75c6fdb..04e0807a5 100644 --- a/tests/testthat/test-interval_score.R +++ b/tests/testthat/test-interval_score.R @@ -1,3 +1,6 @@ +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] + test_that("wis works, median only", { y <- c(1, -15, 22) lower <- upper <- predicted_quantile <- c(1, 2, 3) @@ -28,10 +31,11 @@ test_that("WIS works within score for median forecast", { model = "model1", date = 1:3 ) - eval <- scoringutils::score(test_data, - count_median_twice = TRUE + eval <- score( + test_data, + count_median_twice = TRUE, metrics = metrics_no_cov ) - expect_equal(eval$ae_median, eval$interval_score) + expect_equal(eval$ae_median, eval$wis) }) test_that("wis works, 1 interval only", { @@ -70,8 +74,9 @@ test_that("WIS works within score for one interval", { date = rep(1:3, times = 2) ) - eval <- suppressMessages(scoringutils::score(test_data, - count_median_twice = TRUE + eval <- suppressMessages(score( + test_data, + count_median_twice = TRUE, metrics = metrics_no_cov_no_ae )) eval <- summarise_scores(eval, by = c("model", "date")) @@ -82,7 +87,7 @@ test_that("WIS works within score for one interval", { expected <- (upper - lower) * (alpha / 2) + c(0, 1 - (-15), 22 - 3) - expect_equal(expected, eval$interval_score) + expect_equal(expected, eval$wis) }) test_that("wis works, 1 interval and median", { @@ -94,8 +99,9 @@ test_that("wis works, 1 interval and median", { date = rep(1:3, times = 3) ) - eval <- scoringutils::score(test_data, - count_median_twice = TRUE + eval <- score( + test_data, + count_median_twice = TRUE, metrics = metrics_no_cov ) eval <- summarise_scores(eval, by = c("model", "date")) @@ -117,7 +123,7 @@ test_that("wis works, 1 interval and median", { count_median_twice = TRUE ) - expect_identical(eval$interval_score, expected) + expect_identical(eval$wis, expected) expect_identical(actual_wis, expected) }) @@ -142,8 +148,9 @@ test_that("wis works, 2 intervals and median", { date = rep(1:3, times = 5) ) - eval <- scoringutils::score(test_data, - count_median_twice = TRUE + eval <- score( + test_data, + count_median_twice = TRUE, metrics = metrics_no_cov ) eval <- summarise_scores(eval, by = c("model", "date")) @@ -168,7 +175,7 @@ test_that("wis works, 2 intervals and median", { ) expect_equal( - as.numeric(eval$interval_score), + as.numeric(eval$wis), as.numeric(expected) ) expect_identical(actual_wis, expected) @@ -228,8 +235,9 @@ test_that("wis is correct, median only - test corresponds to covidHubUtils", { data_formatted <- merge(forecasts_formated, truth_formatted) - eval <- scoringutils::score(data_formatted, - count_median_twice = FALSE + eval <- score( + data_formatted, + count_median_twice = FALSE, metrics = metrics_no_cov ) expected <- abs(y - forecast_quantiles_matrix[, 1]) @@ -241,7 +249,7 @@ test_that("wis is correct, median only - test corresponds to covidHubUtils", { count_median_twice = FALSE ) - expect_equal(eval$interval_score, expected) + expect_equal(eval$wis, expected) expect_equal(actual_wis, expected) }) @@ -299,8 +307,8 @@ test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", data_formatted <- merge(forecasts_formated, truth_formatted) - eval <- suppressMessages(scoringutils::score(data_formatted, - count_median_twice = FALSE + eval <- suppressMessages(score(data_formatted, + count_median_twice = FALSE, metrics = metrics_no_cov_no_ae )) eval <- summarise_scores(eval, @@ -321,7 +329,7 @@ test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", count_median_twice = FALSE ) - expect_equal(eval$interval_score, expected) + expect_equal(eval$wis, expected) expect_equal(actual_wis, expected) }) @@ -376,8 +384,8 @@ test_that("wis is correct, 2 intervals and median - test corresponds to covidHub data_formatted <- merge(forecasts_formated, truth_formatted) - eval <- scoringutils::score(data_formatted, - count_median_twice = FALSE + eval <- score(data_formatted, + count_median_twice = FALSE, metrics = metrics_no_cov ) eval <- summarise_scores(eval, @@ -402,7 +410,7 @@ test_that("wis is correct, 2 intervals and median - test corresponds to covidHub count_median_twice = FALSE ) - expect_equal(eval$interval_score, expected) + expect_equal(eval$wis, expected) }) test_that("Quantlie score and interval score yield the same result, weigh = FALSE", { diff --git a/tests/testthat/test-pairwise_comparison.R b/tests/testthat/test-pairwise_comparison.R index 3d0120adb..74275a06a 100644 --- a/tests/testthat/test-pairwise_comparison.R +++ b/tests/testthat/test-pairwise_comparison.R @@ -53,7 +53,7 @@ test_that("pairwise_comparison() works", { ) # evaluate the toy forecasts, once with and once without a baseline model specified - eval <- suppressMessages(score(data_formatted)) + eval <- score(data_formatted) # check with relative skills eval_without_rel_skill <- summarise_scores( @@ -85,7 +85,7 @@ test_that("pairwise_comparison() works", { # prepare scores for the code Johannes Bracher wrote scores_johannes <- data.table::copy(eval_without_baseline) # doesn't matter which one data.table::setnames(scores_johannes, - old = c("location", "target_end_date", "interval_score"), + old = c("location", "target_end_date", "wis"), new = c("unit", "timezero", "wis") ) @@ -238,7 +238,7 @@ test_that("pairwise_comparison() works", { model = rep(c("model1", "model2", "model3"), each = 10), date = as.Date("2020-01-01") + rep(1:5, each = 2), location = c(1, 2), - interval_score = (abs(rnorm(30))), + wis = (abs(rnorm(30))), ae_median = (abs(rnorm(30))) ) diff --git a/tests/testthat/test-plot_heatmap.R b/tests/testthat/test-plot_heatmap.R index 9118ff21f..d6453bd45 100644 --- a/tests/testthat/test-plot_heatmap.R +++ b/tests/testthat/test-plot_heatmap.R @@ -1,9 +1,7 @@ library(ggplot2, quietly = TRUE) test_that("plot_heatmap() works as expected", { - scores <- suppressMessages( - summarise_scores(scores_quantile, by = c("model", "target_type", "range")) - ) + scores <- summarise_scores(scores_quantile, by = c("model", "target_type")) p <- plot_heatmap(scores, x = "target_type", metric = "bias") expect_s3_class(p, "ggplot") skip_on_cran() diff --git a/tests/testthat/test-score.R b/tests/testthat/test-score.R index 9b4040723..6252c12c8 100644 --- a/tests/testthat/test-score.R +++ b/tests/testthat/test-score.R @@ -1,3 +1,6 @@ +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] + # common error handling -------------------------------------------------------- test_that("function throws an error if data is missing", { expect_error(suppressMessages(score(data = NULL))) @@ -191,10 +194,12 @@ test_that("score() quantile produces desired metrics", { quantile = rep(c(0.1, 0.9), times = 10) ) - out <- suppressMessages(score(data = data)) + out <- suppressWarnings(suppressMessages( + score(data = data, metrics = metrics_no_cov)) + ) metric_names <- c( "dispersion", "underprediction", "overprediction", - "bias", "ae_median", "coverage_deviation" + "bias", "ae_median" ) expect_true(all(metric_names %in% colnames(out))) @@ -227,27 +232,16 @@ test_that("all quantile and range formats yield the same result", { expect_equal(sort(eval1$ae_median), sort(ae)) }) -test_that("function produces output even if only some metrics are chosen", { - example <- scoringutils::example_quantile - - eval <- suppressMessages(score(example, metrics = "coverage")) - - expect_equal( - nrow(eval) > 1, - TRUE - ) -}) - test_that("WIS is the same with other metrics omitted or included", { eval <- suppressMessages(score(example_quantile, - metrics = "interval_score" + metrics = list("wis" = wis) )) eval2 <- scores_quantile expect_equal( - sum(eval$interval_score), - sum(eval2$interval_score) + sum(eval$wis), + sum(eval2$wis) ) }) diff --git a/tests/testthat/test-summarise_scores.R b/tests/testthat/test-summarise_scores.R index dc3de70e3..dbd2cde4b 100644 --- a/tests/testthat/test-summarise_scores.R +++ b/tests/testthat/test-summarise_scores.R @@ -1,6 +1,4 @@ test_that("summarise_scores() works without any arguments", { - expect_true("quantile" %in% names(scores_quantile)) - summarised_scores <- summarise_scores(scores_quantile) expect_false("quantile" %in% names(summarised_scores)) From c214adec4e8f0ac7c083c20746bd7222bca3c5a7 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 16:21:27 +0100 Subject: [PATCH 49/81] comment out / delete failing tests related to ranges in the output of score() --- man/plot_quantile_coverage.Rd | 6 +- tests/testthat/test-add_coverage.R | 62 ++++++++++---------- tests/testthat/test-plot_interval_coverage.R | 17 +++--- tests/testthat/test-plot_quantile_coverage.R | 18 +++--- tests/testthat/test-plot_ranges.R | 38 ++++++------ tests/testthat/test-plot_score_table.R | 1 - 6 files changed, 70 insertions(+), 72 deletions(-) diff --git a/man/plot_quantile_coverage.Rd b/man/plot_quantile_coverage.Rd index 2e6ef489e..c479fb5e3 100644 --- a/man/plot_quantile_coverage.Rd +++ b/man/plot_quantile_coverage.Rd @@ -21,7 +21,7 @@ ggplot object with a plot of interval coverage Plot quantile coverage } \examples{ -scores <- score(example_quantile) -scores <- summarise_scores(scores, by = c("model", "quantile")) -plot_quantile_coverage(scores) +# scores <- score(example_quantile) +# scores <- summarise_scores(scores, by = c("model", "quantile")) +# plot_quantile_coverage(scores) } diff --git a/tests/testthat/test-add_coverage.R b/tests/testthat/test-add_coverage.R index fab1e72a1..50d97e81a 100644 --- a/tests/testthat/test-add_coverage.R +++ b/tests/testthat/test-add_coverage.R @@ -1,31 +1,31 @@ -ex_coverage <- scores_quantile[model == "EuroCOVIDhub-ensemble"] - -test_that("add_coverage() works as expected", { - expect_error( - add_coverage(ex_coverage, by = c("model", "target_type"), range = c()) - ) - expect_error( - add_coverage(ex_coverage, by = c("model", "target_type")), NA - ) - cov <- add_coverage( - scores_quantile, by = c("model", "target_type"), range = c(10, 20) - ) - expect_equal( - grep("coverage_", colnames(cov), value = TRUE), - c("coverage_deviation", "coverage_10", "coverage_20") - ) -}) - - -test_that("Order of `add_coverage()` and `summarise_scores()` doesn't matter", { - # Need to update test. Turns out the order does matter... - # see https://github.com/epiforecasts/scoringutils/issues/367 - pw1 <- add_coverage(ex_coverage, by = "model") - pw1_sum <- summarise_scores(pw1, by = "model") - - pw2 <- summarise_scores(ex_coverage, by = "model") - pw2 <- add_coverage(pw2) - - # expect_true(all(pw1_sum == pw2, na.rm = TRUE)) - # expect_true(all(names(attributes(pw2)) == names(attributes(pw1_sum)))) -}) +# ex_coverage <- scores_quantile[model == "EuroCOVIDhub-ensemble"] +# +# test_that("add_coverage() works as expected", { +# expect_error( +# add_coverage(ex_coverage, by = c("model", "target_type"), range = c()) +# ) +# expect_error( +# add_coverage(ex_coverage, by = c("model", "target_type")), NA +# ) +# cov <- add_coverage( +# scores_quantile, by = c("model", "target_type"), range = c(10, 20) +# ) +# expect_equal( +# grep("coverage_", colnames(cov), value = TRUE), +# c("coverage_deviation", "coverage_10", "coverage_20") +# ) +# }) +# +# +# test_that("Order of `add_coverage()` and `summarise_scores()` doesn't matter", { +# # Need to update test. Turns out the order does matter... +# # see https://github.com/epiforecasts/scoringutils/issues/367 +# pw1 <- add_coverage(ex_coverage, by = "model") +# pw1_sum <- summarise_scores(pw1, by = "model") +# +# pw2 <- summarise_scores(ex_coverage, by = "model") +# pw2 <- add_coverage(pw2) +# +# # expect_true(all(pw1_sum == pw2, na.rm = TRUE)) +# # expect_true(all(names(attributes(pw2)) == names(attributes(pw1_sum)))) +# }) diff --git a/tests/testthat/test-plot_interval_coverage.R b/tests/testthat/test-plot_interval_coverage.R index 04f203b03..49649e090 100644 --- a/tests/testthat/test-plot_interval_coverage.R +++ b/tests/testthat/test-plot_interval_coverage.R @@ -1,11 +1,10 @@ library(ggplot2, quietly = TRUE) -test_that("plot_interval_coverage() works as expected", { - scores <- suppressMessages( - summarise_scores(scores_quantile, by = c("model", "range")) - ) - p <- plot_interval_coverage(scores) - expect_s3_class(p, "ggplot") - skip_on_cran() - vdiffr::expect_doppelganger("plot_interval_coverage", p) -}) +# test_that("plot_interval_coverage() works as expected", { +# scores <- +# summarise_scores(scores_quantile, by = c("model", "range")) +# p <- plot_interval_coverage(scores) +# expect_s3_class(p, "ggplot") +# skip_on_cran() +# vdiffr::expect_doppelganger("plot_interval_coverage", p) +# }) diff --git a/tests/testthat/test-plot_quantile_coverage.R b/tests/testthat/test-plot_quantile_coverage.R index 6c3593c04..84b91157f 100644 --- a/tests/testthat/test-plot_quantile_coverage.R +++ b/tests/testthat/test-plot_quantile_coverage.R @@ -1,9 +1,9 @@ -test_that("plot_quantile_coverage() works as expected", { - scores <- suppressMessages( - summarise_scores(scores_quantile, by = c("model", "quantile")) - ) - p <- plot_quantile_coverage(scores) - expect_s3_class(p, "ggplot") - skip_on_cran() - vdiffr::expect_doppelganger("plot_quantile_coverage", p) -}) +# test_that("plot_quantile_coverage() works as expected", { +# scores <- suppressMessages( +# summarise_scores(scores_quantile, by = c("model", "quantile")) +# ) +# p <- plot_quantile_coverage(scores) +# expect_s3_class(p, "ggplot") +# skip_on_cran() +# vdiffr::expect_doppelganger("plot_quantile_coverage", p) +# }) diff --git a/tests/testthat/test-plot_ranges.R b/tests/testthat/test-plot_ranges.R index e9ae5575b..fad3c8095 100644 --- a/tests/testthat/test-plot_ranges.R +++ b/tests/testthat/test-plot_ranges.R @@ -1,19 +1,19 @@ -sum_scores <- suppressMessages( - summarise_scores(scores_quantile, by = c("model", "target_type", "range")) -) - -test_that("plot_ranges() works as expected with interval score", { - p <- plot_ranges(sum_scores, x = "model") + - facet_wrap(~target_type, scales = "free") - expect_s3_class(p, "ggplot") - skip_on_cran() - vdiffr::expect_doppelganger("plot_ranges_interval", p) -}) - -test_that("plot_ranges() works as expected with dispersion", { - p <- plot_ranges(sum_scores, y = "dispersion", x = "model") + - facet_wrap(~target_type) - expect_s3_class(p, "ggplot") - skip_on_cran() - vdiffr::expect_doppelganger("plot_ranges_dispersion", p) -}) +# sum_scores <- suppressMessages( +# summarise_scores(scores_quantile, by = c("model", "target_type", "range")) +# ) +# +# test_that("plot_ranges() works as expected with interval score", { +# p <- plot_ranges(sum_scores, x = "model") + +# facet_wrap(~target_type, scales = "free") +# expect_s3_class(p, "ggplot") +# skip_on_cran() +# vdiffr::expect_doppelganger("plot_ranges_interval", p) +# }) +# +# test_that("plot_ranges() works as expected with dispersion", { +# p <- plot_ranges(sum_scores, y = "dispersion", x = "model") + +# facet_wrap(~target_type) +# expect_s3_class(p, "ggplot") +# skip_on_cran() +# vdiffr::expect_doppelganger("plot_ranges_dispersion", p) +# }) diff --git a/tests/testthat/test-plot_score_table.R b/tests/testthat/test-plot_score_table.R index 8336de7a9..5ffc0b029 100644 --- a/tests/testthat/test-plot_score_table.R +++ b/tests/testthat/test-plot_score_table.R @@ -1,7 +1,6 @@ test_that("plot_score_table() works as expected", { p <- suppressMessages( scores_quantile %>% - add_coverage(by = c("model")) %>% summarise_scores(by = c("model")) %>% summarise_scores(by = c("model"), fun = signif, digits = 1) %>% plot_score_table() From 71d6d657c3a4e33655d8db8a8694a38e8bb170bc Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 16:46:32 +0100 Subject: [PATCH 50/81] Delete old version of `score.score_quantile()` --- NAMESPACE | 1 - R/score.R | 29 +------- R/score_quantile.R | 167 ------------------------------------------ man/score.Rd | 3 - man/score_quantile.Rd | 62 ---------------- 5 files changed, 1 insertion(+), 261 deletions(-) delete mode 100644 R/score_quantile.R delete mode 100644 man/score_quantile.Rd diff --git a/NAMESPACE b/NAMESPACE index ba1aa11be..e4ae0d765 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,6 @@ S3method(score,default) S3method(score,scoringutils_binary) S3method(score,scoringutils_point) S3method(score,scoringutils_quantile) -S3method(score,scoringutils_quantile_old) S3method(score,scoringutils_sample) S3method(validate,default) S3method(validate,scoringutils_binary) diff --git a/R/score.R b/R/score.R index fb82f6568..73998a64d 100644 --- a/R/score.R +++ b/R/score.R @@ -231,34 +231,7 @@ score.scoringutils_sample <- function(data, metrics = metrics_sample, ...) { return(data[]) } -#' @rdname score -#' @export -score.scoringutils_quantile_old <- function(data, metrics = NULL, ...) { - data <- validate(data) - data <- remove_na_observed_predicted(data) - forecast_unit <- attr(data, "forecast_unit") - - if (is.null(metrics)) { - metrics <- available_metrics() - } - metrics <- metrics[metrics %in% available_metrics()] - scores <- score_quantile( - data = data, - forecast_unit = forecast_unit, - metrics = metrics, - ... - ) - - setattr(scores, "metric_names", metrics[metrics %in% colnames(scores)]) - # manual hack to make sure that the correct attributes are there. - setattr(scores, "forecast_unit", forecast_unit) - setattr(scores, "forecast_type", "quantile") - scores <- new_scoringutils(scores, "scoringutils_quantile") - - return(scores[]) -} - - +#' @importFrom data.table `:=` as.data.table rbindlist %like% #' @rdname score #' @export score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { diff --git a/R/score_quantile.R b/R/score_quantile.R deleted file mode 100644 index e0a3fb11c..000000000 --- a/R/score_quantile.R +++ /dev/null @@ -1,167 +0,0 @@ -#' @title Evaluate forecasts in a Quantile-Based Format -#' -#' @inheritParams score -#' @inheritParams interval_score -#' @param count_median_twice logical that controls whether or not to count the -#' median twice when summarising (default is \code{FALSE}). Counting the -#' median twice would conceptually treat it as a 0\% prediction interval, where -#' the median is the lower as well as the upper bound. The alternative is to -#' treat the median as a single quantile forecast instead of an interval. The -#' interval score would then be better understood as an average of quantile -#' scores. -#' @param forecast_unit A character vector with the column names that define -#' the unit of a single forecast, i.e. a forecast was made for a combination -#' of the values in `forecast_unit` -#' -#' @return A data.table with appropriate scores. For more information see -#' [score()] -#' -#' @importFrom data.table ':=' as.data.table rbindlist %like% -#' -#' @author Nikos Bosse \email{nikosbosse@@gmail.com} -#' @inherit score references -#' @keywords internal - -score_quantile <- function(data, - forecast_unit, - metrics, - weigh = TRUE, - count_median_twice = FALSE, - separate_results = TRUE) { - - data <- remove_na_observed_predicted(data) - - # make sure to have both quantile as well as range format -------------------- - range_data <- quantile_to_interval( - data, - keep_quantile_col = FALSE - ) - # adds the range column to the quantile data set - quantile_data <- range_long_to_quantile( - range_data, - keep_range_col = TRUE - ) - - # to deal with point forecasts in a quantile format. This in effect adds - # a third column next to lower and upper after pivoting - range_data[is.na(range), boundary := "point"] - - range_data <- data.table::dcast(range_data, ... ~ boundary, - value.var = "predicted" - ) - - # if we only score point forecasts, it may be true that there are no columns - # upper and lower in the data.frame. If so, these need to be added - if (!all(c("upper", "lower") %in% colnames(range_data))) { - range_data[, c("upper", "lower") := NA] - } - - # set up results data.table that will then be modified throughout ------------ - res <- data.table::copy(range_data) - - # calculate scores on range format ------------------------------------------- - if ("interval_score" %in% metrics) { - # compute separate results if desired - if (separate_results) { - outcols <- c( - "interval_score", "dispersion", - "underprediction", "overprediction" - ) - } else { - outcols <- "interval_score" - } - res <- res[, eval(outcols) := do.call( - scoringutils::interval_score, - list(observed, lower, - upper, range, - weigh, - separate_results = separate_results - ) - )] - } - - # compute coverage for every single observation - if ("coverage" %in% metrics) { - res[, coverage := ifelse(observed <= upper & observed >= lower, 1, 0)] # nolint - res[, coverage_deviation := coverage - range / 100] - } - - # compute bias - if ("bias" %in% metrics) { - res[, bias := bias_range( - range = range, lower = lower, upper = upper, - observed = unique(observed) - ), - by = forecast_unit - ] - } - - # compute absolute and squared error for point forecasts - # these are marked by an NA in range, and a numeric value for point - compute_point <- any( - c("se_point, se_mean, ae_point", "ae_median", "absolute_error") %in% metrics - ) - if (compute_point && "point" %in% colnames(res)) { - res[ - is.na(range) & is.numeric(point), - `:=`(ae_point = abs_error(predicted = point, observed), - se_point = squared_error(predicted = point, observed)) - ] - } - - # calculate scores on quantile format ---------------------------------------- - # compute absolute error of the median - if ("ae_median" %in% metrics) { - quantile_data[, ae_median := ae_median_quantile( - unique(observed), - predicted, - quantile - ), - by = forecast_unit - ] - } - - # compute quantile coverage based on quantile version - if ("quantile_coverage" %in% metrics) { - quantile_data[, quantile_coverage := (observed <= predicted)] - } - - # merge metrics computed on quantile data (i.e. ae_median, quantile_coverage) back - # into metrics computed on range data. One important side effect of this is - # that it controls whether we count the median twice for the interval score - # (row is then duplicated) or only once. However, merge only needs to happen - # if we computed either the interval score or the ae_median or quantile coverage - if (any(c("ae_median", "interval_score", "quantile_coverage") %in% metrics)) { - # delete unnecessary columns before merging back - keep_cols <- unique(c( - forecast_unit, "quantile", "ae_median", "quantile_coverage", - "boundary", "range" - )) - delete_cols <- names(quantile_data)[!(names(quantile_data) %in% keep_cols)] - quantile_data[, eval(delete_cols) := NULL] - - # duplicate median column before merging if median is to be counted twice - # if this is false, then the res will have one entry for every quantile, - # which translates to two rows for every interval, but only one for the median - if (count_median_twice) { - median <- quantile_data[quantile == 0.5, ][, boundary := "upper"] - quantile_data <- data.table::rbindlist(list(quantile_data, median)) - } - - # merge back with other metrics - merge_cols <- setdiff(keep_cols, c( - "ae_median", "quantile_coverage", "quantile", - "boundary" - )) - # specify all.x = TRUE as the point forecasts got deleted when - # going from range to quantile above - res <- merge(res, quantile_data, by = merge_cols, all.x = TRUE) - } - - # delete internal columns before returning result - res <- delete_columns( - res, c("upper", "lower", "boundary", "point", "observed") - ) - - return(res[]) -} diff --git a/man/score.Rd b/man/score.Rd index 9ae7ebf37..c26fbb24c 100644 --- a/man/score.Rd +++ b/man/score.Rd @@ -6,7 +6,6 @@ \alias{score.scoringutils_binary} \alias{score.scoringutils_point} \alias{score.scoringutils_sample} -\alias{score.scoringutils_quantile_old} \alias{score.scoringutils_quantile} \title{Evaluate forecasts in a data.frame format} \usage{ @@ -20,8 +19,6 @@ score(data, ...) \method{score}{scoringutils_sample}(data, metrics = metrics_sample, ...) -\method{score}{scoringutils_quantile_old}(data, metrics = NULL, ...) - \method{score}{scoringutils_quantile}(data, metrics = metrics_quantile, ...) } \arguments{ diff --git a/man/score_quantile.Rd b/man/score_quantile.Rd deleted file mode 100644 index 5f51f94ec..000000000 --- a/man/score_quantile.Rd +++ /dev/null @@ -1,62 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/score_quantile.R -\name{score_quantile} -\alias{score_quantile} -\title{Evaluate forecasts in a Quantile-Based Format} -\usage{ -score_quantile( - data, - forecast_unit, - metrics, - weigh = TRUE, - count_median_twice = FALSE, - separate_results = TRUE -) -} -\arguments{ -\item{data}{A data.frame or data.table with predicted and observed values.} - -\item{forecast_unit}{A character vector with the column names that define -the unit of a single forecast, i.e. a forecast was made for a combination -of the values in \code{forecast_unit}} - -\item{metrics}{A named list of scoring functions. Names will be used as -column names in the output. See \code{\link[=metrics_point]{metrics_point()}}, \code{\link[=metrics_binary]{metrics_binary()}}, -\code{metrics_quantile()}, and \code{\link[=metrics_sample]{metrics_sample()}} for more information on the -default metrics used.} - -\item{weigh}{if TRUE, weigh the score by alpha / 2, so it can be averaged -into an interval score that, in the limit, corresponds to CRPS. Alpha is the -decimal value that represents how much is outside a central prediction -interval (e.g. for a 90 percent central prediction interval, alpha is 0.1) -Default: \code{TRUE}.} - -\item{count_median_twice}{logical that controls whether or not to count the -median twice when summarising (default is \code{FALSE}). Counting the -median twice would conceptually treat it as a 0\\% prediction interval, where -the median is the lower as well as the upper bound. The alternative is to -treat the median as a single quantile forecast instead of an interval. The -interval score would then be better understood as an average of quantile -scores.} - -\item{separate_results}{if \code{TRUE} (default is \code{FALSE}), then the separate -parts of the interval score (dispersion penalty, penalties for over- and -under-prediction get returned as separate elements of a list). If you want a -\code{data.frame} instead, simply call \code{\link[=as.data.frame]{as.data.frame()}} on the output.} -} -\value{ -A data.table with appropriate scores. For more information see -\code{\link[=score]{score()}} -} -\description{ -Evaluate forecasts in a Quantile-Based Format -} -\references{ -Bosse NI, Gruson H, Cori A, van Leeuwen E, Funk S, Abbott S -(2022) Evaluating Forecasts with scoringutils in R. -\doi{10.48550/arXiv.2205.07090} -} -\author{ -Nikos Bosse \email{nikosbosse@gmail.com} -} -\keyword{internal} From 596dcee630248aa3357363b884e4a8d466b6db6d Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 17:39:15 +0100 Subject: [PATCH 51/81] improve the way that data.frames are split in `score()` to deal with differing quantiles --- R/score.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/score.R b/R/score.R index 73998a64d..d373fd3e0 100644 --- a/R/score.R +++ b/R/score.R @@ -248,12 +248,13 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { d_transposed <- data[, .(predicted = list(predicted[order(quantile)]), observed = unique(observed), quantile = list(quantile[order(quantile)]), - N = length(quantile)), by = forecast_unit] + scoringutils_quantile = toString(quantile[order(quantile)])), + by = forecast_unit] # split according to quantile lengths and do calculations for different # quantile lengths separately. The function `wis()` assumes that all # forecasts have the same quantiles - d_split <- split(d_transposed, d_transposed$N) + d_split <- split(d_transposed, d_transposed$scoringutils_quantile) split_result <- lapply(d_split, function(data) { # create a matrix out of the list of predicted values and quantiles @@ -278,6 +279,7 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { }) data <- rbindlist(split_result) + data[, "scoringutils_quantile" := NULL] setattr(data, "metric_names", names(metrics)) return(data[]) From 6989f5d94cd5ae92d3371d15df485e740c859c6a Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 18:42:22 +0100 Subject: [PATCH 52/81] Add test file for binary metrics and input checks --- tests/testthat/setup.R | 1 + tests/testthat/test-metrics-binary.R | 66 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/testthat/test-metrics-binary.R diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index c157fb958..ac7057386 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -1,5 +1,6 @@ # load common required test packages library(ggplot2, quietly = TRUE) +library(data.table) suppressMessages(library(magrittr)) # compute quantile scores diff --git a/tests/testthat/test-metrics-binary.R b/tests/testthat/test-metrics-binary.R new file mode 100644 index 000000000..5eed53714 --- /dev/null +++ b/tests/testthat/test-metrics-binary.R @@ -0,0 +1,66 @@ +observed <- factor(rbinom(10, size = 1, prob = 0.5)) +predicted <- c(0.425, 0.55, 0.541, 0.52, 0.13, 0.469, 0.86, 0.22, 0.74, 0.9) +df <- data.table( + observed = observed, + predicted = predicted, + model = "m1", + id = 1:10 +) + +# test input handling +test_that("Input checking for binary forecasts works", { + # everything correct + expect_no_condition( + scoringutils:::assert_input_binary(observed, predicted) + ) + + # predicted > 1 + expect_error( + scoringutils:::assert_input_binary(observed, predicted + 1), + "Assertion on 'predicted' failed: Element 1 is not <= 1." + ) + + # predicted < 0 + expect_error( + scoringutils:::assert_input_binary(observed, predicted - 1), + "Assertion on 'predicted' failed: Element 1 is not >= 0." + ) + + # observed value not factor + expect_error( + scoringutils:::assert_input_binary(1:10, predicted), + "Assertion on 'observed' failed: Must be of type 'factor', not 'integer'." + ) + + # observed value has not 2 levels + expect_error( + scoringutils:::assert_input_binary(factor(1:10), predicted), + "Assertion on 'observed' failed: Must have exactly 2 levels." + ) + + # observed is a single number and does not have the same length as predicted + expect_error( + scoringutils:::assert_input_binary(factor(1), predicted), + "`observed` and `predicted` need to be of same length when scoring binary forecasts." + ) + + # predicted is a matrix + expect_error( + scoringutils:::assert_input_binary(observed, matrix(predicted)), + "Assertion on 'predicted' failed: Must be of type 'atomic vector', not 'matrix'." + ) + # Note: maybe we should allow + # 1) observed to be a vector and 2) predicted to be a matrix for consistency +}) + +test_that("Binary metrics work within and outside of `score()`", { + result <- score(df) + expect_equal( + brier_score(observed, predicted), + result$brier_score + ) + expect_equal( + logs_binary(observed, predicted), + result$log_score + ) +}) From 376de95471f9fe237e8231d4bc08e6186e31fef6 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 18:46:22 +0100 Subject: [PATCH 53/81] Remove comment (to be turned into an issue) --- tests/testthat/test-metrics-binary.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/testthat/test-metrics-binary.R b/tests/testthat/test-metrics-binary.R index 5eed53714..958262a67 100644 --- a/tests/testthat/test-metrics-binary.R +++ b/tests/testthat/test-metrics-binary.R @@ -49,8 +49,6 @@ test_that("Input checking for binary forecasts works", { scoringutils:::assert_input_binary(observed, matrix(predicted)), "Assertion on 'predicted' failed: Must be of type 'atomic vector', not 'matrix'." ) - # Note: maybe we should allow - # 1) observed to be a vector and 2) predicted to be a matrix for consistency }) test_that("Binary metrics work within and outside of `score()`", { From b13f00ae4a3184308fd8a231af3a2c56ac5331ee Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 19:05:53 +0100 Subject: [PATCH 54/81] small fix in score.scoringutils_quantile to avoid a warning --- R/score.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/score.R b/R/score.R index d373fd3e0..7ec7763e3 100644 --- a/R/score.R +++ b/R/score.R @@ -261,7 +261,7 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { observed <- data$observed predicted <- do.call(rbind, data$predicted) quantile <- unlist(unique(data$quantile)) - data[, c("observed", "predicted", "quantile", "N") := NULL] + data[, c("observed", "predicted", "quantile", "scoringutils_quantile") := NULL] # for each metric, compute score lapply(seq_along(metrics), function(i, ...) { @@ -279,7 +279,6 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { }) data <- rbindlist(split_result) - data[, "scoringutils_quantile" := NULL] setattr(data, "metric_names", names(metrics)) return(data[]) From 983c03095f8172e6f1d9d532dfae845fd84308a8 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 19:20:23 +0100 Subject: [PATCH 55/81] move tests around so they better correspond to file names used for actual functions --- tests/testthat/test-bias.R | 311 ------------------ tests/testthat/test-get_-functions.R | 39 +++ tests/testthat/test-get_duplicate_forecasts.R | 37 --- .../test-lower-level-check-functions.R | 116 ------- tests/testthat/test-metrics-binary.R | 75 +++++ ...-absolute_error.R => test-metrics-point.R} | 60 +--- ...terval_score.R => test-metrics-quantile.R} | 240 ++++++++++++-- tests/testthat/test-metrics-range.R | 45 +++ tests/testthat/test-metrics-sample.R | 146 ++++++++ 9 files changed, 525 insertions(+), 544 deletions(-) delete mode 100644 tests/testthat/test-bias.R delete mode 100644 tests/testthat/test-get_duplicate_forecasts.R delete mode 100644 tests/testthat/test-lower-level-check-functions.R rename tests/testthat/{test-absolute_error.R => test-metrics-point.R} (82%) rename tests/testthat/{test-interval_score.R => test-metrics-quantile.R} (68%) create mode 100644 tests/testthat/test-metrics-range.R create mode 100644 tests/testthat/test-metrics-sample.R diff --git a/tests/testthat/test-bias.R b/tests/testthat/test-bias.R deleted file mode 100644 index 42eefa34f..000000000 --- a/tests/testthat/test-bias.R +++ /dev/null @@ -1,311 +0,0 @@ -test_that("bias_sample() throws an error when missing observed", { - observed <- rpois(10, lambda = 1:10) - predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) - - expect_error( - bias_sample(predicted = predicted), - 'argument "observed" is missing, with no default' - ) -}) - -test_that("bias_sample() throws an error when missing 'predicted'", { - observed <- rpois(10, lambda = 1:10) - predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) - - expect_error( - bias_sample(observed = observed), - 'argument "predicted" is missing, with no default' - ) -}) - -test_that("bias_sample() works for integer observed and predicted", { - observed <- rpois(10, lambda = 1:10) - predicted <- replicate(10, rpois(10, lambda = 1:10)) - output <- bias_sample( - observed = observed, - predicted = predicted - ) - expect_equal( - length(output), - length(observed) - ) - expect_equal( - class(output), - "numeric" - ) -}) - -test_that("bias_sample() works for continuous observed values and predicted", { - observed <- rnorm(10) - predicted <- replicate(10, rnorm(10)) - output <- bias_sample( - observed = observed, - predicted = predicted - ) - expect_equal( - length(output), - length(observed) - ) - expect_equal( - class(output), - "numeric" - ) -}) - -test_that("bias_sample() works as expected", { - observed <- rpois(30, lambda = 1:30) - predicted <- replicate(200, rpois(n = 30, lambda = 1:30)) - expect_true(all(bias_sample(observed, predicted) == bias_sample(observed, predicted))) - - ## continuous forecasts - observed <- rnorm(30, mean = 1:30) - predicted <- replicate(200, rnorm(30, mean = 1:30)) - - scoringutils2 <- bias_sample(observed, predicted) - scoringutils <- bias_sample(observed, predicted) - - expect_equal(scoringutils, scoringutils2) -}) - - -test_that("bias_quantile() works as expected", { - predicted <- c(1, 2, 3) - quantiles <- c(0.1, 0.5, 0.9) - expect_equal( - bias_quantile(observed = 2, predicted, quantiles), - 0 - ) - predicted <- c(0, 1, 2) - quantiles <- c(0.1, 0.5, 0.9) - expect_equal( - bias_quantile(observed = 2, predicted, quantiles), - -0.8 - ) - - predicted <- c( - 705.500, 1127.000, 4006.250, 4341.500, 4709.000, 4821.996, - 5340.500, 5451.000, 5703.500, 6087.014, 6329.500, 6341.000, - 6352.500, 6594.986, 6978.500, 7231.000, 7341.500, 7860.004, - 7973.000, 8340.500, 8675.750, 11555.000, 11976.500 - ) - - quantile <- c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) - - observed <- 8062 - expect_equal(bias_quantile(observed, predicted, quantile), -0.8) -}) - -test_that("bias_quantile handles matrix input", { - observed <- seq(10, 0, length.out = 4) - predicted <- matrix(1:12, ncol = 3) - quantiles <- c(0.1, 0.5, 0.9) - expect_equal( - bias_quantile(observed, predicted, quantiles), - c(-1.0, -0.8, 0.8, 1.0) - ) -}) - - -test_that("bias_quantile() handles vector that is too long", { - predicted <- c(NA, 1, 2, 3) - quantiles <- c(0.1, 0.5, 0.9) - - expect_error( - bias_quantile(observed = 2, predicted, quantiles), - "Assertion on 'quantile' failed: Must have length 4, but has length 3." - ) -}) - -test_that("bias_quantile() handles NA values", { - predicted <- c(NA, 1, 2) - quantiles <- c(0.1, 0.5, 0.9) - expect_equal( - bias_quantile(observed = 2, predicted, quantiles), - -0.8 - ) - predicted <- c(0, 1, 2) - quantiles <- c(0.1, 0.5, NA) - expect_equal( - bias_quantile(observed = 2, predicted, quantiles), - -1 - ) - expect_equal( - bias_quantile(observed = 2, predicted, quantiles, na.rm = FALSE), - NA_real_ - ) -}) - -test_that("bias_quantile() errors if no predictions", { - expect_error( - bias_quantile(observed = 2, numeric(0), numeric(0)), - "Assertion on 'quantile' failed: Must have length >= 1, but has length 0" - ) -}) - -test_that("bias_quantile() returns correct bias if value below the median", { - predicted <- c(1, 2, 4, 5) - quantiles <- c(0.1, 0.3, 0.7, 0.9) - suppressMessages( - expect_equal(bias_quantile(observed = 1, predicted, quantiles), 0.8) - ) -}) - -test_that("bias_quantile() returns correct bias if value above median", { - predicted <- c(1, 2, 4, 5) - quantiles <- c(0.1, 0.3, 0.7, 0.9) - suppressMessages( - expect_equal(bias_quantile(observed = 5, predicted, quantiles), -0.8) - ) -}) - -test_that("bias_quantile() returns correct bias if value at the median", { - predicted <- c(1, 2, 3, 4) - quantiles <- c(0.1, 0.3, 0.5, 0.7) - - expect_equal(bias_quantile(observed = 3, predicted, quantiles), 0) -}) - -test_that("bias_quantile() returns 1 if true value below min prediction", { - predicted <- c(2, 3, 4, 5) - quantiles <- c(0.1, 0.3, 0.7, 0.9) - - suppressMessages( - expect_equal(bias_quantile(observed = 1, predicted, quantiles), 1) - ) -}) - -test_that("bias_quantile() returns -1 if true value above max prediction", { - predicted <- c(1, 2, 3, 4) - quantiles <- c(0.1, 0.3, 0.5, 0.7) - - expect_equal(bias_quantile(observed = 6, predicted, quantiles), -1) -}) - -test_that("bias_quantile(): quantiles must be between 0 and 1", { - predicted <- 1:4 - - # Failing example - quantiles <- c(-0.1, 0.3, 0.5, 0.8) - expect_error( - bias_quantile(observed = 3, predicted, quantiles), - "Assertion on 'quantile' failed: Element 1 is not >= 0." - ) - - # Passing counter example - quantiles <- c(0.1, 0.3, 0.5, 0.8) - expect_silent(bias_quantile(observed = 3, predicted, quantiles)) -}) - -test_that("bias_quantile(): quantiles must be increasing", { - predicted <- 1:4 - - # Failing example - quantiles <- c(0.8, 0.3, 0.5, 0.9) - expect_error( - bias_quantile(observed = 3, predicted, quantiles), - "Predictions must not be decreasing with increasing quantile level" - ) - - # Passing counter example - quantiles <- c(0.3, 0.5, 0.8, 0.9) - expect_silent(bias_quantile(observed = 3, predicted, quantiles)) -}) - -test_that("bias_quantile(): predictions must be increasing", { - predicted <- c(1, 2, 4, 3) - quantiles <- c(0.1, 0.3, 0.5, 0.9) - - expect_error( - bias_quantile(observed = 3, predicted, quantiles), - "Predictions must not be decreasing with increasing quantile level" - ) - expect_silent(bias_quantile( observed = 3, 1:4, quantiles)) -}) - -test_that("bias_quantile(): quantiles must be unique", { - predicted <- 1:4 - - # Failing example - quantiles <- c(0.3, 0.3, 0.5, 0.8) - expect_error( - bias_quantile(observed = 3, predicted, quantiles), - "Assertion on 'quantile' failed: Contains duplicated values, position 2." - ) - - # Passing example - quantiles <- c(0.3, 0.5, 0.8, 0.9) - expect_silent(bias_quantile(observed = 3, predicted, quantiles)) -}) - -test_that("bias_sample() approx equals bias_quantile() for many samples", { - set.seed(123) - - # Generate true value - observed <- 3 - - # Generate many sample predictions - predicted <- sample(rnorm(1000, mean = observed, sd = 2), 1000) - - # Get sample based bias - bias_sample_result <- bias_sample( - observed, matrix(predicted, nrow = 1) - ) - - # Convert predictions to quantiles - quantiles <- seq(0, 1, length.out = 100) - quantile_preds <- quantile(predicted, probs = quantiles) - - # Get quantile based bias - bias_quantile_result <- suppressMessages( - bias_quantile(observed, quantile_preds, quantiles) - ) - - # Difference should be small - expect_equal(bias_quantile_result, bias_sample_result, tolerance = 0.1) -}) - -test_that("bias_quantile() and bias_range() give the same result", { - predicted <- sort(rnorm(23)) - lower <- rev(predicted[1:12]) - upper <- predicted[12:23] - - range <- c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 98) - quantiles <- c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) - observed <- rnorm(1) - - range_bias <- bias_range( - lower = lower, upper = upper, - range = range, observed = observed - ) - range_quantile <- bias_quantile( - observed = observed, - predicted = predicted, - quantile = quantiles - ) - expect_equal(range_bias, range_quantile) -}) - -test_that("bias_range() works with point forecasts", { - predicted <- 1 - observed <- 1 - range <- c(0) - - expect_equal(bias_range(predicted, predicted, range, observed), 0) -}) - -test_that("bias_range(): ranges must be between 0 and 100", { - lower <- 4:1 - upper <- 5:8 - - # Failing example - range <- c(-10, 0, 10, 20) - expect_error( - bias_range(lower, upper, range, observed = 3), - "range must be between 0 and 100" - ) - - # Passing counter example - range <- c(0, 10, 20, 30) - expect_silent(bias_range(lower, upper, range, observed = 3)) -}) - diff --git a/tests/testthat/test-get_-functions.R b/tests/testthat/test-get_-functions.R index 217e954bd..0a499b243 100644 --- a/tests/testthat/test-get_-functions.R +++ b/tests/testthat/test-get_-functions.R @@ -70,3 +70,42 @@ test_that("get_type() handles `NA` values", { expect_equal(get_type(c(1, NA, 3.2)), "continuous") expect_error(get_type(NA), "Can't get type: all values of are NA") }) + + +# `get_duplicate_forecasts()` ================================================== +test_that("get_duplicate_forecasts() works as expected for quantile", { + expect_equal(nrow(get_duplicate_forecasts(example_quantile)), 0) + expect_equal( + nrow( + get_duplicate_forecasts(rbind(example_quantile, example_quantile[1000:1010]))), + 22 + ) +}) + +test_that("get_duplicate_forecasts() works as expected for sample", { + expect_equal(nrow(get_duplicate_forecasts(example_continuous)), 0) + expect_equal( + nrow( + get_duplicate_forecasts(rbind(example_continuous, example_continuous[1040:1050]))), + 22 + ) +}) + + +test_that("get_duplicate_forecasts() works as expected for binary", { + expect_equal(nrow(get_duplicate_forecasts(example_binary)), 0) + expect_equal( + nrow( + get_duplicate_forecasts(rbind(example_binary, example_binary[1000:1010]))), + 22 + ) +}) + +test_that("get_duplicate_forecasts() works as expected for point", { + expect_equal(nrow(get_duplicate_forecasts(example_binary)), 0) + expect_equal( + nrow( + get_duplicate_forecasts(rbind(example_point, example_point[1010:1020]))), + 22 + ) +}) diff --git a/tests/testthat/test-get_duplicate_forecasts.R b/tests/testthat/test-get_duplicate_forecasts.R deleted file mode 100644 index 5487ea0fb..000000000 --- a/tests/testthat/test-get_duplicate_forecasts.R +++ /dev/null @@ -1,37 +0,0 @@ -test_that("get_duplicate_forecasts() works as expected for quantile", { - expect_equal(nrow(get_duplicate_forecasts(example_quantile)), 0) - expect_equal( - nrow( - get_duplicate_forecasts(rbind(example_quantile, example_quantile[1000:1010]))), - 22 - ) -}) - -test_that("get_duplicate_forecasts() works as expected for sample", { - expect_equal(nrow(get_duplicate_forecasts(example_continuous)), 0) - expect_equal( - nrow( - get_duplicate_forecasts(rbind(example_continuous, example_continuous[1040:1050]))), - 22 - ) -}) - - -test_that("get_duplicate_forecasts() works as expected for binary", { - expect_equal(nrow(get_duplicate_forecasts(example_binary)), 0) - expect_equal( - nrow( - get_duplicate_forecasts(rbind(example_binary, example_binary[1000:1010]))), - 22 - ) -}) - -test_that("get_duplicate_forecasts() works as expected for point", { - expect_equal(nrow(get_duplicate_forecasts(example_binary)), 0) - expect_equal( - nrow( - get_duplicate_forecasts(rbind(example_point, example_point[1010:1020]))), - 22 - ) -}) - diff --git a/tests/testthat/test-lower-level-check-functions.R b/tests/testthat/test-lower-level-check-functions.R deleted file mode 100644 index 8d73aa528..000000000 --- a/tests/testthat/test-lower-level-check-functions.R +++ /dev/null @@ -1,116 +0,0 @@ -test_that("Lower-level input check functions work", { - observed <- rpois(30, lambda = 1:30) - predicted <- replicate(20, rpois(n = 30, lambda = 1:30)) - expect_equal(length(crps_sample(observed, predicted)), 30) - - # should error when wrong prediction type is given - predicted2 <- rpois(30, lambda = 1) - expect_error(crps_sample(observed, predicted2), - "Assertion on 'predicted' failed: Must be of type 'matrix', not 'integer'", - fixed = TRUE - ) - - # predictions have wrong number of rows - predicted3 <- replicate(20, rpois(n = 31, lambda = 1)) - expect_error( - crps_sample(observed, predicted3), - "Assertion on 'predicted' failed: Must have exactly 30 rows, but has 31 rows.", - # "Mismatch: 'observed' has length `30`, but 'predicted' has `31` rows.", - fixed = TRUE - ) - - # error with missing argument - expect_error(crps_sample(predicted = predicted), - 'argument "observed" is missing, with no default', - fixed = TRUE - ) - - # checks work for binary forecasts - observed <- factor(sample(c(0, 1), size = 10, replace = TRUE)) - predicted <- runif(n = 10) - expect_equal(length(brier_score(observed, predicted)), 10) - - # predictions are not between 0 and 1 - predicted2 <- predicted + 2 - expect_error( - brier_score(observed, predicted2), - "Assertion on 'predicted' failed: Element 1 is not <= 1.", - fixed = TRUE - ) -}) - - -test_that("function throws an error when missing observed or predicted", { - observed <- sample(c(0, 1), size = 10, replace = TRUE) - predicted <- replicate( - 20, - sample(c(0, 1), size = 10, replace = TRUE) - ) - - expect_error( - brier_score(predicted = predicted), - 'argument "observed" is missing, with no default' - ) - - expect_error( - brier_score(observed = observed), - 'argument "predicted" is missing, with no default' - ) -}) - - - -test_that("function throws an error for wrong format of `observed`", { - observed <- factor(rpois(10, lambda = 1:10)) - predicted <- runif(10, min = 0, max = 1) - - expect_error( - brier_score( - observed = observed, - predicted = predicted - ), - "Assertion on 'observed' failed: Must have exactly 2 levels." - ) - - observed <- rnorm(10) - expect_error( - brier_score( - observed = observed, - predicted = predicted - ), - "Assertion on 'observed' failed: Must be of type 'factor', not 'double'." - ) -}) - -test_that("function throws an error for wrong format of predictions", { - observed <- factor(sample(c(0, 1), size = 10, replace = TRUE)) - predicted <- runif(10, min = 0, max = 3) - expect_error( - brier_score( - observed = observed, - predicted = predicted - ), - #"For a binary forecast, all predictions should be probabilities between 0 or 1." - "Assertion on 'predicted' failed: Element 1 is not <= 1." - ) - - predicted <- runif(10, min = 0, max = 1) - expect_error( - brier_score( - observed = observed, - predicted = as.list(predicted) - ), - "Assertion on 'predicted' failed: Must be of type 'numeric', not 'list'." - ) - - predicted <- runif(15, min = 0, max = 1) - expect_error( - brier_score( - observed = observed, - predicted = predicted - ), - "`observed` and `predicted` need to be of same length when scoring binary forecasts", - # "Arguments to the following function call: 'brier_score(observed = observed, predicted = predicted)' should have the same length (or length one). Actual lengths: 10, 15", - fixed = TRUE - ) -}) diff --git a/tests/testthat/test-metrics-binary.R b/tests/testthat/test-metrics-binary.R index 958262a67..311ae0782 100644 --- a/tests/testthat/test-metrics-binary.R +++ b/tests/testthat/test-metrics-binary.R @@ -8,6 +8,81 @@ df <- data.table( ) # test input handling +test_that("function throws an error when missing observed or predicted", { + observed <- sample(c(0, 1), size = 10, replace = TRUE) + predicted <- replicate( + 20, + sample(c(0, 1), size = 10, replace = TRUE) + ) + + expect_error( + brier_score(predicted = predicted), + 'argument "observed" is missing, with no default' + ) + + expect_error( + brier_score(observed = observed), + 'argument "predicted" is missing, with no default' + ) +}) + + + +test_that("function throws an error for wrong format of `observed`", { + observed <- factor(rpois(10, lambda = 1:10)) + predicted <- runif(10, min = 0, max = 1) + + expect_error( + brier_score( + observed = observed, + predicted = predicted + ), + "Assertion on 'observed' failed: Must have exactly 2 levels." + ) + + observed <- rnorm(10) + expect_error( + brier_score( + observed = observed, + predicted = predicted + ), + "Assertion on 'observed' failed: Must be of type 'factor', not 'double'." + ) +}) + +test_that("function throws an error for wrong format of predictions", { + observed <- factor(sample(c(0, 1), size = 10, replace = TRUE)) + predicted <- runif(10, min = 0, max = 3) + expect_error( + brier_score( + observed = observed, + predicted = predicted + ), + #"For a binary forecast, all predictions should be probabilities between 0 or 1." + "Assertion on 'predicted' failed: Element 1 is not <= 1." + ) + + predicted <- runif(10, min = 0, max = 1) + expect_error( + brier_score( + observed = observed, + predicted = as.list(predicted) + ), + "Assertion on 'predicted' failed: Must be of type 'numeric', not 'list'." + ) + + predicted <- runif(15, min = 0, max = 1) + expect_error( + brier_score( + observed = observed, + predicted = predicted + ), + "`observed` and `predicted` need to be of same length when scoring binary forecasts", + # "Arguments to the following function call: 'brier_score(observed = observed, predicted = predicted)' should have the same length (or length one). Actual lengths: 10, 15", + fixed = TRUE + ) +}) + test_that("Input checking for binary forecasts works", { # everything correct expect_no_condition( diff --git a/tests/testthat/test-absolute_error.R b/tests/testthat/test-metrics-point.R similarity index 82% rename from tests/testthat/test-absolute_error.R rename to tests/testthat/test-metrics-point.R index 118a182d8..2f64226df 100644 --- a/tests/testthat/test-absolute_error.R +++ b/tests/testthat/test-metrics-point.R @@ -1,23 +1,20 @@ -test_that("ae_median_sample works", { - observed <- rnorm(30, mean = 1:30) - predicted_values <- rnorm(30, mean = 1:30) - scoringutils <- ae_median_sample(observed, matrix(predicted_values)) - ae <- abs(observed - predicted_values) - expect_equal(ae, scoringutils) -}) - - -# covidHubUtils-tests +# covidHubUtils-tests on absolute error ======================================== +# test are adapted from the package +# covidHubUtils, https://github.com/reichlab/covidHubUtils/ +y <- c(1, -15, 22) +forecast_quantiles_matrix <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) + +target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) +horizons <- c("1", "2", "1") +locations <- c("01", "01", "02") +target_variables <- rep("inc death", length(y)) test_that("abs error is correct within score, point forecast only", { - # test is adapted from the package covidHubUtils, https://github.com/reichlab/covidHubUtils/ - y <- c(1, -15, 22) - - target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) - horizons <- c("1", "2", "1") - locations <- c("01", "01", "02") - target_variables <- rep("inc death", length(y)) - forecast_target_end_dates <- rep(target_end_dates, times = 1) forecast_horizons <- rep(horizons, times = 1) @@ -71,21 +68,9 @@ test_that("abs error is correct within score, point forecast only", { }) test_that("abs error is correct, point and median forecasts different", { - y <- c(1, -15, 22) - forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) - ) - forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) forecast_quantiles_matrix <- forecast_quantiles_matrix[, 3, drop = FALSE] forecast_quantile_probs <- forecast_quantile_probs[3] - target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) - horizons <- c("1", "2", "1") - locations <- c("01", "01", "02") - target_variables <- rep("inc death", length(y)) - forecast_target_end_dates <- rep(target_end_dates, times = 1 + ncol(forecast_quantiles_matrix)) forecast_horizons <- rep(horizons, times = 1 + ncol(forecast_quantiles_matrix)) @@ -143,21 +128,9 @@ test_that("abs error is correct, point and median forecasts different", { }) test_that("abs error is correct, point and median forecasts same", { - y <- c(1, -15, 22) - forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) - ) - forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) forecast_quantiles_matrix <- forecast_quantiles_matrix[, 3, drop = FALSE] forecast_quantile_probs <- forecast_quantile_probs[3] - target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) - horizons <- c("1", "2", "1") - locations <- c("01", "01", "02") - target_variables <- rep("inc death", length(y)) - forecast_target_end_dates <- rep(target_end_dates, times = 1 + ncol(forecast_quantiles_matrix)) forecast_horizons <- rep(horizons, times = 1 + ncol(forecast_quantiles_matrix)) @@ -194,7 +167,6 @@ test_that("abs error is correct, point and median forecasts same", { stringsAsFactors = FALSE ) - # bring in scoringutils format truth_scoringutils <- data.table::as.data.table(test_truth) fc_scoringutils <- data.table::as.data.table(test_forecasts) @@ -219,7 +191,5 @@ test_that("abs error is correct, point and median forecasts same", { ) expected <- abs(y - point_forecast) - - # expect_equal(actual$abs_error, expected) expect_equal(eval$ae_point, expected) }) diff --git a/tests/testthat/test-interval_score.R b/tests/testthat/test-metrics-quantile.R similarity index 68% rename from tests/testthat/test-interval_score.R rename to tests/testthat/test-metrics-quantile.R index 04e0807a5..87d16e040 100644 --- a/tests/testthat/test-interval_score.R +++ b/tests/testthat/test-metrics-quantile.R @@ -1,15 +1,12 @@ -metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] -metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] - -test_that("wis works, median only", { +test_that("wis works standalone, median only", { y <- c(1, -15, 22) lower <- upper <- predicted_quantile <- c(1, 2, 3) quantile_probs <- 0.5 actual <- interval_score(y, - lower = lower, upper = upper, - weigh = TRUE, - interval_range = 0 + lower = lower, upper = upper, + weigh = TRUE, + interval_range = 0 ) actual_wis <- wis( @@ -23,7 +20,10 @@ test_that("wis works, median only", { expect_identical(actual, expected) }) -test_that("WIS works within score for median forecast", { +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] + +test_that("`wis()` works within score for median forecast", { test_data <- data.frame( observed = c(1, -15, 22), predicted = 1:3, @@ -38,7 +38,7 @@ test_that("WIS works within score for median forecast", { expect_equal(eval$ae_median, eval$wis) }) -test_that("wis works, 1 interval only", { +test_that("`wis()` equals `interval_score()`, 1 interval only", { y <- c(1, -15, 22) lower <- c(0, 1, 0) upper <- c(2, 2, 3) @@ -65,7 +65,7 @@ test_that("wis works, 1 interval only", { expect_identical(actual_wis, expected) }) -test_that("WIS works within score for one interval", { +test_that("wis() works within score for one interval", { test_data <- data.frame( observed = rep(c(1, -15, 22), times = 2), quantile = rep(c(0.25, 0.75), each = 3), @@ -74,10 +74,10 @@ test_that("WIS works within score for one interval", { date = rep(1:3, times = 2) ) - eval <- suppressMessages(score( + eval <- score( test_data, count_median_twice = TRUE, metrics = metrics_no_cov_no_ae - )) + ) eval <- summarise_scores(eval, by = c("model", "date")) @@ -90,7 +90,7 @@ test_that("WIS works within score for one interval", { expect_equal(expected, eval$wis) }) -test_that("wis works, 1 interval and median", { +test_that("`wis()` works 1 interval and median", { test_data <- data.frame( observed = rep(c(1, -15, 22), times = 3), quantile = rep(c(0.25, 0.5, 0.75), each = 3), @@ -308,14 +308,14 @@ test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", data_formatted <- merge(forecasts_formated, truth_formatted) eval <- suppressMessages(score(data_formatted, - count_median_twice = FALSE, metrics = metrics_no_cov_no_ae + count_median_twice = FALSE, metrics = metrics_no_cov_no_ae )) eval <- summarise_scores(eval, - by = c( - "model", "location", "target_variable", - "target_end_date", "forecast_date", "horizon" - ) + by = c( + "model", "location", "target_variable", + "target_end_date", "forecast_date", "horizon" + ) ) alpha1 <- 0.2 @@ -385,14 +385,14 @@ test_that("wis is correct, 2 intervals and median - test corresponds to covidHub data_formatted <- merge(forecasts_formated, truth_formatted) eval <- score(data_formatted, - count_median_twice = FALSE, metrics = metrics_no_cov + count_median_twice = FALSE, metrics = metrics_no_cov ) eval <- summarise_scores(eval, - by = c( - "model", "location", "target_variable", - "target_end_date", "forecast_date", "horizon" - ) + by = c( + "model", "location", "target_variable", + "target_end_date", "forecast_date", "horizon" + ) ) alpha1 <- 0.2 @@ -439,14 +439,14 @@ test_that("Quantlie score and interval score yield the same result, weigh = FALS ) qs_lower <- quantile_score(observed, - predicted = lower, - quantile = alpha / 2, - weigh = w + predicted = lower, + quantile = alpha / 2, + weigh = w ) qs_upper <- quantile_score(observed, - predicted = upper, - quantile = 1 - alpha / 2, - weigh = w + predicted = upper, + quantile = 1 - alpha / 2, + weigh = w ) expect_equal((qs_lower + qs_upper) / 2, is) expect_equal(wis, is) @@ -479,14 +479,14 @@ test_that("Quantlie score and interval score yield the same result, weigh = TRUE ) qs_lower <- quantile_score(observed, - predicted = lower, - quantile = alpha / 2, - weigh = w + predicted = lower, + quantile = alpha / 2, + weigh = w ) qs_upper <- quantile_score(observed, - predicted = upper, - quantile = 1 - alpha / 2, - weigh = w + predicted = upper, + quantile = 1 - alpha / 2, + weigh = w ) expect_equal((qs_lower + qs_upper) / 2, is) expect_equal(wis, is) @@ -503,3 +503,173 @@ test_that("wis works with separate results", { expect_equal(wis$wis, wis$dispersion + wis$overprediction + wis$underprediction) }) + +# `bias_quantile` ============================================================== +test_that("bias_quantile() works as expected", { + predicted <- c(1, 2, 3) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + 0 + ) + predicted <- c(0, 1, 2) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -0.8 + ) + + predicted <- c( + 705.500, 1127.000, 4006.250, 4341.500, 4709.000, 4821.996, + 5340.500, 5451.000, 5703.500, 6087.014, 6329.500, 6341.000, + 6352.500, 6594.986, 6978.500, 7231.000, 7341.500, 7860.004, + 7973.000, 8340.500, 8675.750, 11555.000, 11976.500 + ) + + quantile <- c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) + + observed <- 8062 + expect_equal(bias_quantile(observed, predicted, quantile), -0.8) +}) + +test_that("bias_quantile handles matrix input", { + observed <- seq(10, 0, length.out = 4) + predicted <- matrix(1:12, ncol = 3) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed, predicted, quantiles), + c(-1.0, -0.8, 0.8, 1.0) + ) +}) + + +test_that("bias_quantile() handles vector that is too long", { + predicted <- c(NA, 1, 2, 3) + quantiles <- c(0.1, 0.5, 0.9) + + expect_error( + bias_quantile(observed = 2, predicted, quantiles), + "Assertion on 'quantile' failed: Must have length 4, but has length 3." + ) +}) + +test_that("bias_quantile() handles NA values", { + predicted <- c(NA, 1, 2) + quantiles <- c(0.1, 0.5, 0.9) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -0.8 + ) + predicted <- c(0, 1, 2) + quantiles <- c(0.1, 0.5, NA) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles), + -1 + ) + expect_equal( + bias_quantile(observed = 2, predicted, quantiles, na.rm = FALSE), + NA_real_ + ) +}) + +test_that("bias_quantile() errors if no predictions", { + expect_error( + bias_quantile(observed = 2, numeric(0), numeric(0)), + "Assertion on 'quantile' failed: Must have length >= 1, but has length 0" + ) +}) + +test_that("bias_quantile() returns correct bias if value below the median", { + predicted <- c(1, 2, 4, 5) + quantiles <- c(0.1, 0.3, 0.7, 0.9) + suppressMessages( + expect_equal(bias_quantile(observed = 1, predicted, quantiles), 0.8) + ) +}) + +test_that("bias_quantile() returns correct bias if value above median", { + predicted <- c(1, 2, 4, 5) + quantiles <- c(0.1, 0.3, 0.7, 0.9) + suppressMessages( + expect_equal(bias_quantile(observed = 5, predicted, quantiles), -0.8) + ) +}) + +test_that("bias_quantile() returns correct bias if value at the median", { + predicted <- c(1, 2, 3, 4) + quantiles <- c(0.1, 0.3, 0.5, 0.7) + + expect_equal(bias_quantile(observed = 3, predicted, quantiles), 0) +}) + +test_that("bias_quantile() returns 1 if true value below min prediction", { + predicted <- c(2, 3, 4, 5) + quantiles <- c(0.1, 0.3, 0.7, 0.9) + + suppressMessages( + expect_equal(bias_quantile(observed = 1, predicted, quantiles), 1) + ) +}) + +test_that("bias_quantile() returns -1 if true value above max prediction", { + predicted <- c(1, 2, 3, 4) + quantiles <- c(0.1, 0.3, 0.5, 0.7) + + expect_equal(bias_quantile(observed = 6, predicted, quantiles), -1) +}) + +test_that("bias_quantile(): quantiles must be between 0 and 1", { + predicted <- 1:4 + + # Failing example + quantiles <- c(-0.1, 0.3, 0.5, 0.8) + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Assertion on 'quantile' failed: Element 1 is not >= 0." + ) + + # Passing counter example + quantiles <- c(0.1, 0.3, 0.5, 0.8) + expect_silent(bias_quantile(observed = 3, predicted, quantiles)) +}) + +test_that("bias_quantile(): quantiles must be increasing", { + predicted <- 1:4 + + # Failing example + quantiles <- c(0.8, 0.3, 0.5, 0.9) + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Predictions must not be decreasing with increasing quantile level" + ) + + # Passing counter example + quantiles <- c(0.3, 0.5, 0.8, 0.9) + expect_silent(bias_quantile(observed = 3, predicted, quantiles)) +}) + +test_that("bias_quantile(): predictions must be increasing", { + predicted <- c(1, 2, 4, 3) + quantiles <- c(0.1, 0.3, 0.5, 0.9) + + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Predictions must not be decreasing with increasing quantile level" + ) + expect_silent(bias_quantile( observed = 3, 1:4, quantiles)) +}) + +test_that("bias_quantile(): quantiles must be unique", { + predicted <- 1:4 + + # Failing example + quantiles <- c(0.3, 0.3, 0.5, 0.8) + expect_error( + bias_quantile(observed = 3, predicted, quantiles), + "Assertion on 'quantile' failed: Contains duplicated values, position 2." + ) + + # Passing example + quantiles <- c(0.3, 0.5, 0.8, 0.9) + expect_silent(bias_quantile(observed = 3, predicted, quantiles)) +}) diff --git a/tests/testthat/test-metrics-range.R b/tests/testthat/test-metrics-range.R new file mode 100644 index 000000000..bd0290e9f --- /dev/null +++ b/tests/testthat/test-metrics-range.R @@ -0,0 +1,45 @@ +test_that("bias_quantile() and bias_range() give the same result", { + predicted <- sort(rnorm(23)) + lower <- rev(predicted[1:12]) + upper <- predicted[12:23] + + range <- c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 98) + quantiles <- c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) + observed <- rnorm(1) + + range_bias <- bias_range( + lower = lower, upper = upper, + range = range, observed = observed + ) + range_quantile <- bias_quantile( + observed = observed, + predicted = predicted, + quantile = quantiles + ) + expect_equal(range_bias, range_quantile) +}) + +test_that("bias_range() works with point forecasts", { + predicted <- 1 + observed <- 1 + range <- c(0) + + expect_equal(bias_range(predicted, predicted, range, observed), 0) +}) + +test_that("bias_range(): ranges must be between 0 and 100", { + lower <- 4:1 + upper <- 5:8 + + # Failing example + range <- c(-10, 0, 10, 20) + expect_error( + bias_range(lower, upper, range, observed = 3), + "range must be between 0 and 100" + ) + + # Passing counter example + range <- c(0, 10, 20, 30) + expect_silent(bias_range(lower, upper, range, observed = 3)) +}) + diff --git a/tests/testthat/test-metrics-sample.R b/tests/testthat/test-metrics-sample.R new file mode 100644 index 000000000..ded7b52ae --- /dev/null +++ b/tests/testthat/test-metrics-sample.R @@ -0,0 +1,146 @@ +test_that("Input handling", { + observed <- rpois(30, lambda = 1:30) + predicted <- replicate(20, rpois(n = 30, lambda = 1:30)) + expect_equal(length(crps_sample(observed, predicted)), 30) + + # should error when wrong prediction type is given + predicted2 <- rpois(30, lambda = 1) + expect_error(crps_sample(observed, predicted2), + "Assertion on 'predicted' failed: Must be of type 'matrix', not 'integer'", + fixed = TRUE + ) + + # predictions have wrong number of rows + predicted3 <- replicate(20, rpois(n = 31, lambda = 1)) + expect_error( + crps_sample(observed, predicted3), + "Assertion on 'predicted' failed: Must have exactly 30 rows, but has 31 rows.", + # "Mismatch: 'observed' has length `30`, but 'predicted' has `31` rows.", + fixed = TRUE + ) + + # error with missing argument + expect_error(crps_sample(predicted = predicted), + 'argument "observed" is missing, with no default', + fixed = TRUE + ) +}) + + + +test_that("bias_sample() throws an error when missing observed", { + observed <- rpois(10, lambda = 1:10) + predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) + + expect_error( + bias_sample(predicted = predicted), + 'argument "observed" is missing, with no default' + ) +}) + +test_that("bias_sample() throws an error when missing 'predicted'", { + observed <- rpois(10, lambda = 1:10) + predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) + + expect_error( + bias_sample(observed = observed), + 'argument "predicted" is missing, with no default' + ) +}) + +test_that("bias_sample() works for integer observed and predicted", { + observed <- rpois(10, lambda = 1:10) + predicted <- replicate(10, rpois(10, lambda = 1:10)) + output <- bias_sample( + observed = observed, + predicted = predicted + ) + expect_equal( + length(output), + length(observed) + ) + expect_equal( + class(output), + "numeric" + ) +}) + +test_that("bias_sample() works for continuous observed values and predicted", { + observed <- rnorm(10) + predicted <- replicate(10, rnorm(10)) + output <- bias_sample( + observed = observed, + predicted = predicted + ) + expect_equal( + length(output), + length(observed) + ) + expect_equal( + class(output), + "numeric" + ) +}) + +test_that("bias_sample() works as expected", { + observed <- rpois(30, lambda = 1:30) + predicted <- replicate(200, rpois(n = 30, lambda = 1:30)) + expect_true(all(bias_sample(observed, predicted) == bias_sample(observed, predicted))) + + ## continuous forecasts + observed <- rnorm(30, mean = 1:30) + predicted <- replicate(200, rnorm(30, mean = 1:30)) + + scoringutils2 <- bias_sample(observed, predicted) + scoringutils <- bias_sample(observed, predicted) + + expect_equal(scoringutils, scoringutils2) +}) + + +test_that("bias_sample() approx equals bias_quantile() for many samples", { + set.seed(123) + + # Generate true value + observed <- 3 + + # Generate many sample predictions + predicted <- sample(rnorm(1000, mean = observed, sd = 2), 1000) + + # Get sample based bias + bias_sample_result <- bias_sample( + observed, matrix(predicted, nrow = 1) + ) + + # Convert predictions to quantiles + quantiles <- seq(0, 1, length.out = 100) + quantile_preds <- quantile(predicted, probs = quantiles) + + # Get quantile based bias + bias_quantile_result <- suppressMessages( + bias_quantile(observed, quantile_preds, quantiles) + ) + + # Difference should be small + expect_equal(bias_quantile_result, bias_sample_result, tolerance = 0.1) +}) + + +# `ae_median_sample` =========================================================== +test_that("ae_median_sample works", { + observed <- rnorm(30, mean = 1:30) + predicted_values <- rnorm(30, mean = 1:30) + scoringutils <- ae_median_sample(observed, matrix(predicted_values)) + ae <- abs(observed - predicted_values) + expect_equal(ae, scoringutils) +}) + +# `mad_sample()` =============================================================== +test_that("function throws an error when missing 'predicted'", { + predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) + + expect_error( + mad_sample() + ) +}) + From c89b1f53287ce4e25aba2045a50318c43ed32f83 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 12 Nov 2023 19:28:29 +0100 Subject: [PATCH 56/81] fix small test issues --- tests/testthat/test-metrics-binary.R | 14 ++------------ tests/testthat/test-metrics-quantile.R | 8 ++++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/tests/testthat/test-metrics-binary.R b/tests/testthat/test-metrics-binary.R index 311ae0782..9c49e7050 100644 --- a/tests/testthat/test-metrics-binary.R +++ b/tests/testthat/test-metrics-binary.R @@ -51,17 +51,6 @@ test_that("function throws an error for wrong format of `observed`", { }) test_that("function throws an error for wrong format of predictions", { - observed <- factor(sample(c(0, 1), size = 10, replace = TRUE)) - predicted <- runif(10, min = 0, max = 3) - expect_error( - brier_score( - observed = observed, - predicted = predicted - ), - #"For a binary forecast, all predictions should be probabilities between 0 or 1." - "Assertion on 'predicted' failed: Element 1 is not <= 1." - ) - predicted <- runif(10, min = 0, max = 1) expect_error( brier_score( @@ -116,7 +105,8 @@ test_that("Input checking for binary forecasts works", { # observed is a single number and does not have the same length as predicted expect_error( scoringutils:::assert_input_binary(factor(1), predicted), - "`observed` and `predicted` need to be of same length when scoring binary forecasts." + "`observed` and `predicted` need to be of same length when scoring binary forecasts", + fixed = TRUE ) # predicted is a matrix diff --git a/tests/testthat/test-metrics-quantile.R b/tests/testthat/test-metrics-quantile.R index 87d16e040..a40a93d8e 100644 --- a/tests/testthat/test-metrics-quantile.R +++ b/tests/testthat/test-metrics-quantile.R @@ -1,3 +1,6 @@ +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] + test_that("wis works standalone, median only", { y <- c(1, -15, 22) lower <- upper <- predicted_quantile <- c(1, 2, 3) @@ -20,9 +23,6 @@ test_that("wis works standalone, median only", { expect_identical(actual, expected) }) -metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] -metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] - test_that("`wis()` works within score for median forecast", { test_data <- data.frame( observed = c(1, -15, 22), @@ -76,7 +76,7 @@ test_that("wis() works within score for one interval", { eval <- score( test_data, - count_median_twice = TRUE, metrics = metrics_no_cov_no_ae + count_median_twice = TRUE, metrics = list(wis = wis) ) eval <- summarise_scores(eval, by = c("model", "date")) From cd0d1543e9db8a562780ca9d9e5ce7d1397cf5f4 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 10:01:51 +0100 Subject: [PATCH 57/81] Add input checks for quantile-based forecasts --- tests/testthat/test-metrics-quantile.R | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/testthat/test-metrics-quantile.R b/tests/testthat/test-metrics-quantile.R index a40a93d8e..f8f15cf0f 100644 --- a/tests/testthat/test-metrics-quantile.R +++ b/tests/testthat/test-metrics-quantile.R @@ -1,3 +1,59 @@ +# Input handling =============================================================== +observed <- c(1, -15, 22) +predicted <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) + +test_that("Input checking for quantile forecasts works", { + # everything correct + expect_no_condition( + scoringutils:::assert_input_quantile(observed, predicted, quantile) + ) + + # quantile > 1 + expect_error( + scoringutils:::assert_input_quantile(observed, predicted, quantile + 1), + "Assertion on 'quantile' failed: Element 1 is not <= 1." + ) + + # quantile < 0 + expect_error( + scoringutils:::assert_input_quantile(observed, predicted, quantile - 1), + "Assertion on 'quantile' failed: Element 1 is not >= 0." + ) + + # 10 observations, but only 3 forecasts + expect_error( + scoringutils:::assert_input_quantile(1:10, predicted, quantile), + "Assertion on 'predicted' failed: Must have exactly 10 rows, but has 3 rows." + ) + + # observed value is a factor + expect_error( + scoringutils:::assert_input_quantile(factor(1:10), predicted, quantile), + "Assertion on 'observed' failed: Must be of type 'numeric', not 'factor'." + ) + + # observed is a single number and does not have the same length as predicted + expect_error( + scoringutils:::assert_input_quantile(1, predicted, quantile), + "Assertion failed. One of the following must apply: + * check_numeric_vector(predicted): Must be of type 'atomic vector', not 'matrix' + * check_matrix(predicted): Must have exactly 1 rows, but has 3 rows", + fixed = TRUE + ) + + # predicted is a vector + expect_error( + scoringutils:::assert_input_quantile(observed, as.vector(predicted), quantile), + "Assertion on 'predicted' failed: Must be of type 'matrix', not 'double'." + ) +}) + + metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] From 40807adf6fc2635c10fbf2585a2e04925bde20a9 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 10:02:26 +0100 Subject: [PATCH 58/81] remove old test for sharpness (test has been moved to test-metrics-sample.R) --- tests/testthat/test-sharpness.R | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/testthat/test-sharpness.R diff --git a/tests/testthat/test-sharpness.R b/tests/testthat/test-sharpness.R deleted file mode 100644 index 12dcc4c9f..000000000 --- a/tests/testthat/test-sharpness.R +++ /dev/null @@ -1,7 +0,0 @@ -test_that("function throws an error when missing 'predicted'", { - predicted <- replicate(50, rpois(n = 10, lambda = 1:10)) - - expect_error( - mad_sample() - ) -}) From fa3a7ab2936b3be018623107abc273cd39fa686f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 10:39:33 +0100 Subject: [PATCH 59/81] move piece of code around within the metrics-quantile.R file (since metric has a many-to-one relationship) --- R/metrics-quantile.R | 78 ++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index a321b21bf..db187d376 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -454,6 +454,45 @@ bias_quantile_single_vector <- function(observed, predicted, quantile, na.rm) { } +#' @title Absolute Error of the Median (Quantile-based Version) +#' @description +#' Compute the absolute error of the median calculated as +#' \deqn{ +#' \textrm{abs}(\textrm{observed} - \textrm{median prediction}) +#' }{ +#' abs(observed - median_prediction) +#' } +#' The median prediction is the predicted value for which quantile == 0.5, +#' the function therefore requires 0.5 to be among the quantile levels in +#' `quantile`. +#' @inheritParams wis +#' @return numeric vector of length N with the absolute error of the median +#' @seealso [ae_median_sample()], [abs_error()] +#' @importFrom stats median +#' @examples +#' observed <- rnorm(30, mean = 1:30) +#' predicted_values <- matrix(rnorm(30, mean = 1:30)) +#' ae_median_quantile(observed, predicted_values, quantile = 0.5) +#' @export +#' @keywords metric +ae_median_quantile <- function(observed, predicted, quantile) { + assert_input_quantile(observed, predicted, quantile) + if (!any(quantile == 0.5)) { + warning( + "in order to compute the absolute error of the median, `0.5` must be ", + "among the quantiles given. Returning `NA`." + ) + return(NA_real_) + } + if (is.null(dim(predicted))) { + predicted <- matrix(predicted, nrow = 1) + } + predicted <- predicted[, quantile == 0.5] + abs_error_median <- abs(observed - predicted) + return(abs_error_median) +} + + ################################################################################ # Metrics with a one-to-one relationship between input and score ################################################################################ @@ -619,42 +658,3 @@ wis_one_to_one <- function(observed, } } } - - -#' @title Absolute Error of the Median (Quantile-based Version) -#' @description -#' Compute the absolute error of the median calculated as -#' \deqn{ -#' \textrm{abs}(\textrm{observed} - \textrm{median prediction}) -#' }{ -#' abs(observed - median_prediction) -#' } -#' The median prediction is the predicted value for which quantile == 0.5, -#' the function therefore requires 0.5 to be among the quantile levels in -#' `quantile`. -#' @inheritParams wis -#' @return numeric vector of length N with the absolute error of the median -#' @seealso [ae_median_sample()], [abs_error()] -#' @importFrom stats median -#' @examples -#' observed <- rnorm(30, mean = 1:30) -#' predicted_values <- matrix(rnorm(30, mean = 1:30)) -#' ae_median_quantile(observed, predicted_values, quantile = 0.5) -#' @export -#' @keywords metric -ae_median_quantile <- function(observed, predicted, quantile) { - assert_input_quantile(observed, predicted, quantile) - if (!any(quantile == 0.5)) { - warning( - "in order to compute the absolute error of the median, `0.5` must be ", - "among the quantiles given. Returning `NA`." - ) - return(NA_real_) - } - if (is.null(dim(predicted))) { - predicted <- matrix(predicted, nrow = 1) - } - predicted <- predicted[, quantile == 0.5] - abs_error_median <- abs(observed - predicted) - return(abs_error_median) -} From 0d42acc49eef7403ce7414215193644411997417 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 10:53:46 +0100 Subject: [PATCH 60/81] Add more tests for quantile metrics --- tests/testthat/test-metrics-quantile.R | 102 ++++++++++++++++++++----- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/tests/testthat/test-metrics-quantile.R b/tests/testthat/test-metrics-quantile.R index f8f15cf0f..8ff355f02 100644 --- a/tests/testthat/test-metrics-quantile.R +++ b/tests/testthat/test-metrics-quantile.R @@ -1,12 +1,26 @@ -# Input handling =============================================================== +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] observed <- c(1, -15, 22) predicted <- rbind( c(-1, 0, 1, 2, 3), c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) + c(-2, 0, 3, 3, 4) ) quantile <- c(0.1, 0.25, 0.5, 0.75, 0.9) +# covidHubUtils test: +y <- c(1, -15, 22) +forecast_quantiles_matrix <- rbind( + c(-1, 0, 1, 2, 3), + c(-2, 1, 2, 2, 4), + c(-2, 0, 3, 3, 4) +) +forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) + + +# ============================================================================ # +# Input handling =============================================================== +# ============================================================================ # test_that("Input checking for quantile forecasts works", { # everything correct expect_no_condition( @@ -38,11 +52,12 @@ test_that("Input checking for quantile forecasts works", { ) # observed is a single number and does not have the same length as predicted + # There seems to be an issue with the error message: there is one \n to many + # such that the test fails when executed alone, but works when executed + # together with others. expect_error( scoringutils:::assert_input_quantile(1, predicted, quantile), - "Assertion failed. One of the following must apply: - * check_numeric_vector(predicted): Must be of type 'atomic vector', not 'matrix' - * check_matrix(predicted): Must have exactly 1 rows, but has 3 rows", + "Assertion failed. One of the following must apply:\n * check_numeric_vector(predicted): Must be of type 'atomic vector',\n * not 'matrix'\n * check_matrix(predicted): Must have exactly 1 rows, but has 3 rows", fixed = TRUE ) @@ -54,9 +69,9 @@ test_that("Input checking for quantile forecasts works", { }) -metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] -metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] - +# ============================================================================ # +# wis ========================================================================== +# ============================================================================ #a test_that("wis works standalone, median only", { y <- c(1, -15, 22) lower <- upper <- predicted_quantile <- c(1, 2, 3) @@ -183,15 +198,6 @@ test_that("`wis()` works 1 interval and median", { expect_identical(actual_wis, expected) }) -# covidHubUtils test: -y <- c(1, -15, 22) -forecast_quantiles_matrix <- rbind( - c(-1, 0, 1, 2, 3), - c(-2, 1, 2, 2, 4), - c(-2, 0, 3, 3, 4) -) -forecast_quantile_probs <- c(0.1, 0.25, 0.5, 0.75, 0.9) - test_that("wis works, 2 intervals and median", { test_data <- data.frame( observed = rep(c(1, -15, 22), times = 5), @@ -309,7 +315,6 @@ test_that("wis is correct, median only - test corresponds to covidHubUtils", { expect_equal(actual_wis, expected) }) - test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", { forecast_quantiles_matrix <- forecast_quantiles_matrix[, c(1, 5), drop = FALSE] forecast_quantile_probs <- forecast_quantile_probs[c(1, 5)] @@ -389,7 +394,6 @@ test_that("wis is correct, 1 interval only - test corresponds to covidHubUtils", expect_equal(actual_wis, expected) }) - test_that("wis is correct, 2 intervals and median - test corresponds to covidHubUtils", { target_end_dates <- as.Date("2020-01-01") + c(7, 14, 7) horizons <- c("1", "2", "1") @@ -509,6 +513,10 @@ test_that("Quantlie score and interval score yield the same result, weigh = FALS } }) + +# ============================================================================ # +# Quantile score ============================================================= # +# ============================================================================ # test_that("Quantlie score and interval score yield the same result, weigh = TRUE", { observed <- rnorm(10, mean = 1:10) alphas <- c(0.1, 0.5, 0.9) @@ -560,7 +568,63 @@ test_that("wis works with separate results", { }) +# ============================================================================ # +# overprediction, underprediction, dispersion ================================ # +# ============================================================================ # +test_that("wis is the sum of overprediction, underprediction, dispersion", { + wis <- wis( + observed = y, + predicted = forecast_quantiles_matrix, + quantile = forecast_quantile_probs + ) + + d <- dispersion(y, forecast_quantiles_matrix, forecast_quantile_probs) + o <- overprediction(y, forecast_quantiles_matrix, forecast_quantile_probs) + u <- underprediction(y, forecast_quantiles_matrix, forecast_quantile_probs) + + expect_equal(wis, d + o + u) +}) + + +# ============================================================================ # +# `interval_coverage_quantile` =============================================== # +# ============================================================================ # +test_that("interval_coverage_quantile works", { + expect_equal( + interval_coverage_quantile(observed, predicted, quantile, range = 50), + c(TRUE, FALSE, FALSE) + ) +}) + +test_that("interval_coverage_quantile rejects wrong inputs", { + expect_error( + interval_coverage_quantile(observed, predicted, quantile, range = c(50, 0)), + "Assertion on 'range' failed: Must have length 1." + ) +}) + + +# ============================================================================ # +# `interval_coverage_deviation_quantile` ===================================== # +# ============================================================================ # +test_that("interval_coverage_deviation_quantile works", { + existing_ranges <- unique(get_range_from_quantile(quantile)) + expect_equal(existing_ranges, c(80, 50, 0)) + + cov_50 <- interval_coverage_quantile(observed, predicted, quantile, range = c(50)) + cov_80 <- interval_coverage_quantile(observed, predicted, quantile, range = c(80)) + manual <- 0.5 * (cov_50 - 0.5) + 0.5 * (cov_80 - 0.8) + + expect_equal( + interval_coverage_deviation_quantile(observed, predicted, quantile), + manual + ) +}) + + +# ============================================================================ # # `bias_quantile` ============================================================== +# ============================================================================ # test_that("bias_quantile() works as expected", { predicted <- c(1, 2, 3) quantiles <- c(0.1, 0.5, 0.9) From 32357f1f1a4aafd604f73543922ca3d4c2d3794d Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 14:18:01 +0100 Subject: [PATCH 61/81] Rework existing `add_coverage()` function to work with raw forecasts --- NAMESPACE | 1 + R/add_coverage.R | 78 +++++++++++++++++++++++++++++++++++++++++++ R/summarise_scores.R | 75 ----------------------------------------- R/z_globalVariables.R | 3 ++ man/add_coverage.Rd | 64 ++++++++++++++++++++++------------- 5 files changed, 122 insertions(+), 99 deletions(-) create mode 100644 R/add_coverage.R diff --git a/NAMESPACE b/NAMESPACE index e4ae0d765..bc2a6b542 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -108,6 +108,7 @@ importFrom(data.table,nafill) importFrom(data.table,rbindlist) importFrom(data.table,setDT) importFrom(data.table,setattr) +importFrom(data.table,setcolorder) importFrom(data.table,setnames) importFrom(ggdist,geom_lineribbon) importFrom(ggplot2,.data) diff --git a/R/add_coverage.R b/R/add_coverage.R new file mode 100644 index 000000000..becdbf089 --- /dev/null +++ b/R/add_coverage.R @@ -0,0 +1,78 @@ +#' @title Add Coverage Values to Quantile-Based Forecasts +#' +#' @description Adds interval coverage of central prediction intervals, +#' quantile coverage for predictive quantiles, as well as the deviation between +#' desired and actual coverage to a data.table. Forecasts should be in a +#' quantile format (following the input requirements of `score()`). +#' +#' **Interval coverage** +#' +#' Coverage for a given interval range is defined as the proportion of +#' observations that fall within the corresponding central prediction intervals. +#' Central prediction intervals are symmetric around the median and and formed +#' by two quantiles that denote the lower and upper bound. For example, the 50% +#' central prediction interval is the interval between the 0.25 and 0.75 +#' quantiles of the predictive distribution. +#' +#' The function `add_coverage()` computes the coverage per central prediction +#' interval, so the coverage will always be either `TRUE` (observed value falls +#' within the interval) or `FALSE` (observed value falls outside the interval). +#' You can summarise the coverage values to get the proportion of observations +#' that fall within the central prediction intervals. +#' +#' **Quantile coverage** +#' +#' Quantile coverage for a given quantile is defined as the proportion of +#' observed values that are smaller than the corresponding predictive quantile. +#' For example, the 0.5 quantile coverage is the proportion of observed values +#' that are smaller than the 0.5 quantile of the predictive distribution. +#' +#' **Coverage deviation** +#' +#' The coverage deviation is the difference between the desired coverage and the +#' actual coverage. For example, if the desired coverage is 90% and the actual +#' coverage is 80%, the coverage deviation is -0.1. +#' +#' @inheritParams score +#' @return a data.table with the input and columns "interval_coverage", +#' "interval_coverage_deviation", "quantile_coverage", +#' "quantile_coverage_deviation" added. +#' @importFrom data.table setcolorder +#' @examples +#' library(magrittr) # pipe operator +#' example_quantile %>% +#' add_coverage() +#' @export +#' @keywords scoring +#' @export +add_coverage <- function(data) { + stored_attributes <- get_scoringutils_attributes(data) + data <- validate(data) + data <- remove_na_observed_predicted(data) + forecast_unit <- get_forecast_unit(data) + data_cols <- colnames(data) # store so we can reset column order later + + # what happens if quantiles are not symmetric around the median? + # should things error? Also write tests for that. + interval_data <- quantile_to_interval(data, format = "wide") + interval_data[, interval_coverage := ifelse( + observed <= upper & observed >= lower, + TRUE, + FALSE) + ][, c("lower", "upper", "observed") := NULL] + + data[, range := get_range_from_quantile(quantile)] + + data <- merge(interval_data, data, by = unique(c(forecast_unit, "range"))) + data[, interval_coverage_deviation := interval_coverage - range / 100] + data[, quantile_coverage := observed <= predicted] + data[, quantile_coverage_deviation := quantile_coverage - quantile] + + # reset column order + setcolorder(data, unique(c(data_cols, "range", "interval_coverage", + "interval_coverage_deviation", "quantile_coverage", + "quantile_coverage_deviation"))) + + data <- assign_attributes(data, stored_attributes) + return(data[]) +} diff --git a/R/summarise_scores.R b/R/summarise_scores.R index 40666b1f3..032026402 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -306,78 +306,3 @@ check_summary_params <- function(scores, } return(relative_skill) } - - - -#' @title Add coverage of central prediction intervals -#' -#' @description Adds a column with the coverage of central prediction intervals -#' to unsummarised scores as produced by [score()] -#' -#' The coverage values that are added are computed according to the values -#' specified in `by`. If, for example, `by = "model"`, then there will be one -#' coverage value for every model and [add_coverage()] will compute the coverage -#' for every model across the values present in all other columns which define -#' the unit of a single forecast. -#' -#' @inheritParams summarise_scores -#' @param by character vector with column names to add the coverage for. -#' @param ranges numeric vector of the ranges of the central prediction intervals -#' for which coverage values shall be added. -#' @return a data.table with unsummarised scores with columns added for the -#' coverage of the central prediction intervals. While the overall data.table -#' is still unsummarised, note that for the coverage columns some level of -#' summary is present according to the value specified in `by`. -#' @examples -#' library(magrittr) # pipe operator -#' score(example_quantile) %>% -#' # add_coverage(by = c("model", "target_type")) %>% -#' summarise_scores(by = c("model", "target_type")) %>% -#' summarise_scores(fun = signif, digits = 2) -#' @export -#' @keywords scoring - -add_coverage <- function(scores, - by = NULL, - ranges = c(50, 90)) { - - stored_attributes <- get_scoringutils_attributes(scores) - if (!is.null(attr(scores, "unsummarised_scores"))) { - scores <- attr(scores, "unsummarised_scores") - } - - if (is.null(by) && !is.null(stored_attributes[["scoringutils_by"]])) { - by <- stored_attributes[["scoringutils_by"]] - } else if (is.null(by)) { - # Need to check this again. - # (mentioned in https://github.com/epiforecasts/scoringutils/issues/346) - by <- get_forecast_unit(scores) - } - - summarised_scores <- summarise_scores( - scores, - by = c(by, "range") - )[range %in% ranges] - - - # create cast formula - cast_formula <- - paste( - paste(by, collapse = "+"), - "~", - "paste0('coverage_', range)" - ) - - coverages <- dcast( - summarised_scores, - value.var = "coverage", - formula = cast_formula - ) - - scores_with_coverage <- merge(scores, coverages, by = by) - scores_with_coverage <- assign_attributes( - scores_with_coverage, stored_attributes - ) - - return(scores_with_coverage[]) -} diff --git a/R/z_globalVariables.R b/R/z_globalVariables.R index 441501932..28bcfb95b 100644 --- a/R/z_globalVariables.R +++ b/R/z_globalVariables.R @@ -30,9 +30,12 @@ globalVariables(c( "identifCol", "Interval_Score", "interval_range", + "interval_coverage", + "interval_coverage_deviation", "overprediction", "underprediction", "quantile_coverage", + "quantile_coverage_deviation", "LogS", "log_score", "lower", diff --git a/man/add_coverage.Rd b/man/add_coverage.Rd index 507db1a4a..d6c82d467 100644 --- a/man/add_coverage.Rd +++ b/man/add_coverage.Rd @@ -1,40 +1,56 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summarise_scores.R +% Please edit documentation in R/add_coverage.R \name{add_coverage} \alias{add_coverage} -\title{Add coverage of central prediction intervals} +\title{Add Coverage Values to Quantile-Based Forecasts} \usage{ -add_coverage(scores, by = NULL, ranges = c(50, 90)) +add_coverage(data) } \arguments{ -\item{scores}{A data.table of scores as produced by \code{\link[=score]{score()}}.} - -\item{by}{character vector with column names to add the coverage for.} - -\item{ranges}{numeric vector of the ranges of the central prediction intervals -for which coverage values shall be added.} +\item{data}{A data.frame or data.table with predicted and observed values.} } \value{ -a data.table with unsummarised scores with columns added for the -coverage of the central prediction intervals. While the overall data.table -is still unsummarised, note that for the coverage columns some level of -summary is present according to the value specified in \code{by}. +a data.table with the input and columns "interval_coverage", +"interval_coverage_deviation", "quantile_coverage", +"quantile_coverage_deviation" added. } \description{ -Adds a column with the coverage of central prediction intervals -to unsummarised scores as produced by \code{\link[=score]{score()}} +Adds interval coverage of central prediction intervals, +quantile coverage for predictive quantiles, as well as the deviation between +desired and actual coverage to a data.table. Forecasts should be in a +quantile format (following the input requirements of \code{score()}). + +\strong{Interval coverage} + +Coverage for a given interval range is defined as the proportion of +observations that fall within the corresponding central prediction intervals. +Central prediction intervals are symmetric around the median and and formed +by two quantiles that denote the lower and upper bound. For example, the 50\% +central prediction interval is the interval between the 0.25 and 0.75 +quantiles of the predictive distribution. + +The function \code{add_coverage()} computes the coverage per central prediction +interval, so the coverage will always be either \code{TRUE} (observed value falls +within the interval) or \code{FALSE} (observed value falls outside the interval). +You can summarise the coverage values to get the proportion of observations +that fall within the central prediction intervals. + +\strong{Quantile coverage} + +Quantile coverage for a given quantile is defined as the proportion of +observed values that are smaller than the corresponding predictive quantile. +For example, the 0.5 quantile coverage is the proportion of observed values +that are smaller than the 0.5 quantile of the predictive distribution. + +\strong{Coverage deviation} -The coverage values that are added are computed according to the values -specified in \code{by}. If, for example, \code{by = "model"}, then there will be one -coverage value for every model and \code{\link[=add_coverage]{add_coverage()}} will compute the coverage -for every model across the values present in all other columns which define -the unit of a single forecast. +The coverage deviation is the difference between the desired coverage and the +actual coverage. For example, if the desired coverage is 90\% and the actual +coverage is 80\%, the coverage deviation is -0.1. } \examples{ library(magrittr) # pipe operator -score(example_quantile) \%>\% - # add_coverage(by = c("model", "target_type")) \%>\% - summarise_scores(by = c("model", "target_type")) \%>\% - summarise_scores(fun = signif, digits = 2) +example_quantile \%>\% + add_coverage() } \keyword{scoring} From 1be9055777434c542fa72cdde8e7e0bb0e36ce6b Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 14:19:54 +0100 Subject: [PATCH 62/81] Update News --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 322b2b25d..a00ab7f95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,7 @@ The update introduces a lot of breaking changes. If you want to keep using the o - `quantile`: numeric, a vector with quantile-levels. Can alternatively be a matrix of the same shape as `predicted`. - `check_forecasts()` was replaced by a new function `validate()`. `validate()` validates the input and in that sense fulfills the purpose of `check_forecasts()`. It has different methods: `validate.default()` assigns the input a class based on their forecast type. Other methods validate the input specifically for the various forecast types. - The functionality for computing pairwise comparisons was now split from `summarise_scores()`. Instead of doing pairwise comparisons as part of summarising scores, a new function, `add_pairwise_comparison()`, was introduced that takes summarised scores as an input and adds pairwise comparisons to it. +- `add_coverage()` was reworked completely. It's new purpose is now to add coverage information to the raw forecast data (essentially fulfilling some of the functionality that was previously covered by `score_quantile()`) - The function `find_duplicates()` was renamed to `get_duplicate_forecasts()` - Changes to `avail_forecasts()` and `plot_avail_forecasts()`: - The function `avail_forecasts()` was renamed to `available_forecasts()` for consistency with `available_metrics()`. The old function, `avail_forecasts()` is still available as an alias, but will be removed in the future. From 8719dbe88f6d4ee96e3ef1045b1cca0439acadfa Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 15:10:15 +0100 Subject: [PATCH 63/81] Update `get_protetcted_columns()` with coverage columns --- R/get_-functions.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/get_-functions.R b/R/get_-functions.R index 22aaa47a9..b55e1ef4f 100644 --- a/R/get_-functions.R +++ b/R/get_-functions.R @@ -193,6 +193,8 @@ get_protected_columns <- function(data = NULL) { protected_columns <- c( "predicted", "observed", "sample_id", "quantile", "upper", "lower", "pit_value", "range", "boundary", "relative_skill", "scaled_rel_skill", + "interval_coverage", "interval_coverage_deviation", + "quantile_coverage", "quantile_coverage_deviation", available_metrics(), grep("coverage_", names(data), fixed = TRUE, value = TRUE) ) From 1252e1335747a1d75e6079695545bab097a00218 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 15:56:17 +0100 Subject: [PATCH 64/81] Update `quantile_to_interval.data.frame()` to work with NA values --- R/utils_data_handling.R | 4 +++ tests/testthat/test-utils_data_handling.R | 30 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/R/utils_data_handling.R b/R/utils_data_handling.R index f1dc27201..66849e2cc 100644 --- a/R/utils_data_handling.R +++ b/R/utils_data_handling.R @@ -230,6 +230,10 @@ quantile_to_interval.data.frame <- function(dt, if (format == "wide") { delete_columns(dt, "quantile") dt <- dcast(dt, ... ~ boundary, value.var = "predicted") + # if there are NA values in `predicted`, this introduces a column "NA" + if ("NA" %in% colnames(dt) && all(is.na(dt[["NA"]]))) { + dt[, "NA" := NULL] + } } return(dt[]) } diff --git a/tests/testthat/test-utils_data_handling.R b/tests/testthat/test-utils_data_handling.R index e627485ab..4521c1f73 100644 --- a/tests/testthat/test-utils_data_handling.R +++ b/tests/testthat/test-utils_data_handling.R @@ -22,7 +22,7 @@ test_that("range_long_to_quantile works", { -test_that("quantile_to_interval works", { +test_that("quantile_to_interval.data.frame() works", { quantile <- data.frame( date = as.Date("2020-01-01") + 1:10, model = "model1", @@ -30,7 +30,6 @@ test_that("quantile_to_interval works", { predicted = c(2:11, 4:13), quantile = rep(c(0.25, 0.75), each = 10) ) - long <- data.frame( date = as.Date("2020-01-01") + 1:10, model = "model1", @@ -39,19 +38,38 @@ test_that("quantile_to_interval works", { range = 50, boundary = rep(c("lower", "upper"), each = 10) ) - long2 <- as.data.frame(quantile_to_interval( quantile, keep_quantile_col = FALSE )) - data.table::setcolorder(long2, names(long)) - # for some reason this is needed to pass the unit tests on gh actions long2$boundary <- as.character(long2$boundary) long$boundary <- as.character(long$boundary) - expect_equal(long, as.data.frame(long2)) + + # check that it handles NA values + setDT(quantile) + quantile[c(1, 3, 11, 13), c("observed", "predicted", "quantile") := NA] + # in this instance, a problem appears because there is an NA value both + # for the upper and lower bound. + expect_message( + quantile_to_interval( + quantile, + keep_quantile_col = FALSE, + format = "wide" + ), + "Aggregate function missing, defaulting to 'length'" + ) + quantile <- quantile[-c(1, 3), ] + wide2 <- scoringutils:::quantile_to_interval( + quantile, + keep_quantile_col = FALSE, + format = "wide" + ) + expect_equal(nrow(wide2), 10) + expect_true(!("NA") %in% colnames(wide2)) + expect_equal(sum(wide2$lower, na.rm = TRUE), 59) }) From 3af9fff05dbe76b4586bf04432a64da7ce1a8ebf Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 15:58:29 +0100 Subject: [PATCH 65/81] Don't remove NA values in `add_coverage()` anymore --- R/add_coverage.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/add_coverage.R b/R/add_coverage.R index becdbf089..7aeac496b 100644 --- a/R/add_coverage.R +++ b/R/add_coverage.R @@ -48,7 +48,6 @@ add_coverage <- function(data) { stored_attributes <- get_scoringutils_attributes(data) data <- validate(data) - data <- remove_na_observed_predicted(data) forecast_unit <- get_forecast_unit(data) data_cols <- colnames(data) # store so we can reset column order later From 02c4b1c60c999e25fcdef7727d7a07d50c3d40ce Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 16:52:44 +0100 Subject: [PATCH 66/81] Update `add_coverage` to store an attribute `metric_names` with the name of the coverage columns --- R/add_coverage.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/R/add_coverage.R b/R/add_coverage.R index 7aeac496b..684556026 100644 --- a/R/add_coverage.R +++ b/R/add_coverage.R @@ -68,10 +68,16 @@ add_coverage <- function(data) { data[, quantile_coverage_deviation := quantile_coverage - quantile] # reset column order - setcolorder(data, unique(c(data_cols, "range", "interval_coverage", - "interval_coverage_deviation", "quantile_coverage", - "quantile_coverage_deviation"))) + new_metrics <- c("interval_coverage", "interval_coverage_deviation", + "quantile_coverage", "quantile_coverage_deviation") + setcolorder(data, unique(c(data_cols, "range", new_metrics))) + # add coverage "metrics" to list of stored metrics + # this makes it possible to use `summarise_scores()` later on + stored_attributes[["metric_names"]] <- c( + stored_attributes[["metric_names"]], + new_metrics + ) data <- assign_attributes(data, stored_attributes) return(data[]) } From b41d6554908644519791b28e068ce44631e3ff07 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Mon, 13 Nov 2023 16:58:55 +0100 Subject: [PATCH 67/81] Update tests and code snippets to get stuff working again that was previously failing due to `add_coverage()` --- R/plot.R | 2 +- README.Rmd | 2 +- .../plot-interval-coverage.svg | 20 ++- .../plot-quantile-coverage.svg | 20 ++- .../plot_ranges/plot-ranges-dispersion.svg | 154 ++++++++--------- .../plot_ranges/plot-ranges-interval.svg | 156 +++++++++--------- tests/testthat/setup.R | 6 +- tests/testthat/test-add_coverage.R | 44 ++--- tests/testthat/test-metrics-quantile.R | 2 - tests/testthat/test-plot_interval_coverage.R | 18 +- tests/testthat/test-plot_quantile_coverage.R | 18 +- tests/testthat/test-plot_ranges.R | 43 ++--- tests/testthat/test-score.R | 3 - vignettes/scoringutils.Rmd | 3 +- 14 files changed, 239 insertions(+), 252 deletions(-) diff --git a/R/plot.R b/R/plot.R index 59f0f6eca..84ae33eb1 100644 --- a/R/plot.R +++ b/R/plot.R @@ -613,7 +613,7 @@ plot_interval_coverage <- function(scores, colour = "grey", linetype = "dashed" ) + - geom_line(aes(y = coverage * 100)) + + geom_line(aes(y = interval_coverage * 100)) + theme_scoringutils() + ylab("% Obs inside interval") + xlab("Nominal interval coverage") + diff --git a/README.Rmd b/README.Rmd index 77584d145..0c4c41223 100644 --- a/README.Rmd +++ b/README.Rmd @@ -91,8 +91,8 @@ Forecasts can be easily and quickly scored using the `score()` function. `score( example_quantile %>% set_forecast_unit(c("location", "target_end_date", "target_type", "horizon", "model")) %>% validate() %>% + add_coverage() %>% score() %>% - add_coverage(ranges = c(50, 90), by = c("model", "target_type")) %>% summarise_scores( by = c("model", "target_type") ) %>% diff --git a/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg b/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg index 548878c34..91848b1dd 100644 --- a/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg +++ b/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg @@ -57,15 +57,17 @@ 100 Nominal interval coverage % Obs inside interval -model - - - - -EuroCOVIDhub-baseline -EuroCOVIDhub-ensemble -UMass-MechBayes -epiforecasts-EpiNow2 +model + + + + + +EuroCOVIDhub-baseline +EuroCOVIDhub-ensemble +UMass-MechBayes +epiforecasts-EpiNow2 +NA plot_interval_coverage diff --git a/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg b/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg index bf686eedb..76808cc67 100644 --- a/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg +++ b/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg @@ -57,15 +57,17 @@ 1.00 Quantile % Obs below quantile -model - - - - -EuroCOVIDhub-baseline -EuroCOVIDhub-ensemble -UMass-MechBayes -epiforecasts-EpiNow2 +model + + + + + +EuroCOVIDhub-baseline +EuroCOVIDhub-ensemble +UMass-MechBayes +epiforecasts-EpiNow2 +NA plot_quantile_coverage diff --git a/tests/testthat/_snaps/plot_ranges/plot-ranges-dispersion.svg b/tests/testthat/_snaps/plot_ranges/plot-ranges-dispersion.svg index 812e1600f..4ad667f8a 100644 --- a/tests/testthat/_snaps/plot_ranges/plot-ranges-dispersion.svg +++ b/tests/testthat/_snaps/plot_ranges/plot-ranges-dispersion.svg @@ -25,42 +25,42 @@ - - - - - - - - - - - + - - - - - - - - - - + - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -82,54 +82,54 @@ - - - - - - - - - - - + - - - - - - - - - - + + - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/_snaps/plot_ranges/plot-ranges-interval.svg b/tests/testthat/_snaps/plot_ranges/plot-ranges-interval.svg index 15c9ee3e3..98a9a883c 100644 --- a/tests/testthat/_snaps/plot_ranges/plot-ranges-interval.svg +++ b/tests/testthat/_snaps/plot_ranges/plot-ranges-interval.svg @@ -25,42 +25,42 @@ - - - - - - - - - - - + - - - - - - - - - - + - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -82,54 +82,54 @@ - - - - - - - - - - - + - - - - - - - - - - + + - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -203,7 +203,7 @@ model -interval_score +wis 0 25 diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index ac7057386..a236f299d 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -3,7 +3,11 @@ library(ggplot2, quietly = TRUE) library(data.table) suppressMessages(library(magrittr)) -# compute quantile scores +metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] +metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] + + +# compute scores scores_quantile <- suppressMessages(score(example_quantile)) scores_continuous <- suppressMessages(score(data = example_continuous)) scores_point <- suppressMessages(score(example_point)) diff --git a/tests/testthat/test-add_coverage.R b/tests/testthat/test-add_coverage.R index 50d97e81a..689b8640b 100644 --- a/tests/testthat/test-add_coverage.R +++ b/tests/testthat/test-add_coverage.R @@ -1,31 +1,13 @@ -# ex_coverage <- scores_quantile[model == "EuroCOVIDhub-ensemble"] -# -# test_that("add_coverage() works as expected", { -# expect_error( -# add_coverage(ex_coverage, by = c("model", "target_type"), range = c()) -# ) -# expect_error( -# add_coverage(ex_coverage, by = c("model", "target_type")), NA -# ) -# cov <- add_coverage( -# scores_quantile, by = c("model", "target_type"), range = c(10, 20) -# ) -# expect_equal( -# grep("coverage_", colnames(cov), value = TRUE), -# c("coverage_deviation", "coverage_10", "coverage_20") -# ) -# }) -# -# -# test_that("Order of `add_coverage()` and `summarise_scores()` doesn't matter", { -# # Need to update test. Turns out the order does matter... -# # see https://github.com/epiforecasts/scoringutils/issues/367 -# pw1 <- add_coverage(ex_coverage, by = "model") -# pw1_sum <- summarise_scores(pw1, by = "model") -# -# pw2 <- summarise_scores(ex_coverage, by = "model") -# pw2 <- add_coverage(pw2) -# -# # expect_true(all(pw1_sum == pw2, na.rm = TRUE)) -# # expect_true(all(names(attributes(pw2)) == names(attributes(pw1_sum)))) -# }) +ex_coverage <- example_quantile[model == "EuroCOVIDhub-ensemble"] + +test_that("add_coverage() works as expected", { + expect_no_condition(cov <- add_coverage(example_quantile)) + + required_names <- c( + "range", "interval_coverage", "interval_coverage_deviation", + "quantile_coverage", "quantile_coverage_deviation" + ) + expect_equal(colnames(cov), c(colnames(example_quantile), required_names)) + + expect_equal(nrow(cov), nrow(example_quantile)) +}) diff --git a/tests/testthat/test-metrics-quantile.R b/tests/testthat/test-metrics-quantile.R index 8ff355f02..8dd6d6a22 100644 --- a/tests/testthat/test-metrics-quantile.R +++ b/tests/testthat/test-metrics-quantile.R @@ -1,5 +1,3 @@ -metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] -metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] observed <- c(1, -15, 22) predicted <- rbind( c(-1, 0, 1, 2, 3), diff --git a/tests/testthat/test-plot_interval_coverage.R b/tests/testthat/test-plot_interval_coverage.R index 49649e090..0e885219f 100644 --- a/tests/testthat/test-plot_interval_coverage.R +++ b/tests/testthat/test-plot_interval_coverage.R @@ -1,10 +1,8 @@ -library(ggplot2, quietly = TRUE) - -# test_that("plot_interval_coverage() works as expected", { -# scores <- -# summarise_scores(scores_quantile, by = c("model", "range")) -# p <- plot_interval_coverage(scores) -# expect_s3_class(p, "ggplot") -# skip_on_cran() -# vdiffr::expect_doppelganger("plot_interval_coverage", p) -# }) +test_that("plot_interval_coverage() works as expected", { + coverage <- add_coverage(example_quantile) |> + summarise_scores(by = c("model", "range")) + p <- plot_interval_coverage(coverage) + expect_s3_class(p, "ggplot") + skip_on_cran() + suppressWarnings(vdiffr::expect_doppelganger("plot_interval_coverage", p)) +}) diff --git a/tests/testthat/test-plot_quantile_coverage.R b/tests/testthat/test-plot_quantile_coverage.R index 84b91157f..060b9be26 100644 --- a/tests/testthat/test-plot_quantile_coverage.R +++ b/tests/testthat/test-plot_quantile_coverage.R @@ -1,9 +1,9 @@ -# test_that("plot_quantile_coverage() works as expected", { -# scores <- suppressMessages( -# summarise_scores(scores_quantile, by = c("model", "quantile")) -# ) -# p <- plot_quantile_coverage(scores) -# expect_s3_class(p, "ggplot") -# skip_on_cran() -# vdiffr::expect_doppelganger("plot_quantile_coverage", p) -# }) +test_that("plot_quantile_coverage() works as expected", { + coverage <- add_coverage(example_quantile) |> + summarise_scores(by = c("model", "quantile")) + + p <- plot_quantile_coverage(coverage) + expect_s3_class(p, "ggplot") + skip_on_cran() + suppressWarnings(vdiffr::expect_doppelganger("plot_quantile_coverage", p)) +}) diff --git a/tests/testthat/test-plot_ranges.R b/tests/testthat/test-plot_ranges.R index fad3c8095..b4dec124e 100644 --- a/tests/testthat/test-plot_ranges.R +++ b/tests/testthat/test-plot_ranges.R @@ -1,19 +1,24 @@ -# sum_scores <- suppressMessages( -# summarise_scores(scores_quantile, by = c("model", "target_type", "range")) -# ) -# -# test_that("plot_ranges() works as expected with interval score", { -# p <- plot_ranges(sum_scores, x = "model") + -# facet_wrap(~target_type, scales = "free") -# expect_s3_class(p, "ggplot") -# skip_on_cran() -# vdiffr::expect_doppelganger("plot_ranges_interval", p) -# }) -# -# test_that("plot_ranges() works as expected with dispersion", { -# p <- plot_ranges(sum_scores, y = "dispersion", x = "model") + -# facet_wrap(~target_type) -# expect_s3_class(p, "ggplot") -# skip_on_cran() -# vdiffr::expect_doppelganger("plot_ranges_dispersion", p) -# }) +m <- modifyList(metrics_no_cov_no_ae, list("bias" = NULL)) + +sum_scores <- copy(example_quantile) %>% + .[, interval_range := scoringutils:::get_range_from_quantile(quantile)] |> + score(metrics = m) |> + summarise_scores(by = c("model", "target_type", "interval_range")) + +sum_scores[, range := interval_range] + +test_that("plot_ranges() works as expected with interval score", { + p <- plot_ranges(sum_scores, x = "model") + + facet_wrap(~target_type, scales = "free") + expect_s3_class(p, "ggplot") + skip_on_cran() + suppressWarnings(vdiffr::expect_doppelganger("plot_ranges_interval", p)) +}) + +test_that("plot_ranges() works as expected with dispersion", { + p <- plot_ranges(sum_scores, y = "dispersion", x = "model") + + facet_wrap(~target_type) + expect_s3_class(p, "ggplot") + skip_on_cran() + suppressWarnings(vdiffr::expect_doppelganger("plot_ranges_dispersion", p)) +}) diff --git a/tests/testthat/test-score.R b/tests/testthat/test-score.R index 6252c12c8..5e8e76083 100644 --- a/tests/testthat/test-score.R +++ b/tests/testthat/test-score.R @@ -1,6 +1,3 @@ -metrics_no_cov <- metrics_quantile[!grepl("coverage", names(metrics_quantile))] -metrics_no_cov_no_ae <- metrics_no_cov[!grepl("ae", names(metrics_no_cov))] - # common error handling -------------------------------------------------------- test_that("function throws an error if data is missing", { expect_error(suppressMessages(score(data = NULL))) diff --git a/vignettes/scoringutils.Rmd b/vignettes/scoringutils.Rmd index 6411fad70..4f6989834 100644 --- a/vignettes/scoringutils.Rmd +++ b/vignettes/scoringutils.Rmd @@ -399,8 +399,7 @@ example_integer %>% sample_to_quantile( quantiles = c(0.01, 0.025, seq(0.05, 0.95, 0.05), 0.975, 0.99) ) %>% - score() # %>% - # add_coverage(by = c("model", "target_type")) + score() ``` ## Available metrics From 79fc5333e676209b4a31041e70af24688b9fd646 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 13 Nov 2023 16:03:19 +0000 Subject: [PATCH 68/81] Automatic readme update --- README.md | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2b0e1d1f9..0a5f93881 100644 --- a/README.md +++ b/README.md @@ -129,8 +129,8 @@ details. Finally we summarise these scores by model and target type. example_quantile %>% set_forecast_unit(c("location", "target_end_date", "target_type", "horizon", "model")) %>% validate() %>% + add_coverage() %>% score() %>% - add_coverage(ranges = c(50, 90), by = c("model", "target_type")) %>% summarise_scores( by = c("model", "target_type") ) %>% @@ -144,15 +144,15 @@ example_quantile %>% kable() ``` -| model | target_type | interval_score | dispersion | underprediction | overprediction | coverage_deviation | bias | ae_median | coverage_50 | coverage_90 | relative_skill | scaled_rel_skill | -|:----------------------|:------------|---------------:|-----------:|----------------:|---------------:|-------------------:|--------:|----------:|------------:|------------:|---------------:|-----------------:| -| EuroCOVIDhub-baseline | Cases | 28000 | 4100 | 10000.0 | 14000.0 | -0.110 | 0.0980 | 38000 | 0.33 | 0.82 | 1.30 | 1.6 | -| EuroCOVIDhub-baseline | Deaths | 160 | 91 | 2.1 | 66.0 | 0.120 | 0.3400 | 230 | 0.66 | 1.00 | 2.30 | 3.8 | -| EuroCOVIDhub-ensemble | Cases | 18000 | 3700 | 4200.0 | 10000.0 | -0.098 | -0.0560 | 24000 | 0.39 | 0.80 | 0.82 | 1.0 | -| EuroCOVIDhub-ensemble | Deaths | 41 | 30 | 4.1 | 7.1 | 0.200 | 0.0730 | 53 | 0.88 | 1.00 | 0.60 | 1.0 | -| UMass-MechBayes | Deaths | 53 | 27 | 17.0 | 9.0 | -0.023 | -0.0220 | 78 | 0.46 | 0.88 | 0.75 | 1.3 | -| epiforecasts-EpiNow2 | Cases | 21000 | 5700 | 3300.0 | 12000.0 | -0.067 | -0.0790 | 28000 | 0.47 | 0.79 | 0.95 | 1.2 | -| epiforecasts-EpiNow2 | Deaths | 67 | 32 | 16.0 | 19.0 | -0.043 | -0.0051 | 100 | 0.42 | 0.91 | 0.98 | 1.6 | +| model | target_type | wis | overprediction | underprediction | dispersion | bias | coverage_50 | coverage_90 | coverage_deviation | ae_median | relative_skill | scaled_rel_skill | +|:----------------------|:------------|------:|---------------:|----------------:|-----------:|--------:|------------:|------------:|-------------------:|----------:|---------------:|-----------------:| +| EuroCOVIDhub-baseline | Cases | 28000 | 14000.0 | 10000.0 | 4100 | 0.0980 | 0.33 | 0.82 | -0.120 | 38000 | 1.30 | 1.6 | +| EuroCOVIDhub-baseline | Deaths | 160 | 66.0 | 2.1 | 91 | 0.3400 | 0.66 | 1.00 | 0.120 | 230 | 2.30 | 3.8 | +| EuroCOVIDhub-ensemble | Cases | 18000 | 10000.0 | 4200.0 | 3700 | -0.0560 | 0.39 | 0.80 | -0.100 | 24000 | 0.82 | 1.0 | +| EuroCOVIDhub-ensemble | Deaths | 41 | 7.1 | 4.1 | 30 | 0.0730 | 0.88 | 1.00 | 0.200 | 53 | 0.60 | 1.0 | +| UMass-MechBayes | Deaths | 53 | 9.0 | 17.0 | 27 | -0.0220 | 0.46 | 0.88 | -0.025 | 78 | 0.75 | 1.3 | +| epiforecasts-EpiNow2 | Cases | 21000 | 12000.0 | 3300.0 | 5700 | -0.0790 | 0.47 | 0.79 | -0.070 | 28000 | 0.95 | 1.2 | +| epiforecasts-EpiNow2 | Deaths | 67 | 19.0 | 16.0 | 32 | -0.0051 | 0.42 | 0.91 | -0.045 | 100 | 0.98 | 1.6 | `scoringutils` contains additional functionality to transform forecasts, to summarise scores at different levels, to visualise them, and to @@ -174,20 +174,27 @@ example_quantile %>% score %>% summarise_scores(by = c("model", "target_type", "scale")) %>% head() -#> model target_type scale interval_score dispersion -#> 1: EuroCOVIDhub-baseline Cases log 1.169972e+00 0.4373146 -#> 2: EuroCOVIDhub-baseline Cases natural 2.209046e+04 4102.5009443 -#> 3: EuroCOVIDhub-ensemble Cases log 5.500974e-01 0.1011850 -#> 4: EuroCOVIDhub-ensemble Cases natural 1.155071e+04 3663.5245788 -#> 5: epiforecasts-EpiNow2 Cases log 6.005778e-01 0.1066329 -#> 6: epiforecasts-EpiNow2 Cases natural 1.443844e+04 5664.3779484 -#> underprediction overprediction coverage_deviation bias ae_median -#> 1: 3.521964e-01 0.3804607 -0.10940217 0.09726562 1.185905e+00 -#> 2: 1.028497e+04 7702.9836957 -0.10940217 0.09726562 3.208048e+04 -#> 3: 1.356563e-01 0.3132561 -0.09785326 -0.05640625 7.410484e-01 -#> 4: 4.237177e+03 3650.0047554 -0.09785326 -0.05640625 1.770795e+04 -#> 5: 1.858699e-01 0.3080750 -0.06660326 -0.07890625 7.656591e-01 -#> 6: 3.260356e+03 5513.7058424 -0.06660326 -0.07890625 2.153070e+04 +#> model target_type scale wis overprediction +#> 1: EuroCOVIDhub-ensemble Cases natural 11550.70664 3650.004755 +#> 2: EuroCOVIDhub-baseline Cases natural 22090.45747 7702.983696 +#> 3: epiforecasts-EpiNow2 Cases natural 14438.43943 5513.705842 +#> 4: EuroCOVIDhub-ensemble Deaths natural 41.42249 7.138247 +#> 5: EuroCOVIDhub-baseline Deaths natural 159.40387 65.899117 +#> 6: UMass-MechBayes Deaths natural 52.65195 8.978601 +#> underprediction dispersion bias coverage_50 coverage_90 +#> 1: 4237.177310 3663.52458 -0.05640625 0.3906250 0.8046875 +#> 2: 10284.972826 4102.50094 0.09726562 0.3281250 0.8203125 +#> 3: 3260.355639 5664.37795 -0.07890625 0.4687500 0.7890625 +#> 4: 4.103261 30.18099 0.07265625 0.8750000 1.0000000 +#> 5: 2.098505 91.40625 0.33906250 0.6640625 1.0000000 +#> 6: 16.800951 26.87239 -0.02234375 0.4609375 0.8750000 +#> coverage_deviation ae_median +#> 1: -0.10230114 17707.95312 +#> 2: -0.11437500 32080.48438 +#> 3: -0.06963068 21530.69531 +#> 4: 0.20380682 53.13281 +#> 5: 0.12142045 233.25781 +#> 6: -0.02488636 78.47656 ``` ## Citation From f7faff2f3d9e4ff8701499b94d8016737f1dee70 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 13:50:17 +0100 Subject: [PATCH 69/81] horrible, but working version of a refactoring of score.scoringutils_quantile --- R/score.R | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/R/score.R b/R/score.R index 7ec7763e3..67efd5126 100644 --- a/R/score.R +++ b/R/score.R @@ -263,18 +263,21 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { quantile <- unlist(unique(data$quantile)) data[, c("observed", "predicted", "quantile", "scoringutils_quantile") := NULL] - # for each metric, compute score - lapply(seq_along(metrics), function(i, ...) { - metric_name <- names(metrics[i]) - fun <- metrics[[i]] - matching_args <- filter_function_args(fun, args) - - data[, eval(metric_name) := do.call( - fun, c(list(observed), list(predicted), list(quantile), matching_args) + expr <- expression( + data[, (metric_name) := do.call( + fun, c(list(args$internal_first_arg, + args$internal_second_arg, + args$interal_third_arg), + matching_args) )] - return() - }, - ...) + ) + + data <- apply_metrics( + data, metrics, expr, + internal_first_arg = observed, + internal_second_arg = predicted, + interal_third_arg = quantile, + ...) return(data) }) @@ -283,3 +286,20 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { return(data[]) } + +apply_metrics <- function(data, metrics, expr, ...) { + args <- list(...) + lapply(seq_along(metrics), function(i, data, args) { + + metric_name <- names(metrics[i]) + fun <- metrics[[i]] + matching_args <- filter_function_args(fun, args) + + eval(expr) + + }, data, args) + return(data) +} + + + From cb9bcbe0f95b353943f6a7a59849053698f4ea7c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 14:18:51 +0100 Subject: [PATCH 70/81] More elegant version, currently failing for sample-based forecasts because we can't pass the `forecast_unit` arg to apply_metrics --- R/score.R | 75 +++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/R/score.R b/R/score.R index 67efd5126..d31800ba0 100644 --- a/R/score.R +++ b/R/score.R @@ -152,18 +152,15 @@ score.scoringutils_binary <- function(data, metrics = metrics_binary, ...) { data <- remove_na_observed_predicted(data) metrics <- validate_metrics(metrics) - # Extract the arguments passed in ... - args <- list(...) - lapply(seq_along(metrics), function(i, ...) { - metric_name <- names(metrics[i]) - fun <- metrics[[i]] - matching_args <- filter_function_args(fun, args) - + expr <- expression( data[, (metric_name) := do.call( - fun, c(list(observed, predicted), matching_args) + run_safely, list(observed, predicted, ..., fun = fun) )] - return() - }, ...) + ) + data <- apply_metrics( + data, metrics, expr, + ... + ) setattr(data, "metric_names", names(metrics)) @@ -180,18 +177,15 @@ score.scoringutils_point <- function(data, metrics = metrics_point, ...) { data <- remove_na_observed_predicted(data) metrics <- validate_metrics(metrics) - # Extract the arguments passed in ... - args <- list(...) - lapply(seq_along(metrics), function(i, ...) { - metric_name <- names(metrics[i]) - fun <- metrics[[i]] - matching_args <- filter_function_args(fun, args) - + expr <- expression( data[, (metric_name) := do.call( - fun, c(list(observed, predicted), matching_args) + run_safely, list(observed, predicted, ..., fun = fun) )] - return() - }, ...) + ) + data <- apply_metrics( + data, metrics, expr, + ... + ) setattr(data, "metric_names", names(metrics)) @@ -206,19 +200,15 @@ score.scoringutils_sample <- function(data, metrics = metrics_sample, ...) { forecast_unit <- attr(data, "forecast_unit") metrics <- validate_metrics(metrics) - # Extract the arguments passed in ... - args <- list(...) - lapply(seq_along(metrics), function(i, ...) { - metric_name <- names(metrics[i]) - fun <- metrics[[i]] - matching_args <- filter_function_args(fun, args) - + expr <- expression( data[, (metric_name) := do.call( - fun, c(list(unique(observed), t(predicted)), matching_args) + run_safely, list(observed, predicted, ..., fun = fun) ), by = forecast_unit] - return() - }, - ...) + ) + data <- apply_metrics( + data, metrics, expr, + ... + ) data <- data[ , lapply(.SD, unique), @@ -264,20 +254,12 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { data[, c("observed", "predicted", "quantile", "scoringutils_quantile") := NULL] expr <- expression( - data[, (metric_name) := do.call( - fun, c(list(args$internal_first_arg, - args$internal_second_arg, - args$interal_third_arg), - matching_args) - )] + data[, (metric_name) := do.call(run_safely, list(..., fun = fun))] ) - data <- apply_metrics( data, metrics, expr, - internal_first_arg = observed, - internal_second_arg = predicted, - interal_third_arg = quantile, - ...) + observed, predicted, quantile, ... + ) return(data) }) @@ -288,16 +270,11 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { } apply_metrics <- function(data, metrics, expr, ...) { - args <- list(...) - lapply(seq_along(metrics), function(i, data, args) { - + lapply(seq_along(metrics), function(i, data, ...) { metric_name <- names(metrics[i]) fun <- metrics[[i]] - matching_args <- filter_function_args(fun, args) - eval(expr) - - }, data, args) + }, data, ...) return(data) } From 102370d11303dc3e3b9133dc52de58fcdf2f62c3 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 14:29:44 +0100 Subject: [PATCH 71/81] Fix score.scoringutils_sample by using matrices --- R/score.R | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/R/score.R b/R/score.R index d31800ba0..b0f601d8d 100644 --- a/R/score.R +++ b/R/score.R @@ -200,21 +200,31 @@ score.scoringutils_sample <- function(data, metrics = metrics_sample, ...) { forecast_unit <- attr(data, "forecast_unit") metrics <- validate_metrics(metrics) - expr <- expression( - data[, (metric_name) := do.call( - run_safely, list(observed, predicted, ..., fun = fun) - ), by = forecast_unit] - ) - data <- apply_metrics( - data, metrics, expr, - ... - ) + # transpose the forecasts that belong to the same forecast unit + d_transposed <- data[, .(predicted = list(predicted), + observed = unique(observed), + scoringutils_N = length(list(sample_id))), + by = forecast_unit] - data <- data[ - , lapply(.SD, unique), - .SDcols = colnames(data) %like% paste(names(metrics), collapse = "|"), - by = forecast_unit - ] + # split according to number of samples and do calculations for different + # sample lengths separately + d_split <- split(d_transposed, d_transposed$scoringutils_N) + + split_result <- lapply(d_split, function(data) { + # create a matrix + observed <- data$observed + predicted <- do.call(rbind, data$predicted) + data[, c("observed", "predicted", "scoringutils_N") := NULL] + + expr <- expression( + data[, (metric_name) := do.call(run_safely, list(..., fun = fun))] + ) + data <- apply_metrics( + data, metrics, expr, + observed, predicted, ... + ) + return(data) + }) setattr(data, "metric_names", names(metrics)) @@ -230,9 +240,6 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { forecast_unit <- attr(data, "forecast_unit") metrics <- validate_metrics(metrics) - # Extract the arguments passed in ... - args <- list(...) - # transpose the forecasts that belong to the same forecast unit # make sure the quantiles and predictions are ordered in the same way d_transposed <- data[, .(predicted = list(predicted[order(quantile)]), From 004d2b852d1d03f42110d0b40ab224baca1ce55c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 14:52:30 +0100 Subject: [PATCH 72/81] move the expression into `apply_metrics()` --- R/score.R | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/R/score.R b/R/score.R index b0f601d8d..29230e6e0 100644 --- a/R/score.R +++ b/R/score.R @@ -152,14 +152,9 @@ score.scoringutils_binary <- function(data, metrics = metrics_binary, ...) { data <- remove_na_observed_predicted(data) metrics <- validate_metrics(metrics) - expr <- expression( - data[, (metric_name) := do.call( - run_safely, list(observed, predicted, ..., fun = fun) - )] - ) data <- apply_metrics( - data, metrics, expr, - ... + data, metrics, + data$observed, data$predicted, ... ) setattr(data, "metric_names", names(metrics)) @@ -177,14 +172,9 @@ score.scoringutils_point <- function(data, metrics = metrics_point, ...) { data <- remove_na_observed_predicted(data) metrics <- validate_metrics(metrics) - expr <- expression( - data[, (metric_name) := do.call( - run_safely, list(observed, predicted, ..., fun = fun) - )] - ) data <- apply_metrics( - data, metrics, expr, - ... + data, metrics, + data$observed, data$predicted, ... ) setattr(data, "metric_names", names(metrics)) @@ -216,16 +206,13 @@ score.scoringutils_sample <- function(data, metrics = metrics_sample, ...) { predicted <- do.call(rbind, data$predicted) data[, c("observed", "predicted", "scoringutils_N") := NULL] - expr <- expression( - data[, (metric_name) := do.call(run_safely, list(..., fun = fun))] - ) data <- apply_metrics( - data, metrics, expr, + data, metrics, observed, predicted, ... ) return(data) }) - + data <- rbindlist(split_result) setattr(data, "metric_names", names(metrics)) return(data[]) @@ -260,11 +247,8 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { quantile <- unlist(unique(data$quantile)) data[, c("observed", "predicted", "quantile", "scoringutils_quantile") := NULL] - expr <- expression( - data[, (metric_name) := do.call(run_safely, list(..., fun = fun))] - ) data <- apply_metrics( - data, metrics, expr, + data, metrics, observed, predicted, quantile, ... ) return(data) @@ -276,7 +260,10 @@ score.scoringutils_quantile <- function(data, metrics = metrics_quantile, ...) { return(data[]) } -apply_metrics <- function(data, metrics, expr, ...) { +apply_metrics <- function(data, metrics, ...) { + expr <- expression( + data[, (metric_name) := do.call(run_safely, list(..., fun = fun))] + ) lapply(seq_along(metrics), function(i, data, ...) { metric_name <- names(metrics[i]) fun <- metrics[[i]] From 7eb7c96300f0344c70d39c939418abb3852c4d80 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 16:09:50 +0100 Subject: [PATCH 73/81] Update metrics_quantile (improved error handling + getting rid of `run_safely()` --- NAMESPACE | 1 + R/metrics-quantile.R | 6 ++++++ data/metrics_quantile.rda | Bin 13133 -> 13024 bytes inst/create-list-available-forecasts.R | 4 ++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index bc2a6b542..d3b6ffe22 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -82,6 +82,7 @@ importFrom(checkmate,assert_data_frame) importFrom(checkmate,assert_data_table) importFrom(checkmate,assert_factor) importFrom(checkmate,assert_list) +importFrom(checkmate,assert_logical) importFrom(checkmate,assert_number) importFrom(checkmate,assert_numeric) importFrom(checkmate,check_atomic_vector) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index db187d376..985b00002 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -91,6 +91,7 @@ #' @param count_median_twice if TRUE, count the median twice in the score #' @param na.rm if TRUE, ignore NA values when computing the score #' @importFrom stats weighted.mean +#' @importFrom checkmate assert_logical #' @return #' `wis()`: a numeric vector with WIS values of size n (one per observation), #' or a list with separate entries if `separate_results` is `TRUE`. @@ -105,6 +106,11 @@ wis <- function(observed, assert_input_quantile(observed, predicted, quantile) reformatted <- quantile_to_interval(observed, predicted, quantile) + assert_logical(separate_results, len = 1) + assert_logical(weigh, len = 1) + assert_logical(count_median_twice, len = 1) + assert_logical(na.rm, len = 1) + if (separate_results) { cols <- c("wis", "dispersion", "underprediction", "overprediction") } else { diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index 70a00a9329468320b53b2c7e803ec070df6b33a9..b14a8321c408c6e6d9010c2262f0575fa845a9ea 100644 GIT binary patch literal 13024 zcmV<6G9S%CT4*^jL0KkKS;tuSi~!s@|NsC0|NsC0|NsC0|NsC0|NsC0`|!&WF>;(YUfB*mmtXjZPW-oB=-q@f5 zzE71_t4^8vIaLFKsngqnqPe1}@L|_Frnqx_( zLTxk*g*It2YI!q3Fs9Q1Cyf;J!kM%RZ$xTgHj(5fqZ1QTA*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J zpNIOQbUE{EWJm6E)m4ylVN-n7A*kS#EeE?F+uSw)V*@LHcH41Q*K@T)f7KaG;|~Q- z03MdGsXXweE-|Cy+=Y$t6C%*SQZ<9v>g7Yx1zKuQJSgmcp}nuLc-|}t2HjIDC~Yh{Hsf~YQSAp6AeVH zXt5tP(6S9xw;t*B*J3x9^x8s($}Kt4_c6+l8$^b9ju^UoI2P^Qk|52Ts~%KD3)lw(9fiPgBUUl>}?Z%3t&AyZ8HFU%YR}@2~wm-LB>u^4$HO6^Gf%vKr{|`d7P*7`&dFAMI}b z?^*PEmA>Z>xcfUiEp{9ouS@Cwm7S$$S}SlBe|g3AVkYiuTs*@t=4W*wc!l`@Ndeka zy39A)`k!5r`)s%9J%;-)FKh241?ZH6_sNeK_b+PC)KbqA#W4aPsi7)SDN-hysv~3& z)J~hJQG-PZuxhAIlZmLCO;}@O5tQb%Ml}|bRu&~LP}NPv2^@}?qNbx08W6_Yq>>sM zKP0CaWI!Akkx3P+Ry>9_!t^Anu3+eji&4ax n0LR4i9G}MM`QKJ5FP1~9FjvvYsPC)n&;J*4ML1B9=DWpp5zsP{ diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index fcac2950c..fc4926797 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -28,8 +28,8 @@ metrics_quantile <- list( "underprediction" = underprediction, "dispersion" = dispersion, "bias" = bias_quantile, - "coverage_50" = \(...) {run_safely(..., range = 50, fun = interval_coverage_quantile)}, - "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)}, + "coverage_50" = \(...) {do.call(interval_coverage_quantile, c(list(...), range = 50))}, + "coverage_90" = \(...) {do.call(interval_coverage_quantile, c(list(...), range = 90))}, "coverage_deviation" = interval_coverage_deviation_quantile, "ae_median" = ae_median_quantile ) From 6c213fc71da27056276dd77e7eeb04e024384d38 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 16:14:54 +0100 Subject: [PATCH 74/81] Add global variable to fix failing test --- R/z_globalVariables.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/z_globalVariables.R b/R/z_globalVariables.R index 28bcfb95b..89cfc2eab 100644 --- a/R/z_globalVariables.R +++ b/R/z_globalVariables.R @@ -62,6 +62,7 @@ globalVariables(c( "rel_to_baseline", "relative_skill", "rn", + "sample_id", "scoringutils_InternalDuplicateCheck", "scoringutils_InternalNumCheck", "se_mean", From 97059948dea0a6b7f4ca0f43219874beb6faaa36 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 21:13:35 +0100 Subject: [PATCH 75/81] Create function to ensure an object is a data.table --- R/utils.R | 18 ++++++++++++++++++ R/utils_data_handling.R | 14 ++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/R/utils.R b/R/utils.R index 0d160065e..53a2d800e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -252,3 +252,21 @@ run_safely <- function(..., fun) { return(result) } + +#' Ensure That an Object is a Data Table +#' @description This function ensures that an object is a data table. +#' If the object is not a data table, it is converted to one. If the object +#' is a data table, a copy of the object is returned. +#' @param data An object to ensure is a data table +#' @return A data table +#' @keywords internal +#' @importFrom data.table copy is.data.table as.data.table +ensure_data.table <- function(data) { + if (!is.data.table(data)) { + data <- as.data.table(data) + } else { + data <- copy(data) + } + return(data) +} + diff --git a/R/utils_data_handling.R b/R/utils_data_handling.R index 66849e2cc..1b1302dbf 100644 --- a/R/utils_data_handling.R +++ b/R/utils_data_handling.R @@ -101,12 +101,7 @@ merge_pred_and_obs <- function(forecasts, observations, sample_to_quantile <- function(data, quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95), type = 7) { - if (!is.data.table(data)) { - data <- data.table::as.data.table(data) - } else { - data <- copy(data) - } - + data <- ensure_data.table(data) reserved_columns <- c("predicted", "sample_id") by <- setdiff(colnames(data), reserved_columns) @@ -208,12 +203,7 @@ quantile_to_interval.data.frame <- function(dt, format = "long", keep_quantile_col = FALSE, ...) { - if (!is.data.table(dt)) { - dt <- data.table::as.data.table(dt) - } else { - # use copy to avoid - dt <- copy(dt) - } + dt <- ensure_data.table(dt) dt[, boundary := ifelse(quantile <= 0.5, "lower", "upper")] dt[, range := get_range_from_quantile(quantile)] From afdd3ac372a38da564b1cfe44872b30b84fbb495 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 21:14:25 +0100 Subject: [PATCH 76/81] Simplify set_forcast_unit and ensure that it operates on a data.table --- R/convenience-functions.R | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/R/convenience-functions.R b/R/convenience-functions.R index 870e4ac3d..3448df5a3 100644 --- a/R/convenience-functions.R +++ b/R/convenience-functions.R @@ -235,21 +235,16 @@ log_shift <- function(x, offset = 0, base = exp(1)) { #' example_quantile, #' c("location", "target_end_date", "target_type", "horizon", "model") #' ) - set_forecast_unit <- function(data, forecast_unit) { - - datacols <- colnames(data) - missing <- forecast_unit[!(forecast_unit %in% datacols)] - - if (length(missing) > 0) { + data <- ensure_data.table(data) + missing <- check_columns(data, forecast_unit) + if (!is.logical(missing)) { warning( - "Column(s) '", missing, - "' are not columns of the data and will be ignored." + " (stopped checking at the first missing column)." ) forecast_unit <- intersect(forecast_unit, datacols) } - keep_cols <- c(get_protected_columns(data), forecast_unit) out <- unique(data[, .SD, .SDcols = keep_cols])[] return(out) From 218c01c526a332b06bbee808100ddf5e1e1e1751 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 22:15:09 +0100 Subject: [PATCH 77/81] Make message in `check_columns_present` nicer --- R/check-input-helpers.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index cfaa24b2c..6437e55df 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -297,12 +297,22 @@ check_columns_present <- function(data, columns) { } assert_character(columns, min.len = 1) colnames <- colnames(data) + missing <- list() for (x in columns){ if (!(x %in% colnames)) { - msg <- paste0("Column '", x, "' not found in data") - return(msg) + missing[[x]] <- x } } + missing <- unlist(missing) + if (length(missing > 1)) { + msg <- paste0( + "Columns '", paste(missing, collapse = "', '"), "' not found in data" + ) + return(msg) + } else if (length(missing) == 1) { + msg <- paste0("Column '", missing, "' not found in data") + return(msg) + } return(TRUE) } From 21d887aebd6b481154162f7be1d7530ba6838f4c Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 22:40:26 +0100 Subject: [PATCH 78/81] Reintroduce `run_safely()` into `metrics_quantile` - the alternative wasn't working and everything else feels more complicated. --- data/metrics_quantile.rda | Bin 13024 -> 9677 bytes inst/create-list-available-forecasts.R | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/metrics_quantile.rda b/data/metrics_quantile.rda index b14a8321c408c6e6d9010c2262f0575fa845a9ea..b5598113dba4ec1cb98f7628899619b2b8723cda 100644 GIT binary patch literal 9677 zcmZXaXHXMv@aIDkLg)b^(g_f%h#~Z*2?XgHs(^wJdN0zkK0szZq=Sf{p-NRc zNbl06+x33`yL)jn_nGfJv$M0a^L@9oJCC}hvywE{Ld4kOcR=4`Kqlee|IhpXC$;kT z*6KCYZ!112?UOl|=(E?$2UnMTcNE>{ZTXhw-5D=u=``6#TLN9vQvyz214^~q6@qy$ z6dIdX0srAg24HF{Cn~b=)a1W@)n3+549GEqb>TCcP*+CRU`0gYdYp`r@ z@1%Zq_EfjQU4rNq<@}#T3Y6=AoI-K|lW-k1k+6!r7u7*<0yCT@L-qnN2EqUssmNmh=l=qL z?Eh2(#{TyU06>kj)$tdidpYvcXuil%{gB)wkN`>6mXyQcB0K)GTwsf@To&d$-onVq z0Y($h1PI0%%_!?U;IfA%0J@!R*uZ1Xf*J8aReQ3ZWkb^0G+1_Ns#+MU$Sy^@TvVw$ zg+=5GMs6`iwYyUn29-~Xon_TvAZ!W7*`-BxKo$*&(7^m>g{r7UwM1VKA4>%g5h#y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I|GKB$;})bZ_AQx_cqM7qy~y0zt;K^Hyx*A*-~-n`T>O!8V((X z!sibWp4L5{OF`BtLdUiclF48Mmta2Y;&+Kl(V9G$L80?@uxpMr~pLaPmO4_oQ4aZ9hfvb$7n(tOW|_c9Uq za=hT%)H9;WWp%z6>A=U}Iy6l5ZTK!Z+&`iIMD95E{?Oz~BWU;f79ZT(1t>a{pNhFd< zB$7!mu1dA7>v^qCjCg^}cKt*A_3}_gB5%<>HU}@62j+&Td&aRCVT=WqS!I@4Y}dQK zu1!$CVIB4&ZdUvCw$J&x9?qOO)%rRvYyihszrpK0+itibcBbEE<99svk^g1SLv6*a z8|>b(zW8q(xv1Q;&h?hp^1haCym)o)WjIn; zX2dcrUvIFEF6G4Z}ttF!_HA i%KZP6{7;-Buc8LEDle4;N4Ld?{}*yaI8czsSoe%GtddIr diff --git a/inst/create-list-available-forecasts.R b/inst/create-list-available-forecasts.R index fc4926797..07105a7f4 100644 --- a/inst/create-list-available-forecasts.R +++ b/inst/create-list-available-forecasts.R @@ -28,8 +28,8 @@ metrics_quantile <- list( "underprediction" = underprediction, "dispersion" = dispersion, "bias" = bias_quantile, - "coverage_50" = \(...) {do.call(interval_coverage_quantile, c(list(...), range = 50))}, - "coverage_90" = \(...) {do.call(interval_coverage_quantile, c(list(...), range = 90))}, + "coverage_50" = interval_coverage_quantile, + "coverage_90" = \(...) {run_safely(..., range = 90, fun = interval_coverage_quantile)}, "coverage_deviation" = interval_coverage_deviation_quantile, "ae_median" = ae_median_quantile ) From ebe38695b30d066cea117506f8f2d7c7f1ab8394 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 22:40:49 +0100 Subject: [PATCH 79/81] correct `check_columns_present()` --- R/check-input-helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index 6437e55df..95869f02b 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -304,7 +304,7 @@ check_columns_present <- function(data, columns) { } } missing <- unlist(missing) - if (length(missing > 1)) { + if (length(missing) > 1) { msg <- paste0( "Columns '", paste(missing, collapse = "', '"), "' not found in data" ) From ba9adbf9235a0d1e6756d635628e3f7bcfbfa853 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 14 Nov 2023 22:54:33 +0100 Subject: [PATCH 80/81] Update `set_forecast_unit()` and add tests --- R/convenience-functions.R | 9 ++--- man/ensure_data.table.Rd | 20 +++++++++++ tests/testthat/test-convenience-functions.R | 39 +++++++++++++-------- tests/testthat/test-score.R | 8 ++--- 4 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 man/ensure_data.table.Rd diff --git a/R/convenience-functions.R b/R/convenience-functions.R index 3448df5a3..31f3ab5ab 100644 --- a/R/convenience-functions.R +++ b/R/convenience-functions.R @@ -237,13 +237,10 @@ log_shift <- function(x, offset = 0, base = exp(1)) { #' ) set_forecast_unit <- function(data, forecast_unit) { data <- ensure_data.table(data) - missing <- check_columns(data, forecast_unit) + missing <- check_columns_present(data, forecast_unit) if (!is.logical(missing)) { - warning( - missing, - " (stopped checking at the first missing column)." - ) - forecast_unit <- intersect(forecast_unit, datacols) + warning(missing) + forecast_unit <- intersect(forecast_unit, colnames(data)) } keep_cols <- c(get_protected_columns(data), forecast_unit) out <- unique(data[, .SD, .SDcols = keep_cols])[] diff --git a/man/ensure_data.table.Rd b/man/ensure_data.table.Rd new file mode 100644 index 000000000..6d2457ee5 --- /dev/null +++ b/man/ensure_data.table.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{ensure_data.table} +\alias{ensure_data.table} +\title{Ensure That an Object is a Data Table} +\usage{ +ensure_data.table(data) +} +\arguments{ +\item{data}{An object to ensure is a data table} +} +\value{ +A data table +} +\description{ +This function ensures that an object is a data table. +If the object is not a data table, it is converted to one. If the object +is a data table, a copy of the object is returned. +} +\keyword{internal} diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index ecfc86653..98d784cd4 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -38,46 +38,55 @@ test_that("function transform_forecasts works", { }) +# ============================================================================ # +# `set_forecast_unit()` +# ============================================================================ # test_that("function set_forecast_unit() works", { - # some columns in the example data have duplicated information. So we can remove # these and see whether the result stays the same. - - scores1 <- suppressMessages(score(example_quantile)) - scores1 <- scores1[order(location, target_end_date, target_type, horizon, model), ] + scores1 <- scores_quantile[order(location, target_end_date, target_type, horizon, model), ] ex2 <- set_forecast_unit( example_quantile, c("location", "target_end_date", "target_type", "horizon", "model") ) - scores2 <- suppressMessages(score(ex2)) + scores2 <- score(ex2) scores2 <- scores2[order(location, target_end_date, target_type, horizon, model), ] expect_equal(scores1$interval_score, scores2$interval_score) }) +test_that("set_forecast_unit() works on input that's not a data.table", { + df <- data.frame( + a = 1:2, + b = 2:3, + c = 3:4 + ) + expect_equal( + colnames(set_forecast_unit(df, c("a", "b"))), + c("a", "b") + ) + # apparently it also works on a matrix... good to know :) + expect_equal( + names(set_forecast_unit(as.matrix(df), "a")), + "a" + ) +}) -test_that("function set_forecast_unit() gives warning when column is not there", { +test_that("function set_forecast_unit() gives warning when column is not there", { expect_warning( set_forecast_unit( example_quantile, - c("location", "target_end_date", "target_type", "horizon", "model", "test") + c("location", "target_end_date", "target_type", "horizon", "model", "test1", "test2") ) ) }) - test_that("function get_forecast_unit() and set_forecast_unit() work together", { - fu_set <- c("location", "target_end_date", "target_type", "horizon", "model") - - ex <- set_forecast_unit( - example_binary, - fu_set - ) - + ex <- set_forecast_unit(example_binary, fu_set) fu_get <- get_forecast_unit(ex) expect_equal(fu_set, fu_get) }) diff --git a/tests/testthat/test-score.R b/tests/testthat/test-score.R index 5e8e76083..a67575984 100644 --- a/tests/testthat/test-score.R +++ b/tests/testthat/test-score.R @@ -168,17 +168,13 @@ test_that("score.scoringutils_point() errors with only NA values", { test_that("score_quantile correctly handles separate results = FALSE", { df <- example_quantile[model == "EuroCOVIDhub-ensemble" & target_type == "Cases" & location == "DE"] - eval <- suppressMessages( - score( - df[!is.na(predicted)], - separate_results = FALSE - ) - ) + eval <- score(df[!is.na(predicted)], separate_results = FALSE) expect_equal( nrow(eval) > 1, TRUE ) + expect_true(all(names(metrics_quantile) %in% colnames(eval))) }) From a9e89bbb87256aedc6e8b8127721437a8dc6b2cc Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Wed, 15 Nov 2023 15:51:26 +0100 Subject: [PATCH 81/81] Allow passing additional arguments to `wis()` from `overprediction()`, `underprediction()` and `dispersion()` --- R/metrics-quantile.R | 20 ++++++++++++++------ man/wis.Rd | 9 ++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/R/metrics-quantile.R b/R/metrics-quantile.R index f3598690e..1b74a932c 100644 --- a/R/metrics-quantile.R +++ b/R/metrics-quantile.R @@ -144,11 +144,15 @@ wis <- function(observed, #' @return #' `dispersion()`: a numeric vector with dispersion values (one per observation) +#' @param ... Additional arguments passed on to `wis()` from functions +#' `overprediction()`, `underprediction()` and `dispersion()` #' @export #' @rdname wis -dispersion <- function(observed, predicted, quantile) { +dispersion <- function(observed, predicted, quantile, ...) { + args <- list(...) + args$separate_results <- TRUE assert_input_quantile(observed, predicted, quantile) - wis(observed, predicted, quantile, separate_results = TRUE)$dispersion + do.call(wis, c(list(observed), list(predicted), list(quantile), args))$dispersion } @@ -157,9 +161,11 @@ dispersion <- function(observed, predicted, quantile) { #' observation) #' @export #' @rdname wis -overprediction <- function(observed, predicted, quantile) { +overprediction <- function(observed, predicted, quantile, ...) { + args <- list(...) + args$separate_results <- TRUE assert_input_quantile(observed, predicted, quantile) - wis(observed, predicted, quantile, separate_results = TRUE)$overprediction + do.call(wis, c(list(observed), list(predicted), list(quantile), args))$overprediction } @@ -168,9 +174,11 @@ overprediction <- function(observed, predicted, quantile) { #' observation) #' @export #' @rdname wis -underprediction <- function(observed, predicted, quantile) { +underprediction <- function(observed, predicted, quantile, ...) { + args <- list(...) + args$separate_results <- TRUE assert_input_quantile(observed, predicted, quantile) - wis(observed, predicted, quantile, separate_results = TRUE)$underprediction + do.call(wis, c(list(observed), list(predicted), list(quantile), args))$underprediction } diff --git a/man/wis.Rd b/man/wis.Rd index a76b3c35f..0b4853e76 100644 --- a/man/wis.Rd +++ b/man/wis.Rd @@ -17,11 +17,11 @@ wis( na.rm = TRUE ) -dispersion(observed, predicted, quantile) +dispersion(observed, predicted, quantile, ...) -overprediction(observed, predicted, quantile) +overprediction(observed, predicted, quantile, ...) -underprediction(observed, predicted, quantile) +underprediction(observed, predicted, quantile, ...) } \arguments{ \item{observed}{A vector with observed values of size n} @@ -44,6 +44,9 @@ Default: \code{TRUE}.} \item{count_median_twice}{if TRUE, count the median twice in the score} \item{na.rm}{if TRUE, ignore NA values when computing the score} + +\item{...}{Additional arguments passed on to \code{wis()} from functions +\code{overprediction()}, \code{underprediction()} and \code{dispersion()}} } \value{ \code{wis()}: a numeric vector with WIS values (one per observation), or a list