Skip to content

Instantly share code, notes, and snippets.

@tvladeck
tvladeck / vaccine_threshold_price.stan
Created May 3, 2021
vaccine threshold price model
View vaccine_threshold_price.stan
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;
}
@tvladeck
tvladeck / algo-fairness.R
Created Apr 28, 2021
simulation of algorithmic fairness
View algo-fairness.R
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 =
View uninformed-voter-sim.R
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)
@tvladeck
tvladeck / economist-check.R
Created Jul 18, 2020
economist forecast consistency check
View economist-check.R
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
View KF.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View incorporating_measurement.R
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) +
@tvladeck
tvladeck / income-inequality.R
Created Mar 18, 2019
income inequality analysis
View income-inequality.R
# from IPUMS
# includes 1950 forward
# includes individual income
# sex
# age
raw_data <- data.table::fread("~/Downloads/usa_00008.csv")
library(tidyverse)
@tvladeck
tvladeck / max-diff-power-analysis.R
Created Aug 21, 2018
Computing power of covariate in max diff experience
View max-diff-power-analysis.R
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
View explore_csv.sh
cat orders_2018-05-01.csv | head | sed -e 's/,,/, ,/g' | column -s, -t | less -#5 -N -S
View bitcoin_hashrate.R
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){