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
## For password management
git config --global user.email "[email protected]"
git config --global user.name "Sam Abbott"
git config --global credential.helper cache
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
# github settings
# developer settings
# create access token and copy
# git pull/push
@seabbs
seabbs / plot_per_decrease
Last active November 15, 2017 12:12
Plot the annual percentage decrease in TB notifications
nots %>% ggplot(aes(x = year, y = prop_decrease, col = prop_decrease)) +
geom_hline(yintercept = 0, linetype = 1, alpha = 0.5) +
geom_hline(yintercept = 0.09, linetype = 2, alpha = 0.5) +
geom_point(size = 2) +
scale_y_percent() +
geom_smooth(alpha = 0.2) +
scale_colour_viridis_c() +
theme_minimal()
@seabbs
seabbs / spread_annual_change_nots
Created November 15, 2017 15:18
Spread annual change in nots by year
age_groups <- tibble(age_groups = c("15-19 years",
"20-24 years", "25-29 years"), key = 1)
nots_by_age <- nots %>%
mutate(key = 1) %>%
left_join(age_groups, by = "key") %>%
select(-key, -prev_year_m, -measure, -prop_decrease_sample) %>%
spread(key = "age_groups", value = "prop_decrease_sample")
@seabbs
seabbs / multidplyr
Created November 21, 2017 19:28
How to start a multidplyr cluster
cluster <- create_cluster(CORES) %>%
cluster_library(c("PACKAGE_NAME")) %>%
cluster_copy(CUSTOM_VARIABLE)
then use parition and collect
@seabbs
seabbs / plot_tb_burden_example
Created December 1, 2017 09:29
Plot TB incidence in your country of interest using WHO data
install.packages("devtools")
devtools::install_github("seabbs/getTBinR")
getTBinR::plot_tb_burden(metric = "e_inc_100k", countries = "United Kingdom", facet = "country", interactive = TRUE)
@seabbs
seabbs / gist:13dfd542fa68183cf2d81129ce139c2e
Created December 20, 2017 22:46
Compare nested multiply imputed models
## Likelihood test p values for categorical variables
model_uni <- outcomes %>% map(function(.) model_outcome_uni(., variable = 'ageatvac', LRT = TRUE))
model_adj <- outcomes %>% map(function(.) model_outcome_adj(., variable = 'ageatvac', LRT = TRUE))
ageatvac_lrt_uni <- map2(model_ageatvac_uni, model_uni, function(x, y) pool.compare(x, y, data = imp_df, method = "likelihood")) %>%
map(function(x) ifelse(x < 0.001, "0.001", pretty_round(x, digits = 3)))
ageatvac_lrt_adj <- map2(model_ageatvac_adj, model_adj, function(x, y) pool.compare(x, y, data = imp_df, method = "likelihood")$pvalue) %>%
map(function(x) ifelse(x < 0.001, "0.001", pretty_round(x, digits = 3)))
@seabbs
seabbs / explore_tb_mortality_exc_hiv
Created January 7, 2018 13:54
Explore TB mortality excluding HIV using getTBinR
# install.packages("getTBinR")
library(getTBinR)
# install.packages("tidyverse")
library(tidyverse)
# Get the data
tb_burden <- get_tb_burden(download_data = TRUE, save = TRUE)
dict <- get_data_dict(download_data = TRUE, save = TRUE)
# Look up variables with mortality in their definition
@seabbs
seabbs / explore_tb_incidence
Last active January 9, 2018 14:20
Explore 20 countries with highest TB incidence
# install.packages("getTBinR")
library(getTBinR)
# install.packages("tidyverse")
library(tidyverse)
# Get the data
tb_burden <- get_tb_burden(download_data = TRUE, save = TRUE)
dict <- get_data_dict(download_data = TRUE, save = TRUE)
# Look up variables with mortality in their definition
@seabbs
seabbs / explore_case_detection
Created January 11, 2018 16:16
Explore case detection and incidence rates in the WHO Tuberculosis data
# install.packages("getTBinR")
library(getTBinR)
# install.packages("tidyverse")
library(tidyverse)
# install.packages("gridExtra")
library(gridExtra)
# Get the data
tb_burden <- get_tb_burden(download_data = TRUE, save = TRUE)
dict <- get_data_dict(download_data = TRUE, save = TRUE)
@seabbs
seabbs / tab_ci
Last active January 16, 2018 16:41
Tableau R code ci
FLOAT(SCRIPT_REAL("qbinom(0.001, .arg2, .arg1 / .arg2) / .arg2",
WINDOW_SUM(SUM([prob_Accepted]), -[No. of days for rolling average] + 1, 0),
WINDOW_SUM(COUNT([prob_Accepted]), -[No. of days for rolling average] + 1, 0)))