Smooth a time series of noisy observations. Currently only LOESS smoothing (smoothing_method = "LOESS") is implemented.

smooth_incidence(
  incidence_data,
  smoothing_method = "LOESS",
  simplify_output = TRUE,
  ...
)

Arguments

incidence_data

An object containing incidence data through time. It can either be:

  • A list with two elements:

    1. A numeric vector named values: the incidence recorded on consecutive time steps.

    2. An integer named index_offset: the offset, counted in number of time steps, by which the first value in values is shifted compared to a reference time step This parameter allows one to keep track of the date of the first value in values without needing to carry a date column around. A positive offset means values are delayed in the future compared to the reference values. A negative offset means the opposite.

  • A numeric vector. The vector corresponds to the values element descrived above, and index_offset is implicitely zero. This means that the first value in incidence_data is associated with the reference time step (no shift towards the future or past).

smoothing_method

string. Method used to smooth the original incidence data. Available options are:

simplify_output

boolean. Return a numeric vector instead of module output object if output offset is zero?

...

Arguments passed on to .smooth_LOESS

data_points_incl

integer. Size of the window used in the LOESS algorithm. The span parameter passed to loess is computed as the ratio of data_points_incl and the number of time steps in the input data.

degree

integer. LOESS degree. Must be 0, 1 or 2.

initial_Re_estimate_window

integer. In order to help with the smoothing, the function extends the data back in time, padding with values obtained by assuming a constant Re. This parameter represents the number of timesteps in the beginning of incidence_input to take into account when computing the average initial Re.

Value

A list with two elements:

  1. A numeric vector named values: the result of the computations on the input data.

  2. An integer named index_offset: the offset, counted in number of time steps, by which the result is shifted compared to an index_offset of 0. This parameter allows one to keep track of the date of the first value in values without needing to carry a date column around. A positive offset means values are delayed in the future compared to the reference values. A negative offset means the opposite. Note that the index_offset of the output of the function call accounts for the (optional) index_offset of the input.

If index_offset is 0 and simplify_output = TRUE, the index_offset is dropped and the values element is returned as a numeric vector.

Examples

## Basic usage of smooth_incidence smoothed_incidence_1 <- smooth_incidence( incidence_data = HK_incidence_data$case_incidence, smoothing_method = "LOESS" ) ## Advanced usage of smooth_incidence # Smoothing the incidence using a LOESS window of 15 days, fitting polynomials # of degree 2 in the LOESS algorithm, and averaging the initial Re estimate over # the first 7 days. smoothed_incidence_2 <- smooth_incidence( incidence_data = HK_incidence_data$case_incidence, smoothing_method = "LOESS", simplify_output = FALSE, data_points_incl = 15, degree = 2, initial_Re_estimate_window = 7 )