Impute Cases Date of Infection

nowcast_pipeline(
  reported_cases = NULL,
  linelist = NULL,
  target_date = NULL,
  earliest_allowed_onset = NULL,
  merge_actual_onsets = FALSE,
  approx_delay = FALSE,
  max_delay = 120,
  verbose = FALSE,
  delay_defs = NULL,
  incubation_defs = NULL,
  nowcast_lag = 8,
  max_upscale = 5,
  onset_modifier = NULL
)

Arguments

reported_cases

A dataframe of reported cases

linelist

A linelist of report dates and onset dates

target_date

Character string, in the form "2020-01-01". Date to cast.

earliest_allowed_onset

A character string in the form of a date ("2020-01-01") indiciating the earliest allowed onset.

merge_actual_onsets

Logical, defaults to TRUE. Should linelist onset dates be used where available?

approx_delay

Logical, defaults to FALSE. Should delay sampling be approximated using case counts. Not appropriate when case numbers are low. Useful for high cases counts as decouples run time and resource usage from case count.

max_delay

Numeric, maximum delay to allow. Defaults to 120 days

verbose

Logical, defaults to FALSE. Should internal nowcasting progress messages be returned.

delay_defs

A data.table that defines the delay distributions (model, parameters and maximum delay for each model). See get_delay_dist for an example of the structure.

incubation_defs

A data.table that defines the incubation distributions (model, parameters and maximum delay for each model). See get_delay_dist for an example of the structure.

nowcast_lag

Numeric, defaults to 4. The number of days by which to lag nowcasts. Helps reduce bias due to case upscaling.

max_upscale

Numeric, maximum upscaling of cases allowed at each time point. Defaults to 100 times the observed cases.

onset_modifier

data.frame containing a date variable and a function modifier variable. This is used to modify estimated cases by onset date. modifier must be a function that returns a proportion when called (enables inclusion of uncertainty) and takes the following arguments: n (samples to return) and status ("local" or "import").

Value

A dataframe of nowcast cases from each step of the nowcasting process (defined by type).

Examples

## Construct example distributions ## reporting delay dist delay_dist <- suppressWarnings( EpiNow::get_dist_def(rexp(25, 1 / 10), samples = 1, bootstraps = 1)) ## incubation delay dist incubation_dist <- delay_dist ## Uses example case vector from EpiSoon cases <- data.table::setDT(EpiSoon::example_obs_cases) cases <- cases[, `:=`(confirm = as.integer(cases), import_status = "local")] ## Basic nowcast nowcast <- nowcast_pipeline(reported_cases = cases, target_date = max(cases$date), delay_defs = delay_dist, incubation_defs = incubation_dist) nowcast
#> sample date cases type import_status confidence #> 1: 1 2020-01-15 1 onset local 1.0000000 #> 2: 1 2020-01-16 0 onset local 1.0000000 #> 3: 1 2020-01-17 1 onset local 1.0000000 #> 4: 1 2020-01-18 0 onset local 1.0000000 #> 5: 1 2020-01-19 2 onset local 1.0000000 #> --- #> 254: 1 2020-03-10 332 infection_upscaled local 0.6480296 #> 255: 1 2020-03-11 293 infection_upscaled local 0.5988762 #> 256: 1 2020-03-12 328 infection_upscaled local 0.5466796 #> 257: 1 2020-03-13 367 infection_upscaled local 0.4916264 #> 258: 1 2020-03-14 318 infection_upscaled local 0.4340406