Converts cumulative counts (total reported as of each report date) to
incremental counts (new cases reported at each report date). This is
necessary because some data sources (e.g., epidatr NHSN data) return
cumulative counts, but baselinenowcast::as_reporting_triangle() expects
incremental counts.
Usage
cumulative_to_incremental(data, group_cols = c("reference_date", "location"))Value
A data frame with the same structure as input, but with count
converted to incremental counts (difference from previous report date).
Details
For each reference date (and optionally other grouping columns), the function:
Sorts by report date
Computes the difference from the previous report date's count
Uses 0 as the "previous" count for the first report date
This assumes that the first report date for each reference date represents the initial count (i.e., there was 0 before it).
Examples
# Example with cumulative data
cumulative_data <- data.frame(
reference_date = as.Date(c("2024-01-06", "2024-01-06", "2024-01-06")),
report_date = as.Date(c("2024-01-13", "2024-01-20", "2024-01-27")),
count = c(100, 120, 125), # cumulative
location = "ca"
)
incremental_data <- cumulative_to_incremental(cumulative_data)
# count is now: 100, 20, 5 (the differences)