Expose forecast counts aligned to summarize_scores() grouping?

Open
#1,220 3 comments 3 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
r
Domain
data

Research direction

Start with the summarize_scores() and get_forecast_unit() entry points, then compare the reference implementation in hubverse-org/hubEvals#145 and the use case in hubPredEvalsData#19. Clarify whether a summary-aligned count should be an opt-in API, how it interacts with metrics attributes and forecast-unit detection, and what tests would define the accepted behavior.

Written by the indexing model from the issue text.

Description

Context

In hubEvals we've added an opt-in argument to our score_model_out() wrapper that appends a count column to summarised scores: the number of forecasts scored in each summary group. It's useful context (it shows how much data each summarised mean rests on, and surfaces sparse or uneven coverage across models/groups), and hubPredEvalsData (which prepares the per-model data behind the hubverse evaluation dashboards) needs it to report the number of predictions scored per model (hubverse-org/hubPredEvalsData#19).

The gap

scoringutils already counts forecasts via get_forecast_counts(), which operates on the forecast object and returns a count column (de-duplicating over quantile_level / sample_id). But summarize_scores() exposes no count aligned to its by grouping. So to attach "number scored per summary group" we count the per-row scores before summarize_scores() collapses them, then join it back:

counts <- dplyr::count(scores, dplyr::across(dplyr::all_of(by)))
summ   <- summarize_scores(scores, by = by)
summ   <- dplyr::left_join(summ, counts, by = by)  # + restore the `metrics` attribute

Question

Would you consider exposing a group count from summarize_scores() natively, e.g. an opt-in argument that also returns the group size alongside the summarised metrics? Or is there a recommended pattern we've missed? We appreciate that the design deliberately keeps counting on the forecast side (get_forecast_counts()), so we're really asking whether a summary-aligned count belongs in scoringutils or is better left to callers.

An extra reason it might belong upstream

Appending a count column onto a scores object downstream interacts awkwardly with get_forecast_unit(), which derives the forecast unit by elimination (any column that isn't protected or a listed metric is treated as a task-ID). A bolted-on count column is therefore misclassified as a forecast-unit column, which would skew the guards in get_pairwise_comparisons() / add_relative_skill() if such an object were routed back through them. If scoringutils owned the count column, it could protect the name in its class machinery and avoid this downstream footgun.

Reference implementation: hubverse-org/hubEvals#145.

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.