Skip to contents

[Stable] Filters leading zeros, completes dates, and applies an optional threshold at which point 0 cases are replaced with a user supplied value (defaults to NA).

Usage

create_clean_reported_cases(
  reported_cases,
  horizon = 0,
  filter_leading_zeros = TRUE,
  zero_threshold = Inf,
  fill = NA_integer_,
  add_breakpoints = TRUE
)

Arguments

reported_cases

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

horizon

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

filter_leading_zeros

Logical, defaults to TRUE. Should zeros at the start of the time series be filtered out.

zero_threshold

[Experimental] Numeric defaults to Inf. Indicates if detected zero cases are meaningful by using a threshold number of cases based on the 7-day average. If the average is above this threshold then the zero is replaced using fill.

fill

Numeric, defaults to NA. Value to use to replace NA values or zeroes that are flagged because the 7-day average is above the zero_threshold. If the default NA is used then dates with NA values or with 7-day averages above the zero_threshold will be skipped in model fitting. If this is set to 0 then the only effect is to replace NA values with 0.

add_breakpoints

Logical, defaults to TRUE. Should a breakpoint column be added to the data frame if it does not exist.

Value

A cleaned data frame of reported cases

Examples

create_clean_reported_cases(example_confirmed, 7)
#> Key: <date>
#>            date confirm breakpoint
#>          <Date>   <num>      <num>
#>   1: 2020-02-22      14          0
#>   2: 2020-02-23      62          0
#>   3: 2020-02-24      53          0
#>   4: 2020-02-25      97          0
#>   5: 2020-02-26      93          0
#>  ---                              
#> 133: 2020-07-03      NA          0
#> 134: 2020-07-04      NA          0
#> 135: 2020-07-05      NA          0
#> 136: 2020-07-06      NA          0
#> 137: 2020-07-07      NA          0