Skip to contents

Sets the window the ES indicators are computed over. The window ends on the last day of the month in which es_complete_end() falls, and starts window_months - 1 months before that month, so it spans window_months whole collection months. Running the window to as_of instead would count samples still at the laboratory as if they had no enterovirus.

Usage

es_reporting_window(
  samples,
  as_of = Sys.Date(),
  window_months = 12L,
  resolved_min = 0.8,
  settle_months = 3L,
  cols = list()
)

Arguments

samples

Cleaned environmental samples, one row per sample, as returned by clean_es().

as_of

The reporting date, as a Date or a string that as.Date() reads. Defaults to Sys.Date(). Samples collected after it, or with no collection date, are left out.

window_months

Number of collection months in the window. Default 12.

resolved_min

Share of a month's samples that must be resolved for the month to count as complete. Default 0.80.

settle_months

Number of months after which a month still below resolved_min is taken as final. Default 3.

cols

Named list overriding the default column names, keyed by table, in the same shape as in calc_polio_indicators(), for example list(samples = list(vtype = "virus_type")). The samples defaults are the polished ES columns, with site_name = "site_name", plus vtype = "vtype", site_guid = "site_guid", longitude = "site_x_coordinate", latitude = "site_y_coordinate" and district_key = "adm2_guid", the column samples are counted by district on.

Value

A one-row tibble with window_start, window_end, last_month (the first day of the last month in the window) and lag_months (how many whole months the last month in the window sits behind the month of as_of). Pass window_start and window_end as from and to to calc_es_district_performance() or calc_es_site_performance().

Examples

es <- tibble::tibble(
  collection_date = as.Date(c("2024-01-05", "2024-02-03", "2024-03-10")),
  classification_all = c("NPEV", "NEGATIVE", NA)
)
es_reporting_window(es, as_of = as.Date("2024-03-20"), window_months = 2)
#> # A tibble: 1 × 4
#>   window_start window_end last_month lag_months
#>   <date>       <date>     <date>          <int>
#> 1 2024-01-01   2024-02-29 2024-02-01          1