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 / simulate-cases
Created May 29, 2020 13:15
Simulates cases by date of report from input Rt and initial case seed
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 18:38
Test 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)
@seabbs
seabbs / clean_git.sh
Last active April 7, 2020 11:31
Clean .rds and .png from git histories using BFG
#!bin/bash
## This requires java and bfg to be installed
## bfg: https://rtyley.github.io/bfg-repo-cleaner/
## Assumes that the repo is in the current directory
## Remove all .rds and .png from the Git history
java -jar bfg.jar --delete-files "*.rds" $1
java -jar bfg.jar --delete-files "*.png" $1
@seabbs
seabbs / rco_on_getTBinR.sh
Created December 16, 2019 10:00
Testing {rco} on {getTBinR}
sudo docker pull jcrodriguez1989/rco
mkdir rco_results
sudo docker run -v /rco_results:/rco_results -e RCO_PKG=getTBinR jcrodriguez1989/rco
cd rco_results
@seabbs
seabbs / pomp-tb-model
Created August 8, 2019 11:05
An example POMP TB transmission model
#' Disease Model, with Vaccination, Data Based Population Demographics and Ageing as a Pomp Object
#'
#' @param df A data frame of data to be passed to the pomp model.
#' @param t0 An integer value denoting the starting time for the model, this may be negative.
#' @param nstageA The number of age compartments to model.
#' @param timestep Value indicating the timestep over which to solve the model.
#' @param time The variable to use the time parameter from the data.
#' @param covars Additional data to use within the model.
#' @param tcovar A character string indicating the time variable in covar.
#' @param obsnames A character string of the observable variables.
@seabbs
seabbs / data-read-plus-munge
Last active July 24, 2019 08:57
Read in, munge and save a set of csvs + profiling information
# Get required packages - managed using pacman ---------------------------
# This installs packages if they are missing and otherwise loads them.
if (!require(pacman)) install.packages("pacman"); library(pacman)
p_load("tidyverse")
p_load("fs")
p_load("data.table")
p_load("lubridate")
p_load("purrr")
p_load("furrr")
@seabbs
seabbs / spending_gap_normalised
Created June 7, 2019 10:37
Looking at normalised spending gap for global Tuberculosis funding
# Install and load the package --------------------------------------------
if(!require(pacman))install.packages("pacman")
pacman::p_load('dplyr', 'ggplot2', 'getTBinR')
pacman::p_load_gh('thomasp85/patchwork')
pacman::p_load_gh('bbc/bbplot')
# Look at available datasets\ ---------------------------------------------
available_datasets
@seabbs
seabbs / spending_gap
Last active June 5, 2019 09:29
Looking at the expenditure and funding gap for TB
# Install and load the package --------------------------------------------
#Use install.packages(c("getTBinR", "dplyr", "getTBinR")) to get required packages
library(getTBinR) #TB data + visualisations
library(dplyr) # For data manipulation
library(ggplot2) # For additional visualisations etc.
#For storyboards - install with commented out code
# install.packages("devtools")
# devtools::install_github("thomasp85/patchwork")
@seabbs
seabbs / benchmark-trest
Created February 11, 2019 15:59
Test of benchmarkme functionality.
## Load latest CRAN version of benchmarkme
library(benchmarkme)
## Run a benchmark for a single core
single_perf <- benchmark_std()
## Run a benchmark on multiple cores (here 4)
mutli_perf <- benchmark_std(cores = 4)
@seabbs
seabbs / tidyverse-gpu-dockerfile
Last active January 25, 2019 17:01
A GPU enabled Tidyverse Dockerfile
FROM rocker/tidyverse:latest
MAINTAINER "Sam Abbott" contact@samabbott.co.uk
## Shell tools
RUN apt-get update && apt-get install -y --force-yes --allow-unauthenticated --no-install-recommends --no-upgrade \
curl \
## R package dependencies