create_shifted_cases: Create Delay Shifted Cases

create_shifted_casesR Documentation

Create Delay Shifted Cases

Description

[Stable]

This functions creates a data frame of reported cases that has been smoothed using a centred partial rolling average (with a period set by smoothing_window) and shifted back in time by some delay. It is used by estimate_infections() to generate the mean shifted prior on which the back calculation method (see backcalc_opts()) is based.

Usage

create_shifted_cases(data, shift, smoothing_window, horizon)

Arguments

data

A ⁠<data.frame>⁠ of confirmed cases (confirm) by date (date). confirm must be numeric and date must be in date format.

shift

Numeric, mean delay shift to apply.

smoothing_window

Numeric, the rolling average smoothing window to apply. Must be odd in order to be defined as a centred average.

horizon

Numeric, defaults to 7. Number of days into the future to forecast.

Details

The function first shifts all the data back in time by shift days (thus discarding the first shift days of data) and then applies a centred rolling mean of length smoothing_window to the shifted data except for the final period. The final period (the forecast horizon plus half the smoothing window) is instead replaced by a log-linear model fit (with 1 added to the data for fitting to avoid zeroes and later subtracted again), projected to the end of the forecast horizon. The initial part of the data (corresponding to the length of the smoothing window) is then removed, and any non-integer resulting values rounded up.

Value

A ⁠<data.frame>⁠ for shifted reported cases

Examples

## Not run: 
shift <- 7
horizon <- 7
smoothing_window <- 14
## add NAs for horizon
cases <- create_clean_reported_cases(example_confirmed, horizon = horizon)
## add zeroes initially
cases <- data.table::rbindlist(list(
   data.table::data.table(
     date = seq(
       min(cases$date) - smoothing_window,
       min(cases$date) - 1,
       by = "days"
     ),
     confirm = 0, breakpoint = 0
   ),
   cases
 ))
create_shifted_cases(cases, shift, smoothing_window, horizon)

## End(Not run)

EpiNow2 documentation built on Oct. 31, 2024, 5:09 p.m.