Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathew Kiang mkiang

View GitHub Profile
@mkiang
mkiang / tay_distribution.R
Created Dec 23, 2020
Taylor Swift Profanity Rate
View tay_distribution.R
## 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 Dec 10, 2020
Collaboration network 2020 version
View 01_pull_data.R
## 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 Nov 23, 2020
Comparing COVID-19 daily deaths to 2018 top ten causes of death
View c19_vs_topten.R
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,
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",