Skip to content

Instantly share code, notes, and snippets.

@svmiller
svmiller / 1-dont-bring-boilerplate-centrist-talking-points-to-a-data-fight-claire.R
Created July 31, 2019 16:23
“fReE sTuFf fRoM tHe gOvErnMeNt dOeS nOt pLaY wElL iN tHe mIdWeSt.”
library(tidyverse)
library(stevemisc)
GSS <- readRDS("~/Dropbox/data/gss/GSS_spss-2018/gss7218.rds")
GSS %>%
mutate(regioncondensed = NA,
regioncondensed = ifelse(region == 8 | region == 9, "West", regioncondensed),
regioncondensed = ifelse(region == 3 | region == 4, "Midwest", regioncondensed),
regioncondensed = ifelse(region == 5 | region == 6 | region == 7, "South", regioncondensed),
@statwonk
statwonk / rootograms.R
Last active September 28, 2019 07:11
A gist that shows how a rootogram helps find that the zero-inflated negative binomial was the data generating mechanism.
# install.packages("countreg", repos="http://R-Forge.R-project.org")
# https://www.fromthebottomoftheheap.net/2016/06/07/rootograms/
# https://channel9.msdn.com/Events/useR-international-R-User-conferences/useR-International-R-User-2017-Conference/countreg-Tools-for-count-data-regression
library(countreg)
rzinbinom(3e3, size = 4, mu = 20, pi = 0.05) -> x
table(x)
hist(x, col = "orange")
rootogram(glm(x ~ 1, family = "poisson")) # zeros under fit
library(tidyverse)
library(scales)
data(diamonds)
diamonds %>%
filter(str_detect(cut, "Fair|Ideal")) %>%
ggplot(aes(price, carat)) +
geom_point(color = "skyblue", alpha = 0.5) +
facet_wrap(~cut, strip.position = "bottom") +
scale_x_continuous(labels = comma) +
library(tidyverse)
library(broom)
library(huxtable)
library(estimatr)
library(fabricatr)

set.seed(1234)
dat <- fabricate(
  N = 40,
@vankesteren
vankesteren / wine_plots.R
Last active April 21, 2021 09:58
Plots for a wine data visualisation
# script that outputs a graph
library(tidyverse)
library(firatheme)
wine <- read_delim("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data",
delim = ",",
col_names = c(
"Cultivar", "Alcohol", "Malic acid", "Ash", "Alcalinity of ash", "Magnesium",
"Total phenols", "Flavanoids", "Nonflavanoid phenols", "Proanthocyanins",
"Color intensity", "Hue", "OD280/OD315", "Proline"
)
@gaborcsardi
gaborcsardi / Pkgdown deploy from Travis.md
Last active November 17, 2021 13:41
Walkthrough: deploy a pkgdown site from Travis

Run usethis::use_pkgdown_travis()

usethis::use_pkgdown_travis()
✔ Setting active project to '/Users/gaborcsardi/works/ps'Adding 'docs/' to '.gitignore'Set up deploy keys by running `travis::use_travis_deploy()`Insert the following code in '.travis.yml'
  before_cache: Rscript -e 'remotes::install_cran("pkgdown")'
rm(list = ls())
library(tidyverse)
library(ggrepel)
covid <-
read_csv(file = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv")
covid <-
covid %>% filter(`Country/Region` != "Cruise Ship")
covid_long <-
@clauswilke
clauswilke / CFR.Rmd
Created March 17, 2020 02:57
COVID-19 Case Fatality Rate (CFR) by age
---
title: "COVID-19 Case Fatality Rate (CFR) by age"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```
@mikedecr
mikedecr / smartly-reinstall-R-pkgs.R
Last active November 30, 2021 20:42
When you're installing packages after a major R upgrade and you DON'T just want to get everything from CRAN.
# ----------------------------------------------------
# Installing packages for new R version.
# Michael DeCrescenzo
#
# Hi, I'm a political science PhD student looking for
# a data science/quantitative research/statistics job.
# Learn more at <mikedecr.github.io> and <github.com/mikedecr>
#
# This script deals with the following problem:
# I upgraded to new major version of R, & I want to reinstall packages.
library(RSelenium)
library(rvest)
library(tidyverse)
theme_set(theme_minimal(15) +
theme(plot.title.position = "plot",
plot.caption = element_text(color = "gray40", size = 8)))
url <- "https://www.nytimes.com/interactive/2020/us/coronavirus-us-cases.html"
rd <- rsDriver(browser = "chrome", chromever = "81.0.4044.69")