From f525c0256d83ceaca801ec87d20cc4d4df6ada6a Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 3 Sep 2023 18:45:23 +0200 Subject: [PATCH 1/5] Add documentation for the return value of `summarise_scores()` --- DESCRIPTION | 2 +- NEWS.md | 7 +++++++ R/summarise_scores.R | 3 +++ man/summarise_scores.Rd | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3e876aaf7..2fabe6a00 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: scoringutils Title: Utilities for Scoring and Assessing Predictions -Version: 1.2.1 +Version: 1.2.2 Language: en-GB Authors@R: c( person(given = "Nikos", diff --git a/NEWS.md b/NEWS.md index eb47b1cb4..b63a91048 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# scoringutils 1.2.2 + +This minor update addresses comments made by review from the Journal of Statistical Software (see preprint of the manuscript [here](https://arxiv.org/abs/2205.07090)). + +## Package updates +- add documentation for the return value of `summarise_scores()`. + # scoringutils 1.2.1 ## Package updates diff --git a/R/summarise_scores.R b/R/summarise_scores.R index 5283a8061..d3c1847c2 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -41,6 +41,9 @@ #' @param ... additional parameters that can be passed to the summary function #' provided to `fun`. For more information see the documentation of the #' respective function. +#' @return a data.table with summarised scores. Scores are summarised according +#' to the names of the columns of the original data specified in `by` or +#' `across` using the `fun` passed to `summarise_scores()`. #' @examples #' data.table::setDTthreads(1) # only needed to avoid issues on CRAN #' library(magrittr) # pipe operator diff --git a/man/summarise_scores.Rd b/man/summarise_scores.Rd index ed63cf1af..811f9b2df 100644 --- a/man/summarise_scores.Rd +++ b/man/summarise_scores.Rd @@ -77,6 +77,11 @@ respect to a baseline model.} provided to \code{fun}. For more information see the documentation of the respective function.} } +\value{ +a data.table with summarised scores. Scores are summarised according +to the names of the columns of the original data specified in \code{by} or +\code{across} using the \code{fun} passed to \code{summarise_scores()}. +} \description{ Summarise scores as produced by \code{\link[=score]{score()}} } From 6daa707ca2fe835bb5778d66844f7f7858fb238f Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 3 Sep 2023 18:54:27 +0200 Subject: [PATCH 2/5] remove hard-coded rounding value in `correlation()` --- NEWS.md | 1 + R/correlations.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b63a91048..1ee72d6fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ This minor update addresses comments made by review from the Journal of Statisti ## Package updates - add documentation for the return value of `summarise_scores()`. +- remove hard-coded rounding value for `correlation()`. Previously, the function always rounded correlations to two digits. # scoringutils 1.2.1 diff --git a/R/correlations.R b/R/correlations.R index 5b8233576..a477fd2a9 100644 --- a/R/correlations.R +++ b/R/correlations.R @@ -43,7 +43,7 @@ correlation <- function(scores, df <- df[, .SD, .SDcols = names(df) %in% metrics] # define correlation matrix - cor_mat <- round(cor(as.matrix(df)), 2) + cor_mat <- cor(as.matrix(df)) correlations <- setDT(as.data.frame((cor_mat)), keep.rownames = TRUE From 90c440d2916d61a2b1c1837fcf20ce60264f5caf Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 3 Sep 2023 19:37:21 +0200 Subject: [PATCH 3/5] Introduce a `digits` argument to `correlation()` to set the number of digits the output is rounded to --- NEWS.md | 2 +- R/correlations.R | 11 +++++++++-- man/correlation.Rd | 7 +++++-- tests/testthat/test-plot_correlation.R | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1ee72d6fe..1a93a9b37 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ This minor update addresses comments made by review from the Journal of Statisti ## Package updates - add documentation for the return value of `summarise_scores()`. -- remove hard-coded rounding value for `correlation()`. Previously, the function always rounded correlations to two digits. +- remove hard-coded rounding value for `correlation()`. Previously, the function always rounded correlations to two digits. Instead, a new argument, `digits` was introduced and the default set to 0, meaning that no rounding takes place. # scoringutils 1.2.1 diff --git a/R/correlations.R b/R/correlations.R index a477fd2a9..2033a8a00 100644 --- a/R/correlations.R +++ b/R/correlations.R @@ -7,6 +7,8 @@ #' @param metrics A character vector with the metrics to show. If set to #' `NULL` (default), all metrics present in `scores` will #' be shown +#' @param digits A number indicating how many decimal places the result should +#' be rounded to. By default (`digits = NULL`) no rounding takes place. #' @inheritParams pairwise_comparison #' @return A data.table with correlations for the different metrics #' @importFrom data.table setDT @@ -15,9 +17,10 @@ #' @keywords scoring #' @examples #' scores <- score(example_quantile) -#' correlation(scores) +#' correlation(scores, digits = 2) correlation <- function(scores, - metrics = NULL) { + metrics = NULL, + digits = NULL) { metrics <- check_metrics(metrics) # check metrics are present @@ -45,6 +48,10 @@ correlation <- function(scores, # define correlation matrix cor_mat <- cor(as.matrix(df)) + if (!is.null(digits)) { + cor_mat <- round(cor_mat, digits) + } + correlations <- setDT(as.data.frame((cor_mat)), keep.rownames = TRUE )[, metric := rn][, rn := NULL] diff --git a/man/correlation.Rd b/man/correlation.Rd index 77de3a469..59bda9e42 100644 --- a/man/correlation.Rd +++ b/man/correlation.Rd @@ -4,7 +4,7 @@ \alias{correlation} \title{Correlation Between Metrics} \usage{ -correlation(scores, metrics = NULL) +correlation(scores, metrics = NULL, digits = NULL) } \arguments{ \item{scores}{A data.table of scores as produced by \code{\link[=score]{score()}}.} @@ -12,6 +12,9 @@ correlation(scores, metrics = NULL) \item{metrics}{A character vector with the metrics to show. If set to \code{NULL} (default), all metrics present in \code{scores} will be shown} + +\item{digits}{A number indicating how many decimal places the result should +be rounded to. By default (\code{digits = NULL}) no rounding takes place.} } \value{ A data.table with correlations for the different metrics @@ -22,6 +25,6 @@ scores as produced by \code{\link[=score]{score()}}. } \examples{ scores <- score(example_quantile) -correlation(scores) +correlation(scores, digits = 2) } \keyword{scoring} diff --git a/tests/testthat/test-plot_correlation.R b/tests/testthat/test-plot_correlation.R index 9d6280d6e..be29faf3b 100644 --- a/tests/testthat/test-plot_correlation.R +++ b/tests/testthat/test-plot_correlation.R @@ -1,5 +1,5 @@ test_that("plot_correlation() works as expected", { - correlations <- correlation(summarise_scores(scores)) + correlations <- correlation(summarise_scores(scores), digits = 2) p <- plot_correlation(correlations) expect_s3_class(p, "ggplot") skip_on_cran() From 480bef0f8a157713fa5ee62375ce6c1917f26877 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 3 Sep 2023 19:45:01 +0200 Subject: [PATCH 4/5] specify digits = 2 in several examples that use `correlation()` --- R/plot.R | 3 ++- inst/manuscript/R/00-standalone-Figure-replication.R | 2 +- inst/manuscript/manuscript.Rmd | 2 +- man/plot_correlation.Rd | 3 ++- vignettes/scoringutils.Rmd | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/plot.R b/R/plot.R index 8af22d507..f1771bd18 100644 --- a/R/plot.R +++ b/R/plot.R @@ -1023,7 +1023,8 @@ plot_avail_forecasts <- function(avail_forecasts, #' @examples #' scores <- score(example_quantile) #' correlations <- correlation( -#' summarise_scores(scores) +#' summarise_scores(scores), +#' digits = 2 #' ) #' plot_correlation(correlations) diff --git a/inst/manuscript/R/00-standalone-Figure-replication.R b/inst/manuscript/R/00-standalone-Figure-replication.R index 70bb7776b..14bb1f42b 100644 --- a/inst/manuscript/R/00-standalone-Figure-replication.R +++ b/inst/manuscript/R/00-standalone-Figure-replication.R @@ -655,7 +655,7 @@ p1 / p2 + correlations <- example_quantile |> score() |> summarise_scores() |> - correlation() + correlation(digits = 2) correlations |> glimpse() diff --git a/inst/manuscript/manuscript.Rmd b/inst/manuscript/manuscript.Rmd index 3aa6a9f3e..ef97f067b 100644 --- a/inst/manuscript/manuscript.Rmd +++ b/inst/manuscript/manuscript.Rmd @@ -637,7 +637,7 @@ It may sometimes be interesting to see how different scores correlate with each correlations <- example_quantile |> score() |> summarise_scores() |> - correlation() + correlation(digits = 2) correlations |> glimpse() diff --git a/man/plot_correlation.Rd b/man/plot_correlation.Rd index 390c90f20..0bade90cb 100644 --- a/man/plot_correlation.Rd +++ b/man/plot_correlation.Rd @@ -20,7 +20,8 @@ Plots a heatmap of correlations between different metrics \examples{ scores <- score(example_quantile) correlations <- correlation( - summarise_scores(scores) + summarise_scores(scores), + digits = 2 ) plot_correlation(correlations) } diff --git a/vignettes/scoringutils.Rmd b/vignettes/scoringutils.Rmd index 72d1f159f..71130d4d9 100644 --- a/vignettes/scoringutils.Rmd +++ b/vignettes/scoringutils.Rmd @@ -375,7 +375,7 @@ Visualising correlations: example_quantile %>% score() %>% summarise_scores() %>% - correlation() %>% + correlation(digits = 2) %>% plot_correlation() ``` From cb42edb72e7ee93f428f11c87eb6ce7048c99a8a Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 7 Nov 2023 11:59:38 +0000 Subject: [PATCH 5/5] Automatic readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49bbb6270..e23242f13 100644 --- a/README.md +++ b/README.md @@ -181,8 +181,8 @@ example_quantile %>% #> 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.09726563 1.185905e+00 -#> 2: 1.028497e+04 7702.9836957 -0.10940217 0.09726563 3.208048e+04 +#> 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