Univariate metrics: edge cases in PIT, integer detection, interval coverage and input checks

Open
#1,271 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
r
Domain
data

Research direction

Start by reading the affected metric implementations and their tests in the scoringutils package, especially pit_histogram_sample(), get_type(), interval_coverage(), logs_binary(), and the quantile and point metric functions. Reproduce the listed examples and check existing tests for input validation, missing values, and matrix outputs. Done means the reported edge cases have consistent, tested behavior across the affected metrics.

Written by the indexing model from the issue text.

Description

CLAUDE: - [ ] The randomised PIT uses one uniform draw per replicate for all forecasts (runif(1)); Czado et al. (2009) use an independent draw per forecast. With few replicates the histogram of a calibrated forecast looks miscalibrated.

P <- matrix(rep(0:9, 100), 100, byrow = TRUE); set.seed(1)
pit_histogram_sample(rep(5, 100), P, seq(0, 1, 0.01)[c(1, 51:61, 101)],
                     integers = "random", n_replicates = 1)
#> 0 0 0 100 0 0 0 0 0 0 0 0
  • get_type() uses a relative tolerance, so continuous samples around 1e8 are classified as integer and bias_sample() uses the integer formula (bias_sample(1e8 + 0.5, matrix(1e8 + runif(200), 1)) is about 0.5 rather than about 0). Values above 2^31 warn ("NAs introduced by coercion to integer range"). Suggestion: all(x == round(x)).
  • interval_coverage() returns logical(0) for interval ranges that are not round numbers, e.g. interval_range = 100 / 3 with levels 1/3 and 2/3, because one comparison is rounded and the other is not.
  • NA in quantile_level is accepted and handled differently by each metric (quantile_score() gives NA, bias_quantile() a value, wis() an error).
  • logs_binary() loses precision: -log(1 - abs(observed - predicted)) returns Inf for p = 1e-17 where 39.1 is correct.
  • na.rm is inconsistent: wis() defaults to FALSE, bias_quantile() to TRUE, other quantile metrics have no such argument; sample metrics differ in whether NA errors, gives NA, or is dropped.
  • Point metrics are unvalidated anonymous functions with the argument actual instead of observed; inputs recycle silently.
  • pit_histogram_sample() barely validates n_replicates and quantiles.
  • The default sample metrics include log_score, which warns for every integer-valued data set, including example_sample_discrete.
  • Binary metrics return a matrix when predicted is an n x 1 matrix.

Found during a full review of the package (version 2.3.0.9000, main at 779d7d68).

Dominant language
R
Stars
67
Forks
24
Avg merge
1h 24m
Merged PRs (30d)
2

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from epiforecasts/scoringutils

All issues in epiforecasts/scoringutils

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.