Created
January 10, 2021 23:13
-
-
Save thoughtfulbloke/156dd0a9becbc924344bd5727335c8ee to your computer and use it in GitHub Desktop.
New Zealand MiQ covid positivity rate calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readxl) | |
library(readr) | |
library(dplyr) | |
library(lubridate) | |
library(ggplot2) | |
library(ggthemes) | |
# arrivals from provisional daily arrivals stats NZ | |
# postive MiQ data from MoH case demographics | |
crossings <- read_excel("Downloads/20201223-daily-movements-across-nz-border-Jan-Dec-2019-2020.xlsx", | |
sheet = "Data", col_types = c("numeric", | |
"numeric", "numeric", "date", "text", | |
"text", "text", "text", "text", "text", | |
"text", "text", "text", "numeric")) | |
arrivals <- crossings %>% | |
filter(travel_mode == "A") %>% | |
group_by(date) %>% | |
summarise(entries = sum(total_movements)) | |
cases <- read_csv("Downloads/covid_cases_2021-01-10.csv", | |
col_types = cols(`Report Date` = col_date(format = "%Y-%m-%d"))) | |
MiQ <- cases %>% filter(DHB == "Managed Isolation & Quarantine", | |
`Overseas travel` == "Yes") %>% | |
count(`Report Date`) %>% | |
rename(date = `Report Date`) | |
# on the assumption of tests on day 3 and 12 | |
bind_rows(arrivals %>% mutate(date = date + days(3)), | |
arrivals %>% mutate(date = date + days(12))) %>% | |
group_by(date) %>% | |
summarise(miq_tests = sum(entries)) %>% | |
filter(date >= as.Date("2020-07-01"), date < as.Date("2021-01-11")) %>% | |
left_join(MiQ, by="date") %>% | |
mutate(n = ifelse(is.na(n),0,n), | |
positivity_rate = 100 * n/miq_tests) %>% | |
ggplot(aes(x=date,y=positivity_rate, xend=date)) + | |
geom_segment(yend=0) + | |
ggtitle("Assuming day 3 and 12 tests, daily positivity rate for NZ MiQ") + | |
theme_minimal() + geom_smooth() + | |
ylab("Positive cases per 100 tests") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment