Skip to content

Instantly share code, notes, and snippets.

@noamross
noamross / density.R
Last active July 27, 2016 04:55
Overlapping Density Plots
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
df = data_frame(a = rnorm(100, mean=1), b=rnorm(100, mean=2), c=rnorm(100, mean=0)) %>%
gather("var", "value", a,b,c)
ggplot(df, aes(x=value)) +
geom_density(fill="black", col="white", lwd=1) +
@noamross
noamross / test_rstanarm_gamm4.R
Created November 21, 2016 02:29
Trying out rstanarm's new GAM support
library(rstanarm)
library(tidyverse)
library(viridis)
gtemp <- read.delim("http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.5.0.0.annual_ns_avg.txt",
sep="", header = FALSE) %>%
select(1,2) %>%
set_names(c("Year", "Temperature"))
st_mod2 <- stan_gamm4(Temperature ~ s(Year), data = gtemp)
@noamross
noamross / gg_epi.R
Last active May 14, 2022 03:47
Animating vertices of a graph with gganimate and ggraph
library(tidyverse)
library(igraph)
library(ggraph)
library(gganimate)
library(ggforce)
#File at https://dl.dropbox.com/s/hxmsut19lelgw33/epinetwork.rds
episim <- readRDS("epinetwork.rds") # Saved is the simulation data and an adjacency matrix for the network
# Create an undirected graph from this matrix
ign <- graph_from_adjacency_matrix(episim$network > 0, "undirected")
@noamross
noamross / quartzbug.R
Created December 10, 2016 21:59
Bug in R quartz() device
# I believe I found a bug in R's quartz() device, specifically it's
# GECap method (the C routine called by dev.capture). The following
# yields the two images in the comment below. This occurs whether working
# from the terminal or RStudio. This works fine with Cairo devices that
# support raster capture.
quartz()
plot(1,1)
aa <- dev.capture()
dev.size("px")
@noamross
noamross / bias_shapes.R
Created April 4, 2017 13:39
Non-functional extract of fasterraster usage
bias_matrix <- as.matrix(bias_raster) # Bias measure
num_matrix <- as.matrix(number_raster) # Number of samples measure
# Boolean matrix for signficant bias
bias_mat2 <- ifelse((bias_matrix > bias_funs$upper(num_matrix)) | bias_matrix < bias_funs$lower(num_matrix), 1, NA)
# Convert bias boolean to shapes. This is a list of shapes, each shape being an NX2 matrix of points.
bias_shapes <- fasteraster::raster2vector(bias_mat2) %>%
# Remove shapes that are actually just points or lines (<= 3 defining points)
{Filter(function(x) nrow(x) > 3, .) } %>%
# Convert matrix coords to lat/long for each shape
@noamross
noamross / find_local_tweeps.R
Created August 14, 2017 23:43
A visit to Durham
library(rtweet) #rtweet API creds should already be set up
library(stringi)
library(dplyr)
friends = get_friends(user="noamross")
followers = get_followers("noamross")
tweeps_id = distinct(bind_rows(friends, followers))
tweeps_info = lookup_users(tweeps_id$user_id)
# A regex for a visit to Durham
@noamross
noamross / ecohealth-research-scientist-2017.md
Last active October 10, 2017 13:59
JOB: Research Scientist at EcoHealth Alliance, Modeling & Analytics

Position Title: Research Scientist

https://www.ecohealthalliance.org/career/research-scientist

POSITION SUMMARY

EcoHealth Alliance seeks a creative and analytically-minded research scientist with strong quantitative skills to support our Modeling and Analytics team. The research scientist will work closely with our team of scientists and staff on multiple projects related to disease emergence, antimicrobial resistance, land-use change, and conservation. The research scientist will work as part of the USAID supported PREDICT project as well as other federally-funded research. Responsibilities of the research scientist include performing statistical analyses, assembling and curating data sets, performing literature reviews, and writing scientific publications and government reports. The candidate must be self-motivated, proactive, and willing and able to help design new research projects that fit with the mission and direction of EcoHealth Alliance. The candidate must be

@noamross
noamross / ecohealth-alliance-disease-ecologist-2017.md
Created December 6, 2017 22:37
JOB ADVERTISMENT: Disease Ecologist

JOB ADVERTISMENT: Disease Ecologist

https://www.ecohealthalliance.org/career/disease-ecologist

EcoHealth Alliance seeks a Disease Ecologist with strong quantitative skills for a six-month, full-time position. The Disease Ecologist will work with our team of scientists and staff on a research project modeling the risk of import and spread of foot-and-mouth disease in the cattle and swine sectors in the USA. Responsibilities of the Disease Ecologist include developing and performing simulations, performing statistical analyses, assembling and curating data sets, performing literature reviews and writing reports. The candidate must have strong epidemiological and computational skills, including experience with stochastic simulation, spatial analyses, and network models. The candidate must have strong writing skills and the ability to work independently.

PRIMARY RESPONSIBILITIES

@noamross
noamross / mkrproj.sh
Last active January 17, 2018 13:33 — forked from bearloga/mkrproj.sh
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
#!/bin/bash
# Usage: mkproj [projectname]
# projectname defaults to name of current directory
template="Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Yes
@noamross
noamross / gh_file.R
Last active December 3, 2020 09:25
Function to download a file from github via API, including large files and private repos
# TODO (maybe)
# - Vectorize on URLs
# - Allow for downloading whole directory contents if path is a directory
# - Make a recursive = TRUE argument for this case
# - Error messages/input checking
#' Gets a file from a github repo, using the Data API blob endpoint
#'
#' This avoids the 1MB limit of the content API and uses [gh::gh] to deal with
#' authorization and such. See https://developer.github.com/v3/git/blobs/