Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
Created November 3, 2021 22:12
Show Gist options
  • Save thoughtfulbloke/fd199c6ebc9796dbc4645293398a0394 to your computer and use it in GitHub Desktop.
Save thoughtfulbloke/fd199c6ebc9796dbc4645293398a0394 to your computer and use it in GitHub Desktop.
rolling locations of interest per adult case of covid
library(dplyr)
library(lubridate)
library(ggplot2)
library(ggthemes)
library(tidyr)
library(RcppRoll)
# To look at locations of interest, I am taking my own set of infectious vs isolated cases from the 1pm news conference, the csv of individual case details to get location (available as a csv linked from https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics ), and a collection of the location of interest updates kindly provided by @nzgizmoguy on Twitter at https://github.com/gizmoguy/locations-of-interest
all_cases <- read.csv("covid_cases_2021-11-03.csv", colClasses = c("Date","character","character","character","character","character","character"))
Lcsvs <- list.files(path = "by-commit", full.names = TRUE, recursive = TRUE, pattern = "csv$")
custom_read <- function(x){
someCols <- read.csv(x, colClasses = "character")
return(someCols)
}
sheets_lst <- lapply(Lcsvs, custom_read)
sheets_agg <- bind_rows(sheets_lst)
Locations <- sheets_agg %>%
select(id, City, Added) %>%
mutate(creation = dmy_hm(Added),
creation = if_else(is.na(creation), ymd_hms(Added), creation),
creation = as.Date(creation)) %>%
filter(creation > as.Date("2021-9-12")) %>%
arrange(id, creation) %>%
select(id, City, creation) %>%
distinct() %>%
filter(!is.na(creation)) %>%
mutate(DHB = case_when(City == "AD-19339240"~ "Auckland",
City == "auckland"~ "Auckland",
City == "Auckland"~ "Auckland",
City == "Bombay"~ "Auckland",
City == "Clarks Beach"~ "Auckland",
City == "Drury"~ "Auckland",
City == "Parakai"~ "Auckland",
City == "Red Beach"~ "Auckland",
City == "Kaiwaka"~ "Auckland",
City == "Kumeu"~ "Auckland",
City == "Whangaparaoa"~ "Auckland",
City == "Silverdale"~ "Auckland",
City == "Warkworth"~ "Auckland",
City == "Wellsford"~ "Auckland",
City == "Takanini"~ "Auckland",
City == "Pukekohe"~ "Auckland",
City == "Papakura" ~ "Auckland",
is.na(City) ~ "Auckland",
TRUE ~ "exAuckland")) %>%
count(creation, DHB) %>%
spread(key=DHB, value=n, fill=0) %>%
mutate(L3Auck = roll_meanr(Auckland, 3),
L3exAu = roll_meanr(exAuckland, 3)) %>%
select(creation, L3Auck, L3exAu) %>%
gather(key=region, value=rollingLocs, 2:3) %>%
filter(!is.na(rollingLocs)) %>%
mutate(region = ifelse(region == "L3Auck", "Auckland", "exAuckland")) %>%
rename(Report.Date = creation)
adults <- all_cases %>%
filter(Age.group %in% c("0 to 9", "10 to 19"),
DHB != "Managed Isolation & Quarantine",
Report.Date > as.Date("2021-9-12")) %>%
mutate(region = ifelse(DHB %in% c("Auckland", "Counties Manukau", "Waitemata"),"Auckland", "exAuckland")) %>%
count(region, Report.Date) %>%
spread(key=region, value=n, fill=0) %>%
mutate(C3Auck = roll_meanr(Auckland, 3) + .3,
C3exAu = roll_meanr(exAuckland, 3) + .3) %>%
select(Report.Date, C3Auck, C3exAu) %>%
gather(key=region, value=rollingCases, 2:3) %>%
filter(!is.na(rollingCases)) %>%
mutate(region = ifelse(region == "C3Auck", "Auckland", "exAuckland"))
locAd <- Locations %>% inner_join(adults, by = c("Report.Date", "region")) %>%
mutate(Loc_per_Adult = rollingLocs/ rollingCases) %>%
ggplot(aes(x=Report.Date, y=Loc_per_Adult,
colour=region)) + geom_point() +
geom_line() + scale_colour_colorblind() + theme_minimal() +
labs(Title="Rolling 3 day New Locations divided by
(Rolling 3 day covid postive adults (20+) + 0.3)",
x = "Date of test report or Date Location added",
y= "Rolling Locations per Adult")
ggsave(filename="~/Desktop/locations_adult.png", plot=locAd, dpi=150, units="in",
height = 5.556, width=9.877, bg="white")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment