knitr::opts_chunk$set(echo = FALSE, include = TRUE, warning = FALSE, message = FALSE, root.dir = here::here(), fig.width = 12, fig.height = 9) options(digits = 1) library(here) library(forecast.vocs) library(dplyr) library(loo) library(scoringutils) library(knitr) library(data.table)
# load packages library(ggplot2) library(scales) library(dplyr) library(here) library(readr) library(data.table) # load functions source(here("R", "load-local-data.R")) source(here("R", "plot-summary.R")) source(here("R", "plot-daily-cases.R")) source(here("R", "plot-omicron-95.R")) source(here("R", "plot-cumulative-percent.R"))
We use S-gene status by specimen date sourced from UKHSA as a direct proxy for the Omicron variant with a target failure indicating a case has the Omicron variant. Data was available by UKHSA region.
# get latest date date_latest <- get_latest_date() # load data daily <- load_local_data(date_latest) # start date start_date <- as.Date("2021-11-23") daily <- daily %>% filter(date >= start_date) %>% filter(!is.na(sgtf)) %>% filter(!(region %in% "England")) # munge fraction, logit scaling, difference, and dow daily <- daily %>% mutate(frac_sgtf = sgtf / total_sgt) %>% mutate(logit_frac_sgtf = log(frac_sgtf / (1 - frac_sgtf))) %>% group_by(region) %>% arrange(date) %>% mutate(diff_logit_sgtf = logit_frac_sgtf - lag(logit_frac_sgtf)) %>% ungroup() %>% mutate(weekday = weekdays(date) %>% factor(levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))) %>% mutate(mondays = ifelse(weekday %in% "Monday", date, NA_Date_))
All models were implemented using the forecast.vocs
R package [@R; @forecast.vocs] and fit using stan
[@stan] and cmdstanr
[@cmdstanr]. Each model was fit using 2 chains with each chain having 1000 warmup steps and 2000 sampling steps. Convergence was assessed using the Rhat diagnostic [@stan]. Models were compared using approximate leave-one-out (LOO) cross-validation [@loo; @loo-paper] where negative values indicate an improved fit for the correlated model.
daily %>% plot_daily_cases( truncate_date = max(daily$date), caption = "", start_date = start_date, smooth_total = TRUE ) + geom_vline(aes(xintercept = mondays), linetype = 2, alpha = 0.5)
daily %>% ggplot() + aes(x = date, y = logit_frac_sgtf, col = region) + geom_vline(aes(xintercept = mondays), linetype = 2, alpha = 0.5) + geom_point(alpha = 0.8) + geom_line(alpha = 0.4) + scale_color_brewer(palette = "Paired") + theme_bw() + theme(legend.position = "bottom") + labs(x = "Specimen date", y = "Fraction of those tested for the S gene with target failure (logit scale)", col = "UKHSA region")
daily %>% ggplot() + aes(x = weekday, y = diff_logit_sgtf, col = region) + geom_violin(aes(col = NULL), alpha = 0.4, fill = "grey", draw_quantiles = c(0.25, 0.5, 0.75)) + geom_jitter(alpha = 0.6) + scale_color_brewer(palette = "Paired") + theme_bw() + theme(legend.position = "bottom") + guides(fill = NULL) + labs(x = "Day of week", y = "Difference in SGTF fraction from the previous day (logit scale)", col = "UKHSA region")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.