Skip to content

Instantly share code, notes, and snippets.

View mkiang's full-sized avatar

Mathew Kiang mkiang

View GitHub Profile
@mkiang
mkiang / tay_distribution.R
Created December 23, 2020 20:10
Taylor Swift Profanity Rate
## Imports ----
library(tidyverse)
library(genius)
library(here)
library(fs)
data("stop_words")
source("https://raw.githubusercontent.com/mkiang/airline_testing_strategies/master/code/mk_nytimes.R")
dir_create(here("data"))
@mkiang
mkiang / 01_pull_data.R
Created December 10, 2020 22:35
Collaboration network 2020 version
## Visualizing authorship networks: code for this blog post:
## https://mathewkiang.com/2020/12/10/my-collaboration-network-for-2010-to-2020-other-plots
## Imports ----
library(scholar) # remotes::install_github("jkeirstead/scholar")
library(tidyverse)
library(fs)
library(here)
## Constants ----
@mkiang
mkiang / c19_vs_topten.R
Last active November 23, 2020 00:57
Comparing COVID-19 daily deaths to 2018 top ten causes of death
library(tidyverse)
library(ggrepel)
library(zoo)
source("https://raw.githubusercontent.com/mkiang/opioid_geographic/master/code/mk_nytimes.R")
## 2018 top causes of death:
## https://www.cdc.gov/nchs/fastats/deaths.htm
nchs_df <- tribble(~ cause, ~ deaths_2018,
"1.Heart disease", 655381,
"2. Cancer", 599274,
@mkiang
mkiang / clean_tweets.R
Last active October 16, 2020 04:02
clean_tweets
## 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 February 15, 2020 00:57
Distribution of inter-peak days of the DJIA
library(tidyverse)
library(tidyquant)
source(
"https://raw.githubusercontent.com/mkiang/disproportionate_prescribing/master/code/mk_nytimes.R"
)
getSymbols("^DJI")
DJI <- as_tibble(DJI) %>%
mutate(
## 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 September 11, 2019 01:23
Skeleton code for the DGHS Workshop
## 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
@mkiang
mkiang / packages.R
Last active September 10, 2019 07:19
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 21:35
Code to create your collaboration network in 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
@mkiang
mkiang / 01_get_data.R
Created December 3, 2017 01:04
Weather plots
## 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",