Skip to content

Commit

Permalink
Merge pull request #960 from epiforecasts/cran-updates
Browse files Browse the repository at this point in the history
Cran updates
  • Loading branch information
nikosbosse authored Oct 31, 2024
2 parents c7df01c + 815c9ee commit dcabdfb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ of our [original](https://doi.org/10.48550/arXiv.2205.07090) `scoringutils` pape

### `score()`
- The main function of the package is still the function `score()`. However, we reworked the function and updated and clarified its input requirements.
- The previous columns "true_value" and "prediction" were renamed. `score()` now requires columns called "observed" and "predicted" and "model". The column `quantile` was renamed to `quantile_level` and `sample` was renamed to `sample_id`
- The previous columns "true_value" and "prediction" were renamed. `score()` now requires columns called "observed" and "predicted" (some functions still assume the existence of a `model` column as default but this is not a strict requirement). The column `quantile` was renamed to `quantile_level` and `sample` was renamed to `sample_id`
- `score()` is now a generic. It has S3 methods for the classes `forecast_point`, `forecast_binary`, `forecast_quantile`, `forecast_sample`, and `forecast_nominal`, which correspond to the different forecast types that can be scored with `scoringutils`.
- `score()` now calls `na.omit()` on the data, instead of only removing rows with missing values in the columns `observed` and `predicted`. This is because `NA` values in other columns can also mess up e.g. grouping of forecasts according to the unit of a single forecast.
- `score()` and many other functions now require a validated `forecast` object. `forecast` objects can be created using the functions `as_forecast_point()`, `as_forecast_binary()`, `as_forecast_quantile()`, and `as_forecast_sample()` (which replace the previous `check_forecast()`). A forecast object is a data.table with class `forecast` and an additional class corresponding to the forecast type (e.g. `forecast_quantile`).
Expand Down
5 changes: 4 additions & 1 deletion R/class-forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ assert_forecast.default <- function(
forecast, forecast_type = NULL, verbose = TRUE, ...
) {
cli_abort(
#nolint start: keyword_quote_linter
c(
"!" = "The input needs to be a valid forecast object.",
"i" = "Please convert to `forecast` object first (see {.fn as_forecast})." # nolint
"i" = "Please convert to `forecast` object first by calling the
appropriate {.fn as_forecast_<type>} function)."
)
#nolint end
)
}

Expand Down
5 changes: 4 additions & 1 deletion R/score.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ score <- function(forecast, metrics, ...) {
#' @export
score.default <- function(forecast, metrics, ...) {
cli_abort(
#nolint start: keyword_quote_linter
c(
"!" = "The input needs to be a valid forecast object.",
"i" = "Please convert to `forecast` object first (see {.fn as_forecast})." # nolint
"i" = "Please convert to `forecast` object first by calling the
appropriate {.fn as_forecast_<type>} function)."
)
#nolint end
)
}

Expand Down
5 changes: 3 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ remotes::install_github("epiforecasts/scoringutils", dependencies = TRUE)
- `point`: a forecast for a continuous or discrete outcome variable that is represented by a single number.
- `quantile`: a probabilistic forecast for a continuous or discrete outcome variable, with the forecast distribution represented by a set of predictive quantiles.
- `sample`: a probabilistic forecast for a continuous or discrete outcome variable, with the forecast represented by a finite set of samples drawn from the predictive distribution.
- `nominal` categorical forecast with unordered outcome possibilities (generalisation of binary forecasts to multiple outcomes)

### Input formats and input validation

The expected input format is generally a `data.frame` (or similar) with required columns `observed`, `predicted`, and `model` that holds the forecasts and observed values. Exact requirements depend on the forecast type. For more information, have a look at the [paper](https://drive.google.com/file/d/1URaMsXmHJ1twpLpMl1sl2HW4lPuUycoj/view?usp=drive_link), call `?as_forecast()`, or have a look at the example data provided in the package (`example_binary`, `example_point`, `example_quantile`, `example_sample_continuous`, `example_sample_discrete`).
The expected input format is generally a `data.frame` (or similar) with required columns `observed`, and `predicted` that holds the forecasts and observed values. Exact requirements depend on the forecast type. For more information, have a look at the [paper](https://drive.google.com/file/d/1URaMsXmHJ1twpLpMl1sl2HW4lPuUycoj/view?usp=drive_link), call `?as_forecast_binary`, `?as_forecast_quantile` etc., or have a look at the example data provided in the package (`example_binary`, `example_point`, `example_quantile`, `example_sample_continuous`, `example_sample_discrete`, `example_nominal`).

Before scoring, input data needs to be validated and transformed into a forecast object using the function `as_forecast()`.
Before scoring, input data needs to be validated and transformed into a forecast object using one of the `as_forecast_<type>()` functions.

```{r}
forecast_quantile <- example_quantile |>
Expand Down

0 comments on commit dcabdfb

Please sign in to comment.