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
data { | |
int n_respondents; | |
int n_choices; | |
int n_vaccines; | |
int responses[n_choices]; | |
int respondent[n_choices]; | |
int vaccine[n_choices]; | |
vector[n_choices] money; | |
} |
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) | |
set.seed(1) | |
sims <- map(1:200, function(x) { | |
intercept = -runif(1)/2 | |
beta_male = runif(1)/4 | |
beta_smoker = runif(1)/4 | |
dat = |
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
set.seed(1) | |
margins <- c() | |
for(i in 1:1000) { | |
sim <- c() | |
for(j in 1:10) { | |
experts <- rbeta(1000, 1.5, 1) | |
expert_votes <- runif(1000) < experts | |
uninformed <- runif(1000) < .5 | |
sim[j] = sum(expert_votes) + sum(uninformed) - sum(!expert_votes)-sum(!uninformed) |
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
p_over_time = | |
read_csv("https://cdn.economistdatateam.com/us-2020-forecast/data/president/electoral_college_probability_over_time.csv") %>% | |
# convert win probabilites to logit scale | |
mutate(win_prob_logit = boot::logit(win_prob)) %>% | |
# look only at one side | |
filter(party == "democratic") | |
# take the variance of the differences |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
less_uncertainty_smaller_step <- | |
.25 * (1:1000 %>% map(~ run_simulation(initial = 1 - 0.1)) %>% unlist %>% mean) + | |
.5 * (1:1000 %>% map(~ run_simulation(initial = 1)) %>% unlist %>% mean) + | |
.25 * (1:1000 %>% map(~ run_simulation(initial = 1 + 0.1)) %>% unlist %>% mean) | |
greater_uncertainty_bigger_step <- | |
.05 * (1:1000 %>% map(~ run_simulation(initial = 1 - 3, step_size = 0.5)) %>% unlist %>% mean) + | |
.1 * (1:1000 %>% map(~ run_simulation(initial = 1 - 2, step_size = 0.5)) %>% unlist %>% mean) + |
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
# from IPUMS | |
# includes 1950 forward | |
# includes individual income | |
# sex | |
# age | |
raw_data <- data.table::fread("~/Downloads/usa_00008.csv") | |
library(tidyverse) |
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(foreach) | |
library(doParallel) | |
library(tidyverse) | |
library(magrittr) | |
registerDoParallel(40) | |
runs <- 100 | |
N_test <- c(250, 300, 350, 400, 500, 600) # sample in each group |
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
cat orders_2018-05-01.csv | head | sed -e 's/,,/, ,/g' | column -s, -t | less -#5 -N -S |
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
set.seed(20180226) | |
block_mining_times <- rpois(1000, 10) # lambda = 10 | |
max_time <- sum(block_mining_times) | |
cumulative_times <- cumsum(block_mining_times) | |
rand_times <- runif(1000, min = 0, max = max_time) | |
deltas_between_blocks <- | |
rand_times %>% | |
sapply(function(t){ |
NewerOlder