Skip to contents

[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

# \donttest{
# 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
)
#> Warning: `lognorm_dist_def()` was deprecated in EpiNow2 1.5.0.
#>  Please use `LogNormal()` instead.
#>  The function will be removed completely in version 2.0.0.
report <- adjust_infection_to_report(
 cases,
 delay_defs = list(delay_def),
 reporting_model = function(n) rpois(length(n), n)
)
#> Warning: `adjust_infection_to_report()` was deprecated in EpiNow2 1.5.0.
#>  Please use `simulate_secondary()` instead.
#>  See equivalent examples using `simulate_secondary()`
#>  in ?adjust_infection_to_report.
#>  This function will be removed completely in version 2.0.0.
#> Warning: The `delay_defs` argument of `adjust_infection_to_report()` should be a
#> dist_spec as of EpiNow2 1.5.0.
#>  Specifying this as a list of data tables is deprecated.
print(report)
#>            date cases
#>          <Date> <int>
#>   1: 2020-02-23     5
#>   2: 2020-02-24    28
#>   3: 2020-02-25    41
#>   4: 2020-02-26    39
#>   5: 2020-02-27    53
#>  ---                 
#> 125: 2020-06-26   313
#> 126: 2020-06-27   315
#> 127: 2020-06-28   256
#> 128: 2020-06-29   272
#> 129: 2020-06-30   211

# 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
)
#> Warning: Uncertain lognormal distribution specified in terms of parameters that are not the "natural" parameters of the distribution (meanlog, sdlog). Converting using a crude and very approximate method that is likely to produce biased results. If possible, it is preferable to specify the distribution directly in terms of the natural parameters.
delay <- fix_dist(uncertain_delay, strategy = "sample")
report <- simulate_secondary(
 cases,
 delays = delay_opts(delay),
 obs = obs_opts(family = "poisson")
)
print(report)
#>       date.date secondary
#>          <Date>     <num>
#>   1: 2020-02-22         0
#>   2: 2020-02-23         2
#>   3: 2020-02-24         9
#>   4: 2020-02-25        31
#>   5: 2020-02-26        58
#>  ---                     
#> 126: 2020-06-26       210
#> 127: 2020-06-27       354
#> 128: 2020-06-28       381
#> 129: 2020-06-29       279
#> 130: 2020-06-30       212
# }