Skip to content

Instantly share code, notes, and snippets.

View mkiang's full-sized avatar

Mathew Kiang mkiang

View GitHub Profile
@mkiang
mkiang / server.R
Created November 22, 2013 05:44
OpenSEIR model to share. To run locally, use: library(shiny) runGist('7595396')
# See https://github.com/mkiang/OpenSEIR for comments or updates.
library(shiny)
library(deSolve)
library(ggplot2)
shinyServer(function(input, output) {
# Define the SEIR model for open population
# b is transmission probability, k is contact rate, r is recovery rate,
# bd is birth/death rate, and L is the rate from latent to infectious.
@mkiang
mkiang / snowfall.R
Last active August 29, 2015 14:16
Boston Snowfall
## Side project name: Boston winters for the last ten years
## Author: M Kiang
## Data: http://www.ncdc.noaa.gov/snow-and-ice/daily-snow/
library(ggplot2)
library(dplyr)
library(tidyr)
# library(scales)
# library(gridExtra)
# library(directlabels)
@mkiang
mkiang / mtafares.R
Last active August 29, 2015 14:17
MetroCard Graph
## Side project name: Refilling MTA cards (March 2015 rates)
## Author: Mathew Kiang
## See: http://mathewkiang.com/2015/03/23/new-metrocard-rates-and-the-dreaded-dead-zone-of-change/
library(ggplot2)
## Define parameters
price <- 2.75
bonus <- 1.11
lim <- 0.15 # amount of change willing to tolerate
upp <- 25 # upper limit to amount deposited
@mkiang
mkiang / sequencegenerators.R
Created June 10, 2015 00:45
Benchmark and plot four different ways to generate sequences in R
library(microbenchmark)
library(ggplot2)
library(dplyr)
holder <- NULL
endpoints <- 10 ^ (1:9)
for(endpoint in endpoints) {
x <- microbenchmark(
seq_len = seq_len(endpoint),
colon = 1:endpoint,
@mkiang
mkiang / google_cites.R
Created October 8, 2016 06:39
A visual tour of my publications
## Code for this blog post:
## http://mathewkiang.com/2016/10/08/a-visual-tour-of-my-publications/
## Imports
library(RColorBrewer)
library(ggplot2)
library(dplyr)
library(devtools)
devtools::install_github("jkeirstead/scholar")
library(scholar)
@mkiang
mkiang / lunar_phases.py
Created January 7, 2017 22:33
Download lunar phases from the US National Observatory as a pandas df
import requests
import errno
import pandas as pd
import os
def mkdir_p(path):
""" If a directory does not exist, create it. """
try:
os.makedirs(path)
@mkiang
mkiang / histogram_legend.R
Created January 17, 2017 02:06
Code demonstrating how to use a histogram as a legend on a choropleth
## Code for this blog post: https://mathewkiang.com/2017/01/16/using-histogram-legend-choropleths/
## Download the drug death data from:
## https://blogs.cdc.gov/nchs-data-visualization/drug-poisoning-mortality/
##
## Download the 2013 CB shapefiles (500k will do) for counties and states:
## https://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html
## https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html
## Imports ----
@mkiang
mkiang / SIR.R
Created January 27, 2017 12:09
Sample SIR code for EPI 501 lab
#SIR practical from Debarre and Bonhoeffer ("SIR models of epidemics")
library(deSolve)
parms <- c(beta = 0.333, k = 3 , r = 0.333)
inits <- c(S = 499, I = 1, R = 0)
dt <- seq(0, 300, 1)
SIR <- function(t, x, parms){
with(as.list(c(parms, x)), {
@mkiang
mkiang / nejm_blog_post.R
Created October 9, 2017 02:36
NEJM and pre-print policy
## Code for the blog post here:
## https://mathewkiang.com/2017/10/08/using-r-wikipedia-sherparomeo-show-new-england-journal-medicines-pre-print-statement-empirically-false
## You can download the original files from the blogpost.
## If downloading new files, you probably want to change the date in the file names.
## Imports
library(rvest)
library(tidyverse)
## Wiki data

Keybase proof

I hereby claim:

  • I am mkiang on github.
  • I am mkiang (https://keybase.io/mkiang) on keybase.
  • I have a public key ASBcR0WeyXKq1QlGo0lxZxRG2VRNJKIJ8-h6NNFJLDFSYAo

To claim this, I am signing this object: