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.
Arguments
- data
A
<data.frame>
of confirmed cases (confirm) by date (date).confirm
must be numeric anddate
must be in date format. Optionally this can also have a logicalaccumulate
column which indicates whether data should be added to the next data point. This is useful when modelling e.g. weekly incidence data. See also thefill_missing()
function which helps add theaccumulate
column with the desired properties when dealing with non-daily data. If any accumulation is done this happens after truncation as specified by thetruncation
argument.- 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
Deprecated; use
forecast
instead to specify the predictive horizon
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.
Examples
if (FALSE) { # \dontrun{
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)
} # }