Description Usage Arguments Value Examples
Stochastic mapping from cases by date of infection to date of report via date of
onset. Essentially reversal of nowcast_pipeline
.
1 2 3 4 5 6 7 8 9 10 | adjust_infection_to_report(
infections,
delay_def,
incubation_def,
reporting_effect,
reporting_model,
type = "sample",
return_onset = FALSE,
truncate_future = TRUE
)
|
infections |
|
delay_def |
A single row data.table that defines the delay distribution (model, parameters and maximum delay for each model).
See |
incubation_def |
A single row data.table that defines the incubation distribution (model, parameters and maximum delay for each model).
See |
reporting_effect |
A numeric vector of length 7 that allows the scaling of reported cases by the day on which they report (1 = Monday, 7 = Sunday). By default no scaling occurs. |
reporting_model |
A function that takes a single numeric vector as an argument and returns a single numeric vector. Can be used to apply stochastic reporting effects. See the examples for details. |
type |
Character string indicating the method to use to transfrom counts. Supports either "sample" which approximates sampling or "median" would shift by the median of the distribution. |
return_onset |
Logical, defaults to |
truncate_future |
Logical, should cases be truncted if they occur after the first date reported in the data.
Defaults to |
A data.table
containing a date
variable (date of report) and a cases
variable. If return_onset = TRUE
there will be
a third variable reference
which indicates what the date variable refers to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ## Define example cases
cases <- data.table::as.data.table(EpiSoon::example_obs_cases)
cases <- cases[, `:=`(confirm = as.integer(cases), import_status = "local")]
## Define a single report delay distribution
delay_def <- EpiNow::lognorm_dist_def(mean = 5,
mean_sd = 1,
sd = 3,
sd_sd = 1,
max_value = 30,
samples = 1,
to_log = TRUE)
## Define a single incubation period
incubation_def <- EpiNow::lognorm_dist_def(mean = EpiNow::covid_incubation_period[1, ]$mean,
mean_sd = EpiNow::covid_incubation_period[1, ]$mean_sd,
sd = EpiNow::covid_incubation_period[1, ]$sd,
sd_sd = EpiNow::covid_incubation_period[1, ]$sd_sd,
max_value = 30, samples = 1)
## Perform a nowcast
nowcast <- nowcast_pipeline(reported_cases = cases,
target_date = max(cases$date),
delay_defs = delay_def,
incubation_defs = incubation_def)
infections <- nowcast[type %in% "infection_upscaled" & import_status %in% "local"]
infections <- infections[, `:=`(type = NULL, import_status = NULL)]
## Simple mapping
report <- adjust_infection_to_report(infections, delay_def, incubation_def)
print(report)
## Mapping with a weekly reporting effect
report_weekly <- adjust_infection_to_report(
infections, delay_def, incubation_def,
reporting_effect = c(1.1, rep(1, 4), 0.95, 0.95))
print(report_weekly)
## Map using a deterministic median shift for both delays
report_median <- adjust_infection_to_report(infections, delay_def,
incubation_def, type = "median")
## Map with a weekly reporting effect and stochastic reporting model
report_stochastic <- adjust_infection_to_report(
infections, delay_def, incubation_def,
reporting_effect = c(1.1, rep(1, 4), 0.95, 0.95),
reporting_model = function(n) {
out <- suppressWarnings(rnbinom(length(n), as.integer(n), 0.5))
out <- ifelse(is.na(out), 0, out)
})
print(report_stochastic)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.