nowcast_pipeline: Impute Cases Date of Infection

Description Usage Arguments Value Examples

View source: R/nowcast_pipeline.R

Description

Impute Cases Date of Infection

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## 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

epiforecasts/EpiNow documentation built on Oct. 26, 2020, 2:38 p.m.