clean_reversals: Clean up reversals in daily count time series

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

This function was written to overcome the fact that the Covid Historical Data Table has negative counts on a few days in the time series because of changes in the underlying data. The function fixes that by subtracting the negative count from the prior positive day's count.

Usage

1
clean_reversals(daily_time_series, verbose = TRUE)

Arguments

daily_time_series

a time series of count data in chronological order

verbose

a logical where FALSE means messages are suppressed. Default = TRUE

Details

If there are two or more negative counts in a row, the function subtracts the sum of the negative count from the most recent day with a positive count. It will issue a warning if this cleaning algorithm results in a daily time series that still has negative counts.

This algorithm ensures that the total cumulative count after the cleaning is equal to what it was originally.

Value

a vector of counts of the same length as the original

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
  suppressPackageStartupMessages(library(dplyr))

  pull_histTable() %>%
    group_by(fips) %>%
    mutate(
      tests_daily_clean = clean_reversals(tests_daily)
    )

## End(Not run)

Skomim/COVID_trajectory_Madison documentation built on July 19, 2020, 12:34 a.m.