adjust_infection_to_report: Adjust from Case Counts by Infection Date to Date of Report

View source: R/adjust.R

adjust_infection_to_reportR Documentation

Adjust from Case Counts by Infection Date to Date of Report

Description

[Deprecated] Maps from cases by date of infection to date of report via date of onset.

Usage

adjust_infection_to_report(
  infections,
  delay_defs,
  reporting_model,
  reporting_effect,
  type = "sample",
  truncate_future = TRUE
)

Arguments

infections

⁠<data.table>⁠ containing a date variable and a numeric cases variable.

delay_defs

A list of single row data.tables that each defines a delay distribution (model, parameters and maximum delay for each model). See lognorm_dist_def() for an example of the structure.

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.

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.

type

Character string indicating the method to use to transform counts. Supports either "sample" which approximates sampling or "median" would shift by the median of the distribution.

truncate_future

Logical, should cases be truncated if they occur after the first date reported in the data. Defaults to TRUE.

Value

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.

Examples


# This function is deprecated and its functionality can now be accessed
# from [simulate_secondary()].
# Here are some examples of how to use [simulate_secondary()] to replace
# adjust_infection_to_report().

# Old (using adjust_infection_to_report()):
# Define example case data
cases <- data.table::copy(example_confirmed)
cases <- cases[, cases := as.integer(confirm)]
# Define a simple reporting delay distribution
delay_def <- lognorm_dist_def(
 mean = 5, mean_sd = 1, sd = 3, sd_sd = 1,
 max_value = 30, samples = 1, to_log = TRUE
)
report <- adjust_infection_to_report(
 cases,
 delay_defs = list(delay_def),
 reporting_model = function(n) rpois(length(n), n)
)
print(report)

# New (using simulate_secondary()):
cases <- data.table::copy(example_confirmed)
cases <- cases[, primary := as.integer(confirm)]
uncertain_delay <- LogNormal(
 mean = Normal(5, 1), sd = Normal(3, 1),
 max = 30
)
delay <- fix_dist(uncertain_delay, strategy = "sample")
report <- simulate_secondary(
 cases,
 delays = delay_opts(delay),
 obs = obs_opts(family = "poisson")
)
print(report)


epiforecasts/EpiNow2 documentation built on April 27, 2024, 9:15 p.m.