Skip to contents

This is a helper function which allows users to filter datasets by reference date. This is useful, for example, when evaluating nowcast performance against fully observed data. Users may wish to combine this function with enw_filter_report_dates(). Note that by definition it is assumed that a report date for a given reference date must be the equal or greater (i.e a report cannot happen before the event being reported occurs). This means that this function will also filter report dates earlier than the target reference dates.

Usage

enw_filter_reference_dates(
  obs,
  earliest_date,
  include_days,
  latest_date,
  remove_days
)

Arguments

obs

An data.frame; must have report_date and reference_date columns.

earliest_date

earliest reference date to include in the data set

include_days

if earilest_date is not given, the number of reference dates to include, ending with the latest reference date included once report dates have been removed. If specified this is indexed to latest_date or remove_days.

latest_date

Date, the latest reference date to include in the returned dataset.

remove_days

Integer, if latest_date is not given, the number of reference dates to remove, starting from the latest date included.

Value

A data.table filtered by report date

Examples

# Filter by date
enw_filter_reference_dates(
  germany_covid19_hosp,
  earliest_date = "2021-09-01",
  latest_date = "2021-10-01"
)
#>         reference_date location age_group confirm report_date
#>      1:     2021-09-01       DE       00+     124  2021-09-01
#>      2:     2021-09-02       DE       00+      94  2021-09-02
#>      3:     2021-09-03       DE       00+     130  2021-09-03
#>      4:     2021-09-04       DE       00+      82  2021-09-04
#>      5:     2021-09-05       DE       00+      42  2021-09-05
#>     ---                                                      
#> 129111:     2021-09-01    DE-TH     05-14       0  2021-10-20
#> 129112:     2021-09-01    DE-TH     15-34       0  2021-10-20
#> 129113:     2021-09-01    DE-TH     35-59       1  2021-10-20
#> 129114:     2021-09-01    DE-TH     60-79       2  2021-10-20
#> 129115:     2021-09-01    DE-TH       80+       2  2021-10-20
#
# Filter by days
enw_filter_reference_dates(
  germany_covid19_hosp,
  include_days = 10, remove_days = 10
)
#>        reference_date location age_group confirm report_date
#>     1:     2021-09-30       DE       00+     110  2021-09-30
#>     2:     2021-10-01       DE       00+     105  2021-10-01
#>     3:     2021-10-02       DE       00+      97  2021-10-02
#>     4:     2021-10-03       DE       00+      41  2021-10-03
#>     5:     2021-10-04       DE       00+      23  2021-10-04
#>    ---                                                      
#> 20940:     2021-09-30    DE-TH     05-14       1  2021-10-20
#> 20941:     2021-09-30    DE-TH     15-34       2  2021-10-20
#> 20942:     2021-09-30    DE-TH     35-59       6  2021-10-20
#> 20943:     2021-09-30    DE-TH     60-79       4  2021-10-20
#> 20944:     2021-09-30    DE-TH       80+      10  2021-10-20