convolve_and_scale function

Convolve and scale a time series

Convolve and scale a time series

This applies a lognormal convolution with given, potentially time-varying parameters representing the parameters of the lognormal distribution used for the convolution and an optional scaling factor. This is akin to the model used in estimate_secondary() and simulate_secondary().

convolve_and_scale( data, type = c("incidence", "prevalence"), family = c("none", "poisson", "negbin"), delay_max = 30, ... )

Arguments

  • data: A <data.frame> containing the date of report and primary

    cases as a numeric vector.

  • type: A character string indicating the type of observation the secondary reports are. Options include:

    • "incidence": Assumes that secondary reports equal a convolution of previously observed primary reported cases. An example application is deaths from an infectious disease predicted by reported cases of that disease (or estimated infections).
    • "prevalence": Assumes that secondary reports are cumulative and are defined by currently observed primary reports minus a convolution of secondary reports. An example application is hospital bed usage predicted by hospital admissions.
  • family: Character string defining the observation model. Options are Negative binomial ("negbin"), the default, Poisson ("poisson"), and "none" meaning the expectation is returned.

  • delay_max: Integer, defaulting to 30 days. The maximum delay used in the convolution model.

  • ...: Additional parameters to pass to the observation model (i.e rnbinom or rpois).

Returns

A <data.frame> containing simulated data in the format required by estimate_secondary().

Details

Up to version 1.4.0 this function was called simulate_secondary().

Examples

# load data.table for manipulation library(data.table) #### Incidence data example #### # make some example secondary incidence data cases <- example_confirmed cases <- as.data.table(cases)[, primary := confirm] # Assume that only 40 percent of cases are reported cases[, scaling := 0.4] # Parameters of the assumed log normal delay distribution cases[, meanlog := 1.8][, sdlog := 0.5] # Simulate secondary cases cases <- convolve_and_scale(cases, type = "incidence") cases #### Prevalence data example #### # make some example prevalence data cases <- example_confirmed cases <- as.data.table(cases)[, primary := confirm] # Assume that only 30 percent of cases are reported cases[, scaling := 0.3] # Parameters of the assumed log normal delay distribution cases[, meanlog := 1.6][, sdlog := 0.8] # Simulate secondary cases cases <- convolve_and_scale(cases, type = "prevalence") cases

See Also

estimate_secondary