This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(tidyverse) | |
library(stringr) | |
library(lubridate) | |
library(ggrepel) | |
pres_terms <- | |
read_html("https://www.presidentsusa.net/presvplist.html") %>% | |
html_nodes("table") %>% | |
pluck(1) %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rvest) | |
pew_tables <- | |
read_html("http://www.pewforum.org/fact-sheet/changing-attitudes-on-gay-marriage/") %>% | |
html_nodes("table") %>% | |
html_table | |
gg_df <- | |
pew_tables[-1] %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
library(tidyverse) | |
fate <- | |
function(stopping_rule) { | |
# the order you meet people | |
the_shuffle = sample(1:100) | |
# everybody you've met | |
the_exes <- the_shuffle[1:stopping_rule] | |
# how good was the best so far |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script shows how to make blocks with blockTools, then randomize with randomizr | |
# Alex Coppock | |
# declaredesign.org | |
library(randomizr) | |
library(blockTools) | |
library(tidyverse) | |
# Prepare data with dplyr + tidyr ----------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gelman and Hill 2007: Chapter 3 Regression Examples | |
# Using ggplot and estimatr | |
rm(list = ls()) | |
# Uncomment to install | |
# install.packages("ggplot2") | |
# install.packges("haven") | |
# install.pacakges("estimatr") | |
library(ggplot2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DeclareDesign) | |
proportion_shy <- .06 | |
population <- declare_population( | |
N = 5000, | |
# true trump vote (unobservable) | |
truthful_trump_vote = draw_binary(.45, N), | |
# shy voter (unobservable) | |
shy = draw_binary(proportion_shy, N), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
library(tidyverse) | |
library(estimatr) | |
N <- 1000 | |
dat <- | |
data.frame( | |
Y = rnorm(N), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fabricatr) | |
library(randomizr) | |
library(estimatr) | |
library(ggplot2) | |
dat <- fabricate(N = 200, | |
Z = complete_ra(N, conditions = c("Control", "Treatment")), | |
X = sample(c("A", "B"), size = N, replace = TRUE), | |
Y = (X == "A") + (Z == "Treatment") + rnorm(N, sd = 1 + (Z == "Treatment"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DeclareDesign) | |
library(tidyverse) | |
set.seed(343) | |
design <- | |
declare_population(N = N) + | |
declare_potential_outcomes( | |
# Difference 1: 0.6 - 0.4 = 0.2 | |
Y_Z_1 = draw_binary(prob = 0.4, N = N), |
NewerOlder