--- title: "Season week" author: "Chi Zhang" date: "2022-03-14" output: rmarkdown::html_vignette: fig_width: 6 fig_height: 6 vignette: > %\VignetteIndexEntry{Season week} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} editor_options: chunk_output_type: console --- ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` Season week is the week number within an epidemiological season. It is used for surveillance outcomes such as influenza, where aligning data to a season rather than a calendar year makes trends easier to compare across years. Isoweek runs from 1 to 53; season week runs from 1 to 52. When isoweek is 53, the corresponding season week is 18.5. ```{r} library(cstime) library(magrittr) library(data.table) ``` ## Mapping between isoweek and season week The chart below shows the relationship across all isoweek values, with the special case of isoweek 53 highlighted. ```{r, echo = FALSE} library(ggplot2) pd <- data.table(isoweek = 1:53, seasonweek = isoweek_to_seasonweek_n(1:53)) q <- ggplot(pd, aes(x=seasonweek, y = isoweek)) q <- q + geom_point() q <- q + geom_point(data = pd[isoweek==53], mapping = aes(color="Isoweek==53")) q <- q + scale_color_discrete(NULL) q <- q + scale_x_continuous("seasonweek", breaks = seq(1,52,4)) q <- q + scale_y_continuous("isoweek", breaks = seq(1,53,4)) q ``` ## Conversion functions ```{r} seasonweek_to_isoweek_c(10) seasonweek_to_isoweek_n(10) isoweek_to_seasonweek_n(1) seasonweek_to_isoweek_n(1:52) isoweek_to_seasonweek_n(1:53) ```