Skip to content

Commit 2d1bc8b

Browse files
authored
Merge pull request #997 from epiforecasts/ordinal-tolerance
Allow for numeric imprecision for ordinal forecasts
2 parents e85f7e0 + 44f4a60 commit 2d1bc8b

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# scoringutils (development version)
22

3+
- Added tolerance for numeric errors when checking that probabilities sum to one in ordinal forecasts (#997)
34
- Made computation of p-values optional in pairwise comparisons by allowing `test_type = NULL` in `compare_forecasts()`. When `test_type = NULL`, p-values will be `NA` (#978).
45

5-
66
# scoringutils 2.1.0
77

88
Minor spelling / mathematical updates to Scoring rule vignette. (#969)

R/metrics-nominal.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ assert_input_categorical <- function(
7272
assert_matrix(predicted, nrows = n)
7373
summed_predictions <- round(rowSums(predicted, na.rm = TRUE), 10) # avoid numeric errors
7474
}
75-
if (!all(summed_predictions == 1)) {
75+
# Allow for numeric errors
76+
invalid_rows <- abs(summed_predictions - 1) > 1e-4
77+
if (any(invalid_rows)) {
7678
#nolint start: keyword_quote_linter object_usage_linter
77-
row_indices <- as.character(which(summed_predictions != 1))
79+
row_indices <- which(invalid_rows)
7880
cli_abort(
7981
c(
8082
`!` = "Probabilities belonging to a single forecast must sum to one",

0 commit comments

Comments
 (0)