The function more or less provides a wrapper around merge
that
aims to handle the merging well if additional columns are present
in one or both data sets. If in doubt, you should probably merge the
data sets manually.
Usage
merge_pred_and_obs(
forecasts,
observations,
join = c("left", "full", "right"),
by = NULL
)
Arguments
- forecasts
data.frame with the forecast data (as can be passed to
score()
).- observations
data.frame with the observations
- join
character, one of
c("left", "full", "right")
. Determines the type of the join. Usually, a left join is appropriate, but sometimes you may want to do a full join to keep dates for which there is a forecast, but no ground truth data.- by
character vector that denotes the columns by which to merge. Any value that is not a column in observations will be removed.
Examples
forecasts <- example_quantile_forecasts_only
observations <- example_truth_only
merge_pred_and_obs(forecasts, observations)
#> location target_end_date target_type true_value location_name
#> 1: DE 2021-01-02 Cases 127300 Germany
#> 2: DE 2021-01-02 Deaths 4534 Germany
#> 3: DE 2021-01-09 Cases 154922 Germany
#> 4: DE 2021-01-09 Deaths 6117 Germany
#> 5: DE 2021-01-16 Cases 110183 Germany
#> ---
#> 20541: IT 2021-07-24 Deaths 78 Italy
#> 20542: IT 2021-07-24 Deaths 78 Italy
#> 20543: IT 2021-07-24 Deaths 78 Italy
#> 20544: IT 2021-07-24 Deaths 78 Italy
#> 20545: IT 2021-07-24 Deaths 78 Italy
#> forecast_date quantile prediction model horizon
#> 1: <NA> NA NA <NA> NA
#> 2: <NA> NA NA <NA> NA
#> 3: <NA> NA NA <NA> NA
#> 4: <NA> NA NA <NA> NA
#> 5: <NA> NA NA <NA> NA
#> ---
#> 20541: 2021-07-12 0.850 352 epiforecasts-EpiNow2 2
#> 20542: 2021-07-12 0.900 397 epiforecasts-EpiNow2 2
#> 20543: 2021-07-12 0.950 499 epiforecasts-EpiNow2 2
#> 20544: 2021-07-12 0.975 611 epiforecasts-EpiNow2 2
#> 20545: 2021-07-12 0.990 719 epiforecasts-EpiNow2 2