Skip to contents

Transform data from a format that is based on predictive samples to a format based on plain quantiles.

Usage

sample_to_quantile(
  forecast,
  quantile_level = c(0.05, 0.25, 0.5, 0.75, 0.95),
  type = 7
)

Arguments

forecast

A forecast object of class forecast_sample (a validated data.table with predicted and observed values, see as_forecast()).

quantile_level

A numeric vector of quantile levels for which quantiles will be computed.

type

Type argument passed down to the quantile function. For more information, see quantile().

Value

a data.table in a long interval range format

Examples

library(magrittr) # pipe operator
example_sample_discrete %>%
  as_forecast_sample() %>%
  sample_to_quantile()
#>  Some rows containing NA values may be removed. This is fine if not
#>   unexpected.
#>  Some rows containing NA values may be removed. This is fine if not
#>   unexpected.
#> Forecast type: quantile
#> Forecast unit:
#> location, location_name, target_end_date, target_type, forecast_date, model,
#> and horizon
#> 
#>       location location_name target_end_date target_type forecast_date
#>         <char>        <char>          <Date>      <char>        <Date>
#>    1:       DE       Germany      2021-01-02       Cases          <NA>
#>    2:       DE       Germany      2021-01-02       Cases          <NA>
#>    3:       DE       Germany      2021-01-02       Cases          <NA>
#>    4:       DE       Germany      2021-01-02       Cases          <NA>
#>    5:       DE       Germany      2021-01-02       Cases          <NA>
#>   ---                                                                 
#> 5151:       IT         Italy      2021-07-24      Deaths    2021-07-12
#> 5152:       IT         Italy      2021-07-24      Deaths    2021-07-12
#> 5153:       IT         Italy      2021-07-24      Deaths    2021-07-12
#> 5154:       IT         Italy      2021-07-24      Deaths    2021-07-12
#> 5155:       IT         Italy      2021-07-24      Deaths    2021-07-12
#>                      model horizon observed quantile_level predicted
#>                     <char>   <num>    <num>          <num>     <num>
#>    1:                 <NA>      NA   127300           0.05        NA
#>    2:                 <NA>      NA   127300           0.25        NA
#>    3:                 <NA>      NA   127300           0.50        NA
#>    4:                 <NA>      NA   127300           0.75        NA
#>    5:                 <NA>      NA   127300           0.95        NA
#>   ---                                                               
#> 5151: epiforecasts-EpiNow2       2       78           0.05     44.90
#> 5152: epiforecasts-EpiNow2       2       78           0.25     89.25
#> 5153: epiforecasts-EpiNow2       2       78           0.50    151.50
#> 5154: epiforecasts-EpiNow2       2       78           0.75    208.00
#> 5155: epiforecasts-EpiNow2       2       78           0.95    469.10