Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Sam Abbott seabbs

🏠
Working from home
View GitHub Profile
@seabbs
seabbs / covidregionaldata-0.9.1-overview.R
Created May 7, 2021
An overview of the features included in the 0.9.1 release of covidregionaldata. See the release notes for more details: https://github.com/epiforecasts/covidregionaldata/releases/tag/v0.9.1
View covidregionaldata-0.9.1-overview.R
library(covidregionaldata)
# set up a data cache
start_using_memoise()
#> Using a cache at: /tmp/RtmphiSeWY
# check for supported countries
get_available_datasets()
#> # A tibble: 18 x 8
#> origin class level_1_region level_2_region level_3_region type data_urls
@seabbs
seabbs / process-rt.R
Created Mar 9, 2021
Example script for processing samples.
View process-rt.R
# Packages ----------------------------------------------------------------
require(data.table, quietly = TRUE)
require(EpiNow2, quietly = TRUE)
require(purrr)
require(ggplot2)
# Target date -------------------------------------------------------------
creation_date <- Sys.Date()
extraction_date <- creation_date
@seabbs
seabbs / covid19-utla-rt-from-admissions.R
Last active Jun 9, 2021
R code using {covid19.nhs.data} and estimates from epiforecasts.io/covid to generate a gif of the effective reproduction for Covid-19 using hospital admissions by upper-tier local authority in England.
View covid19-utla-rt-from-admissions.R
# Packages ----------------------------------------------------------------
library(covid19.nhs.data)
library(vroom)
library(dplyr)
library(tidyr)
library(lubridate)
library(gganimate)
#devtools::install_github("thomasp85/transformr")
library(transformr)
library(gifski)
@seabbs
seabbs / covid19-utla-admissions.R
Last active Jan 25, 2021
R code using {covid19.nhs.data} to generate a gif of Covid-19 hospital admissions byupper-tier local authority in England.
View covid19-utla-admissions.R
# Packages ----------------------------------------------------------------
library(covid19.nhs.data)
library(dplyr)
library(tidyr)
library(lubridate)
library(gganimate)
#devtools::install_github("thomasp85/transformr")
library(transformr)
library(gifski)
library(ggplot2)
@seabbs
seabbs / covid19-ltla-admissions.R
Last active Jan 25, 2021
R code using {covid19.nhs.data} to generate a gif of weekly Covid-19 hospital admissions by lower-tier local authority in England.
View covid19-ltla-admissions.R
# Packages ----------------------------------------------------------------
library(covid19.nhs.data)
library(dplyr)
library(tidyr)
library(lubridate)
library(gganimate)
#devtools::install_github("thomasp85/transformr")
library(transformr)
library(gifski)
library(ggplot2)
@seabbs
seabbs / epinow2-covid-rt-region.R
Last active Dec 8, 2020
Example of using EpiNow2 to estimate the Rt of Covid-19 in last 3 months for a region in a country supported in covidregionaldata. See the documentation for more details and examples: https://epiforecasts.io/EpiNow2/
View epinow2-covid-rt-region.R
# packages
# install.packages(c("data.table", "remotes", "EpiNow2"))
# remotes::install_github("epiforecasts/EpiNow2")
# remotes::install_github("epiforecasts/covidregionaldata")
library(data.table)
library(EpiNow2)
library(covidregionaldata)
# target country (must be supported in covidregionaldata)
country <- "uk" # harder to fit "india"
@seabbs
seabbs / regional-secondary.R
Last active Jun 1, 2021
Prototype function for forecasting a secondary observation from a primary observation across multiple regions. An example application of this function can be found here: https://github.com/epiforecasts/covid-german-forecasts/blob/master/rt-forecast/update-death-from-cases.R. See the documentation of EpiNow2 for more details: https://epiforecasts…
View regional-secondary.R
# load required packages
library(EpiNow2)
library(future.apply)
library(purrr)
library(data.table)
warning("This gist is depreciated. Please use the following development repository: https://github.com/seabbs/regional-secondary.git")
# extract priors from a posterior and update fitting args
extract_secondary_priors <- function(posterior) {
@seabbs
seabbs / forecast-covid-deaths-from-covid-cases.R
Last active Dec 1, 2020
Example of using EpiNow2 to forecast Covid-19 deaths from Covid-19 cases (both observed and forecast) for a country in the ECDC dataset. See the documentation for more details: https://epiforecasts.io/EpiNow2/dev/
View forecast-covid-deaths-from-covid-cases.R
# set number of cores to use fitting the model
# no benefit on runtime if cores > chains which is set to 4 by default
options(mc.cores = 4)
# Packages ----------------------------------------------------------------
# install.packages(c("data.table", "remotes", "ggplot2"))
# remotes::install_github("epiforecasts/EpiNow2")
# remotes::install_github("epiforecasts/covidregionaldata")
library(data.table)
library(ggplot2)
@seabbs
seabbs / explore-covid-19-data-truncation
Last active Nov 23, 2020
Explores Covid-19 data truncation in England (i.e when data is updated in later releases) using an experimental model in EpiNow2. By default looks at test positive cases but this can be updated by changing the selected variable in line 27.
View explore-covid-19-data-truncation
# Note: estimate_truncation is experimental so use this for exploratory purposes
# only and/or with a high level of interpretation
# Packages ----------------------------------------------------------------
# install packages
# install.packages(c("data.table", "purrr", "remotes", "EpiNow2"))
# remotes::install_github("epiforecasts/covidregionaldata")
library(data.table)
library(purrr)
library(covidregionaldata)
library(EpiNow2)
@seabbs
seabbs / epinow2-covid-rt-national.R
Last active Jan 14, 2021
Example of using EpiNow2 to estimate the Rt of Covid-19 in last 3 months for a country in the ECDC dataset. See the documentation for more details and examples of producing estimates for subregional areas: https://epiforecasts.io/EpiNow2/
View epinow2-covid-rt-national.R
# packages
# install.packages(c("data.table", "remotes", "EpiNow2"))
# remotes::install_github("epiforecasts/covidregionaldata")
library(data.table)
library(EpiNow2)
library(covidregionaldata)
# target country (must be present in ECDC data)
country <- "france"