`get_pit_histogram()` for quantile forecasts is wrong when forecasts have different quantile levels

Open
#1,261 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
data

Research direction

Start with get_pit_histogram.forecast_quantile() in R/class-forecast-quantile.R and trace how it builds bins and computes densities for each by group. Reproduce the example with models A and B, then check that groups with different quantile levels produce valid bins and densities. Done means B's histogram has four bins with densities 1, 1, 0, and 2, or the function aborts with a clear message when requested breaks are missing.

Written by the indexing model from the issue text.

Description

CLAUDE: The bins are built from the union of the quantile levels in the whole data set, but the densities are computed per by group from that group's own levels. A group with fewer quantile levels gets its densities recycled across the wrong bins. The only hint is a base R "longer object length" warning.

library(scoringutils); library(data.table)
ql <- c(0.1, 0.25, 0.5, 0.75, 0.9)
d <- data.table(model = "A", id = rep(1:4, each = 5), quantile_level = rep(ql, 4),
                observed = rep(c(5, 1.5, 3, 10), each = 5), predicted = rep(1:5, 4))
d2 <- rbind(d, d[quantile_level %in% c(0.25, 0.5, 0.75)][, model := "B"])
get_pit_histogram(as_forecast_quantile(d2), by = "model")[model == "B"]
#> 6 bins with densities 2.5 1.67 0 2.0 1.67 2.5
#> correct for B: 4 bins [0,0.25) [0.25,0.5) [0.5,0.75) [0.75,1) with densities 1 1 0 2

Location: get_pit_histogram.forecast_quantile() in R/class-forecast-quantile.R. PR #1244 does not change this.

Suggested fix: require every group to contain all requested breaks (abort with a clear message otherwise), or compute the bins per group.

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.