Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathew Kiang mkiang

View GitHub Profile
View clean_tweets.R
## A quick R script for cleaning up your Twitter timeline. This assumes you
## have Twitter API creds but it probably isn't necessary. This is based on
## Chris Albon's Python script:
## https://gist.github.com/chrisalbon/b9bd4a6309c9f5f5eeab41377f27a670
##
## In this example, I remove old tweets in two stages: (1) if tweets are
## older than two years and have fewer than 100 likes and then (2) if tweets
## are older than 90 days and have fewer than 25. Retweets are removed after
## 90 days. Importantly, tweets (and retweets) that I liked are *always*
## protected from deletion.
@mkiang
mkiang / DJI_inter_peak_days.R
Created Feb 15, 2020
Distribution of inter-peak days of the DJIA
View DJI_inter_peak_days.R
library(tidyverse)
library(tidyquant)
source(
"https://raw.githubusercontent.com/mkiang/disproportionate_prescribing/master/code/mk_nytimes.R"
)
getSymbols("^DJI")
DJI <- as_tibble(DJI) %>%
mutate(
View 01_pull_data.R
## Visualizing authorship networks: code for this blog post:
## https://mathewkiang.com/2019/12/07/collaboration-network-from-2010-to-2019/
## Imports ----
library(scholar) # remotes::install_github("jkeirstead/scholar")
library(tidyverse)
library(fs)
library(here)
## Constants ----
@mkiang
mkiang / intro_sir.R
Created Sep 11, 2019
Skeleton code for the DGHS Workshop
View intro_sir.R
## Import packages
library(deSolve)
## Basic SIR using number of people (not proportion of pop)
SIR <- function(t, x, parms){
with(as.list(c(parms, x)), {
N = S + I + R
dS <- -beta*S*I/N
dI <- beta*S*I/N - r*I
dR <- r*I
View packages.R
install.packages("rgdal", dep = TRUE)
install.packages("reshape2", dep = TRUE)
install.packages("viridis", dep = TRUE)
install.packages("rgeos", dep = TRUE)
install.packages("Imap", dep = TRUE)
install.packages("network", dep = TRUE)
install.packages("DT", dep = TRUE)
install.packages("tidyverse", dep = TRUE)
install.packages("deSolve", dep = TRUE)
install.packages("manipulate", dep = TRUE)
@mkiang
mkiang / collab_network.R
Last active May 10, 2019
Code to create your collaboration network in R
View collab_network.R
## Visualizing authorship networks: code for this blog post:
## https://mathewkiang.com/2018/06/17/my-collaboration-network/
library(scholar) # devtools::install_github("jkeirstead/scholar")
library(visNetwork)
library(tidyverse)
## Constants
MIN_TIME <- 60 * 5
MAX_TIME <- 60 * 30
PROJ_WEIGHT <- .8
View 01_get_data.R
## For blog post here: https://mathewkiang.com/2017/12/02/tldr-san-diego-weather-is-better-than-boston-weather/
## Imports ----
library(tidyverse)
library(GSODR)
library(ggmap)
## Define places we are interested in and google maps query ----
city_dict <- list(sandiego = "san diego airport",
View keybase.md

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:

@mkiang
mkiang / nejm_blog_post.R
Created Oct 9, 2017
NEJM and pre-print policy
View nejm_blog_post.R
## 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
@mkiang
mkiang / SIR.R
Created Jan 27, 2017
Sample SIR code for EPI 501 lab
View SIR.R
#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)), {
You can’t perform that action at this time.