Skip to content

Instantly share code, notes, and snippets.

View seabbs's full-sized avatar
🏠
Working from home

Sam Abbott seabbs

🏠
Working from home
View GitHub Profile
@seabbs
seabbs / regional-secondary.R
Last active December 14, 2023 19:00
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…
# 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 November 14, 2023 18:28
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/
# 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 September 30, 2021 16:20
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.
# 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"))
library(data.table)
library(purrr)
library(covidregionaldata)
library(EpiNow2)
@seabbs
seabbs / epinow2-covid-rt-national.R
Last active June 25, 2023 08:02
Example of using EpiNow2 to estimate the Rt of Covid-19 in last 3 months for a country in the WHO dataset. See the documentation for more details and examples of producing estimates for subregional areas: https://epiforecasts.io/EpiNow2/
# packages
# install.packages(c("data.table", "remotes", "EpiNow2"))
library(data.table)
library(EpiNow2)
library(covidregionaldata)
# target country (must be present in ECDC data)
country <- "france"
# set number of cores to use fitting the model
#!bin/bash
cd /home/azureuser/covid-rt-estimates
git add --all
git commit -m "update estimates"
git push
@seabbs
seabbs / update-site.sh
Last active September 10, 2020 09:23
#!bin/bash
cd /home/azureuser/
git clone git@github.com:epiforecasts/covid-rt-estimates.git
cd covid-rt-estimates
sudo bash bin/update-docker.sh "build"
sudo bash bin/update-via-docker.sh
FILE=last-update/update-complete
while [ ! -f "$FILE" ]; do
@seabbs
seabbs / change_with_rw_padding
Last active August 21, 2020 17:26
Evaluates Rt over two fixed time points with Rt assumed to vary based on a random walk in-between the two time points and after a period of time.
library(EpiNow2)
library(data.table)
# Get example case counts
reported_cases <- EpiNow2::example_confirmed[1:60]
# Add a dummy breakpoint (used only when optionally estimating breakpoints)
reported_cases <- reported_cases[, breakpoint := data.table::fifelse((date >= as.Date("2020-03-16") & date <= as.Date("2020-03-29")) | date >= as.Date("2020-04-11"),
1, 0)]
# Set up example generation time
@seabbs
seabbs / set-up-epinow2.sh
Last active August 14, 2020 10:40
Set up an instance of EpiNow2 on a clean server with an interactive Rstudio server at localhost:8787 (username/login: epinow2)
#!bin/bash
sudo apt-get update
sudo apt-get install -y docker.io
sudo docker login docker.pkg.github.com
sudo docker pull docker.pkg.github.com/epiforecasts/epinow2/epinow2:latest
sudo docker tag docker.pkg.github.com/epiforecasts/epinow2/epinow2:latest epinow2
@seabbs
seabbs / update-rt-estimates.sh
Last active August 17, 2020 19:38
Update Rt estimates on a remote server over SSH. Run with: sudo bash update-rt-estimates.sh server-public-ip
#!/bin/bash
# Get rid of the older update script
rm update-via-ssh.sh
# Get the new update script
curl --fail https://raw.githubusercontent.com/epiforecasts/covid-rt-estimates/master/bin/update-via-ssh.sh > update-via-ssh.sh
# Run the update script
bash update-via-ssh.sh ~/.ssh/id_rsa azureuser@$1 github-username-here github-pat-here
@seabbs
seabbs / deploy_pages.sh
Created July 2, 2020 19:40
Deploy GitHub pages from the docs folder to gh-pages
git subtree split --squash --prefix docs -b gh-pages
git push -f origin gh-pages:gh-pages
git branch -D gh-pages