modify_reference_date
applies an arbitrary transformation to the
reference_date of a hubverse table and recomputes the horizon, based on the
new reference_date and existing target_end_date
. A new unit for the horizon
can also be specified.
Usage
modify_reference_date(
original_hub_tbl,
horizon_timescale = NULL,
reference_date_transform = identity,
reference_date_col = "reference_date",
target_end_date_col = "target_end_date",
horizon_col = "horizon",
horizon_timescale_col = "horizon_timescale"
)
Arguments
- original_hub_tbl
A data frame containing the hub table.
- horizon_timescale
The timescale for the horizon. Must be a valid argument to
horizons_from_target_end_dates()
. IfNULL
, the horizon fromhorizon_timescale_col
is used.- reference_date_transform
A function to transform the reference date. Default is
identity
.- reference_date_col
The name of the reference date column. Default is "reference_date".
- target_end_date_col
The name of the target end date column. Default is "target_end_date".
- horizon_col
The name of the horizon column. Default is "horizon".
- horizon_timescale_col
The name of the horizon timescale column. Default is "horizon_timescale".
Examples
example_daily_forecast_flu |>
trajectories_to_quantiles(
id_cols = "location",
timepoint_col = "date",
value_col = "hosp"
) |>
dplyr::rename(target_end_date = date) |>
get_hubverse_quantile_table(
reference_date = as.Date("2023-10-20"),
horizon_timescale = "weeks",
target_name = "my_target",
timepoint_col = "target_end_date",
horizons = 1:4
) |>
modify_reference_date(\(x) x - 1, horizon_timescale = "days")
#> # A tibble: 4,876 × 9
#> reference_date target horizon horizon_timescale target_end_date location
#> <date> <chr> <dbl> <chr> <date> <chr>
#> 1 2023-10-19 my_target 8 days 2023-10-27 AK
#> 2 2023-10-19 my_target 8 days 2023-10-27 AK
#> 3 2023-10-19 my_target 8 days 2023-10-27 AK
#> 4 2023-10-19 my_target 8 days 2023-10-27 AK
#> 5 2023-10-19 my_target 8 days 2023-10-27 AK
#> 6 2023-10-19 my_target 8 days 2023-10-27 AK
#> 7 2023-10-19 my_target 8 days 2023-10-27 AK
#> 8 2023-10-19 my_target 8 days 2023-10-27 AK
#> 9 2023-10-19 my_target 8 days 2023-10-27 AK
#> 10 2023-10-19 my_target 8 days 2023-10-27 AK
#> # ℹ 4,866 more rows
#> # ℹ 3 more variables: output_type <chr>, output_type_id <dbl>, value <dbl>