Skip to content

Instantly share code, notes, and snippets.

David Robinson dgrtwo

Block or report user

Report or block dgrtwo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View underpowered-simulation.R
# Code behind this tweet:
# https://twitter.com/drob/status/1126988304090574848
library(tidyverse)
library(broom)
t_tests <- crossing(pi0 = .75,
effect_size = .25,
trial = 1:10000,
@dgrtwo
dgrtwo / dice-rolls.R
Created Feb 25, 2019
Animation of die rolls
View dice-rolls.R
# Code behind this tweet: https://twitter.com/drob/status/1100182329350336513
library(tidyverse)
library(gganimate)
# Setup
options(gganimate.nframes = 200)
set.seed(2019)
simulation <- tibble(roll = 1:10000) %>%
mutate(result = sample(6, n(), replace = TRUE)) %>%
View by_tag_year.csv
We can't make this file beautiful and searchable because it's too large.
year,tag,number,year_total
2008,.htaccess,54,58390
2008,.net,5910,58390
2008,.net-2.0,289,58390
2008,.net-3.5,319,58390
2008,.net-4.0,6,58390
2008,.net-assembly,3,58390
2008,.net-core,1,58390
2008,2d,42,58390
View cross validation
library(modelr)
library(tidyverse)
library(broom)
mtcars %>%
crossv_kfold(k = 10) %>%
mutate(model = map(train, ~ lm(mpg ~ wt, .)),
result = map2(model, test, ~ augment(.x, newdata = .y))) %>%
unnest(result)
@dgrtwo
dgrtwo / gist:39af4512dff5b7357b534a04a971405d
Created Mar 14, 2018
Early attempt at creating materialized SQL views from dplyr
View gist:39af4512dff5b7357b534a04a971405d
separate_sql <- function(expression) {
s <- paste(deparse(expression), collapse = "\n")
s <- stringr::str_replace(s, "%>%", "%>%\n ")
s <- stringr::str_split(s, "\n")[[1]]
val <- eval(expression)
list(expression = expression,
dplyr_code = s,
sql = as.character(dbplyr:::remote_query(val)),
View file663a44ec31fa.R
library(purrr)
transition_mc <- function(steps, start, mat) {
i <- seq_len(nrow(mat))
transition <- ~ sample(i, 1, prob = (i == .) %*% mat)
accumulate(seq_len(steps), transition, .init = start)
}
View file663a4c3ed972.R
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(purrr)
transition_mc <- function(steps, start, mat) {
i <- seq_len(nrow(mat))
@dgrtwo
dgrtwo / mnist_pairs.R
Created May 31, 2017
Comparing pairs of MNIST digits based on one pixel
View mnist_pairs.R
library(tidyverse)
# Data is downloaded from here:
# https://www.kaggle.com/c/digit-recognizer
kaggle_data <- read_csv("~/Downloads/train.csv")
pixels_gathered <- kaggle_data %>%
mutate(instance = row_number()) %>%
gather(pixel, value, -label, -instance) %>%
extract(pixel, "pixel", "(\\d+)", convert = TRUE)
@dgrtwo
dgrtwo / month_tag.csv
Created May 11, 2017
Number of Stack Overflow questions asked about each tag per month; data behind the Stack Overflow Trends tool
View month_tag.csv
We can't make this file beautiful and searchable because it's too large.
Year,Month,Questions,Tag,MonthTotal,TagTotal
2008,8,4,.htaccess,3929,57155
2008,9,12,.htaccess,14543,57155
2008,10,10,.htaccess,14951,57155
2008,11,16,.htaccess,12967,57155
2008,12,12,.htaccess,12324,57155
2009,1,24,.htaccess,16152,57155
2009,2,35,.htaccess,17889,57155
2009,3,43,.htaccess,20785,57155
@dgrtwo
dgrtwo / code-faces.R
Last active Apr 14, 2017
geom_vase vs geom_faces
View code-faces.R
library(readr)
library(dplyr)
library(ggplot2)
faces <- read_csv("faces.csv")
vase <- bind_rows(select(faces, x = x1, y),
select(faces, x = x2, y) %>% arrange(y))
faces %>%
You can’t perform that action at this time.