Skip to content

Instantly share code, notes, and snippets.

Avatar
💼

Sam Abbott seabbs

💼
View GitHub Profile
@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
Last active Nov 23, 2020
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
# 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"
View update-estimate-git.sh
#!bin/bash
cd /home/azureuser/covid-rt-estimates
git add --all
git commit -m "update estimates"
git push
View update-site.sh
#!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 Aug 21, 2020
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.
View change_with_rw_padding
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 Aug 14, 2020
Set up an instance of EpiNow2 on a clean server with an interactive Rstudio server at localhost:8787 (username/login: epinow2)
View set-up-epinow2.sh
#!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 Aug 17, 2020
Update Rt estimates on a remote server over SSH. Run with: sudo bash update-rt-estimates.sh server-public-ip
View update-rt-estimates.sh
#!/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 Jul 2, 2020
Deploy GitHub pages from the docs folder to gh-pages
View deploy_pages.sh
git subtree split --squash --prefix docs -b gh-pages
git push -f origin gh-pages:gh-pages
git branch -D gh-pages
@seabbs
seabbs / simulate-cases
Created May 29, 2020
Simulates cases by date of report from input Rt and initial case seed
View simulate-cases
library(EpiNow)
library(EpiSoon)
library(data.table)
#1. Input a vector of Rt estimates, and vector to initialise cases, and a generation time
initial_cases <- 100
initial_date <- as.Date("2020-03-01")
rts <- c(rep(2, 20), (2 - 1:15 * 0.1), rep(0.5, 10))
## Simulating cases
@seabbs
seabbs / memory-leak
Created May 11, 2020
Test memory leak
View memory-leak
# Packages -----------------------------------------------------------------
require(data.table, quietly = TRUE)
require(future, quietly = TRUE)
## Require for data and nowcasting
# require(EpiNow, quietly = TRUE)
# require(NCoVUtils, quietly = TRUE)
## Required for forecasting
# require(future.apply, quietly = TRUE)
You can’t perform that action at this time.