library(dplyr)
# Create sample data
outbreak_data <- data.frame(
onset_date = as.Date("2024-12-10") + sample(0:100, 50, replace = TRUE),
cases = sample(1:5, 50, replace = TRUE)
)
# Basic weekly binning
bin_by_date(outbreak_data, dates_from = onset_date)
# Weekly binning with case weights
bin_by_date(outbreak_data, onset_date, n = cases)
# Monthly binning
bin_by_date(outbreak_data, onset_date,
date_resolution = "month"
)
# ISO week binning (Monday start)
bin_by_date(outbreak_data, onset_date,
date_resolution = "isoweek"
) |>
mutate(date_formatted = strftime(onset_date, "%G-W%V")) # Add correct date labels
# US CDC epiweek binning (Sunday start)
bin_by_date(outbreak_data, onset_date,
date_resolution = "epiweek"
)
# With population data for incidence calculation
outbreak_data$population <- 10000
bin_by_date(outbreak_data, onset_date,
n = cases,
population = population
)
Run the code above in your browser using DataLab