Skip to contents


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.


create_shifted_cases(data, shift, smoothing_window, horizon)



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


Numeric, mean delay shift to apply.


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


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


A <data.frame> for shifted reported cases


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.


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(
     date = seq(
       min(cases$date) - smoothing_window,
       min(cases$date) - 1,
       by = "days"
     confirm = 0, breakpoint = 0
create_shifted_cases(cases, shift, smoothing_window, horizon)
} # }