knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(vdhcovid) library(dplyr) library(ggplot2)
The daily number of tests has a strong periodic signal.
apr15 <- as.Date('2020-04-15') dailytotal <- group_by(vadailytests, date) %>% summarise(ntest=sum(ntest)) %>% filter(date >= apr15) trendfit <- lm(ntest~date, dailytotal) dailytotal$ntest_detrend <- dailytotal$ntest - predict(trendfit) N <- nrow(dailytotal) Nhalf <- floor(N/2 + 1) ggplot(dailytotal, aes(x=date, y=ntest)) + geom_line(size=1.2, color='MidnightBlue') + theme_bw()
We can do a spectral analysis to work out what frequencies are represented.
ps <- fft(dailytotal$ntest_detrend)[1:Nhalf] f <- (seq_along(ps) - 1) / N pltps <- data.frame(f=f, ps=Mod(ps)) ggplot(pltps, aes(x=f, y=ps)) + geom_vline(color='red', xintercept = 1/7, linetype=2) + geom_col(width=0.25*f[2], fill='MidnightBlue') + ylab('Spectral density') + xlab('Frequency (1/day)') + theme_bw()
top3 <- order(pltps$ps, decreasing=TRUE)[1:3] f3 <- f[top3] per3 <- signif(1/f3, 2)
The top 3 modes have periods of r paste(per3, collapse=', ')
days. The first
of these confirms what we expected; there is a weekly periodicity that is probably
due to less testing and test processing on weekends. The third is probably due
to weekends being two days long. The middle one is about half a week; it's probably
related to the fact that the character of the periodicity is more like $\sin^2 t$
than $\sin t$.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.