Skip to contents

Expects a hubverse-format quantile table (e.g. as created by get_hubverse_quantile_table()). Treats all columns in that table other than output_type_id, output_type, and value as grouping / id columns, and returns them in the output table.

Usage

hub_quantiles_to_median_qi(
  hubverse_quantile_table,
  .width = NULL,
  require_only_quantiles = TRUE,
  require_all_medians = TRUE,
  require_all_widths = TRUE,
  quantile_tol = 10
)

Arguments

hubverse_quantile_table

Hubverse-format quantile table, as an object something coerceible to a tibble.

.width

Vector of interval width(s) to for which to create rows in the output. If NULL (the default), use all and only the widths that can be computed from quantiles available in hubverse_quantile_table, as determined by get_available_qi_widths.

require_only_quantiles

Boolean. Error if the table contains output_type values other than "quantile"? If FALSE, the function will silently filter the table to rows with output_type == 'quantile'. Default TRUE.

require_all_medians

Boolean. Error if the output is missing any medians? If TRUE, the function will succeed if it can find a median (0.5 quantile) value for all groups present in the input and otherwise will error. Default TRUE.

require_all_widths

Boolean. Error if the output is missing any of the requested .widths for any group? If TRUE, the function will succeed if it can calculate all the requested interval .widths for all the groups present in the input and otherwise will error. Default TRUE.

quantile_tol

Round quantile level values to this many decimal places, to avoid problems with floating point number equality comparisons. Passed as the digits argument to base::round(). Default 10.

Value

A tibble in the output format of ggdist::median_qi() added.

Examples

hub_quantiles_to_median_qi(
  hubExamples::forecast_outputs |>
    dplyr::filter(.data$output_type == "quantile"),
  .width = c(0.5, 0.8)
)
#> # A tibble: 96 × 12
#>    model_id  reference_date target horizon location target_end_date value .lower
#>    <chr>     <date>         <chr>    <int> <chr>    <date>          <dbl>  <dbl>
#>  1 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     45
#>  2 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     31
#>  3 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052   1032
#>  4 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052    958
#>  5 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51     38
#>  6 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51     21
#>  7 Flusight… 2022-11-19     wk in…       1 48       2022-11-26       1052   1007
#>  8 Flusight… 2022-11-19     wk in…       1 48       2022-11-26       1052    915
#>  9 Flusight… 2022-11-19     wk in…       2 25       2022-12-03         51     33
#> 10 Flusight… 2022-11-19     wk in…       2 25       2022-12-03         51     12
#> # ℹ 86 more rows
#> # ℹ 4 more variables: .upper <dbl>, .width <dbl>, .point <chr>, .interval <chr>

hub_quantiles_to_median_qi(hubExamples::forecast_outputs,
  .width = c(0.5),
  require_only_quantiles = FALSE
)
#> # A tibble: 48 × 12
#>    model_id  reference_date target horizon location target_end_date value .lower
#>    <chr>     <date>         <chr>    <int> <chr>    <date>          <dbl>  <dbl>
#>  1 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     45
#>  2 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052   1032
#>  3 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51     38
#>  4 Flusight… 2022-11-19     wk in…       1 48       2022-11-26       1052   1007
#>  5 Flusight… 2022-11-19     wk in…       2 25       2022-12-03         51     33
#>  6 Flusight… 2022-11-19     wk in…       2 48       2022-12-03       1052    980
#>  7 Flusight… 2022-11-19     wk in…       3 25       2022-12-10         51     29
#>  8 Flusight… 2022-11-19     wk in…       3 48       2022-12-10       1052    961
#>  9 Flusight… 2022-12-17     wk in…       0 25       2022-12-17        582    575
#> 10 Flusight… 2022-12-17     wk in…       0 48       2022-12-17       1791   1765
#> # ℹ 38 more rows
#> # ℹ 4 more variables: .upper <dbl>, .width <dbl>, .point <chr>, .interval <chr>

hub_quantiles_to_median_qi(hubExamples::forecast_outputs,
  require_only_quantiles = FALSE,
  require_all_widths = FALSE
)
#> # A tibble: 144 × 12
#>    model_id  reference_date target horizon location target_end_date value .lower
#>    <chr>     <date>         <chr>    <int> <chr>    <date>          <dbl>  <dbl>
#>  1 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     45
#>  2 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     31
#>  3 Flusight… 2022-11-19     wk in…       0 25       2022-11-19         51     22
#>  4 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052   1032
#>  5 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052    958
#>  6 Flusight… 2022-11-19     wk in…       0 48       2022-11-19       1052    905
#>  7 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51     38
#>  8 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51     21
#>  9 Flusight… 2022-11-19     wk in…       1 25       2022-11-26         51      5
#> 10 Flusight… 2022-11-19     wk in…       1 48       2022-11-26       1052   1007
#> # ℹ 134 more rows
#> # ℹ 4 more variables: .upper <dbl>, .width <dbl>, .point <chr>, .interval <chr>