Add conversion methods between multivariate and univariate forecast types

Open
#1,119 2 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@seabbs is already working on this.

Since Mar 9, 2026.

Assessment

This issue has not been assessed yet.

Description

enhancement

Summary

There are no dedicated conversion methods between multivariate and univariate forecast types. Some conversions already work via default methods, but others need new methods.

What already works

Promoting univariate to multivariate works via the .default constructors:

  • as_forecast_multivariate_sample(forecast_sample_obj, joint_across = "location") works because the .default method calls as_forecast_generic() which strips/rebuilds the object, then ensure_mv_grouping() adds .mv_group_id.
  • as_forecast_multivariate_point(forecast_point_obj, joint_across = "location") works the same way.

Existing univariate conversions for reference:

  • as_forecast_quantile.forecast_sample converts samples to quantiles
  • as_forecast_point.forecast_quantile extracts the median as a point forecast

No new methods needed for the promotion cases.

What needs new methods

as_forecast_multivariate_point.forecast_multivariate_sample

Summarise samples to multivariate point predictions (e.g. via mean or median per forecast unit). Should follow the as_forecast_point.forecast_quantile pattern:

  1. Assert input is valid multivariate sample
  2. Aggregate predicted values per forecast unit (configurable summary function, default mean)
  3. Remove sample_id column
  4. Preserve .mv_group_id and grouping structure
  5. Return forecast_multivariate_point object
as_forecast_point.forecast_multivariate_sample

Same as above but also drops the multivariate grouping:

  1. Aggregate predicted values per forecast unit
  2. Remove sample_id and .mv_group_id columns
  3. Return forecast_point object

Could be implemented as: convert to multivariate point first, then drop grouping. Or directly in one step.

as_forecast_point.forecast_multivariate_point

Downgrade by stripping multivariate grouping:

  1. Remove .mv_group_id column
  2. Return forecast_point object
as_forecast_quantile.forecast_multivariate_sample

Analogous to the existing as_forecast_quantile.forecast_sample but drops the multivariate grouping. Could delegate to the existing sample-to-quantile method after stripping .mv_group_id.

References

  • #1114 (variogram score for multivariate sample)
  • #1115 (multivariate point class)
  • as_forecast_point.forecast_quantile in R/class-forecast-quantile.R for the conversion pattern
  • as_forecast_quantile.forecast_sample in R/class-forecast-sample.R for the sample-to-quantile pattern

This was opened by a bot. Please ping @seabbs for any questions.

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.