Skip to contents

Plot median predictions and prediction intervals against observed data by forecast date.

Usage

plot_pred_obs_by_forecast_date(
  scorable_table,
  horizons = NULL,
  prediction_interval_width = 0.95,
  forecast_date_col = "reference_date",
  target_date_col = "target_end_date",
  predicted_col = "predicted",
  observed_col = "observed",
  quantile_level_col = "quantile_level",
  horizon_col = "horizon",
  facet_columns = NULL,
  x_label = "Date",
  y_label = "Target",
  y_transform = "log10",
  quantile_tol = 10
)

Arguments

scorable_table

quantile table with observations, as the output of scoringutils::as_forecast_quantile(), or as a table coercible to a scoringutils-ready quantile forecast via scoringutils::as_forecast_quantile(). Must contain the median (0.5) quantile and the endpoint quantiles for the central prediction interval specified in prediction_interval_width.

horizons

Forecast horizons to plot. If NULL, plot all available horizons. Default NULL.

prediction_interval_width

Width of the (central) prediction interval to plot around the median. Must correspond to quantiles available in scorable_table. Default 0.95 (plot the range from quantile 0.025 to quantile 0.975).

forecast_date_col

Name of the column in scorable_table giving the forecast date or forecast reference date. Default "reference_date" (as in hubverse schema).

target_date_col

Name of the column in scorable_table giving the forecast target date for a given prediction. Default "target_end_date" (as in hubverse schema).

predicted_col

Name of the column in scorable_table giving the predicted values. Default "predicted" (as in the output of scoringutils::as_forecast_quantile(). Passed as the predicted argument to scoringutils::as_forecast_quantile().

observed_col

Name of the column in scorable_table giving the observed values. Default "observed" (as in the output of scoringutils::as_forecast_quantile(). Passed as the observed argument to scoringutils::as_forecast_quantile().

quantile_level_col

Name of the column in scorable_table giving the quantile level for a given row. Default "quantile_level" (as in the output of scoringutils::as_forecast_quantile(). Passed as the quantile_level argument to scoringutils::as_forecast_quantile().

horizon_col

Name of the column in scorable_table containing the forecast horizon for a given row. Default "horizon" (as in hubverse schema).

facet_columns

Columns in scorable_table by which to facet the resulting plot. Will always facet by forecast_date_col. If NULL, facet by all the columns that make up the scoringutils "forecast unit", as determined by scoringutils::get_forecast_unit(), except for target_date_col and horizon. This means that, by default, two distinct predictions for a given target date and horizon should not be visualized on the same facet. To facet only by the forecast date column, pass that column name again, or pass "".

x_label

Label for the x axis in the plot. Default "Date".

y_label

Label for the y axis in the plot. Default "Target".

y_transform

Transformation for the y axis in the plot. Passed as the transform argument to ggplot2::scale_y_continuous() Default "log10".

quantile_tol

Round quantile level values to this many decimal places, to avoid problems with floating point number equality comparisons. Affects both the target quantile level values determined from prediction_interval_width and the quantile level values in the quantile_level_col column of scorable_table. Passed as the digits argument to base::round(). Default 10.

Value

The plot, as a ggplot2::ggplot() object.

Examples

scoringutils::example_quantile |>
  dplyr::filter(
    location == "IT",
    target_type == "Cases",
    model == "EuroCOVIDhub-ensemble"
  ) |>
  plot_pred_obs_by_forecast_date(
    forecast_date_col = "forecast_date",
    facet_columns = "" # facet only by forecast date
  )