Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created April 9, 2021 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvladeck/905b0b02aa1a322f7e7725ade3c54afe to your computer and use it in GitHub Desktop.
Save tvladeck/905b0b02aa1a322f7e7725ade3c54afe to your computer and use it in GitHub Desktop.
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)
}
margins[i] = mean(sim)
}
n_uninformed = 1:1000
plot(margins, pch = 4, xlab = "Number of Uninformed Voters",
ylab = "Vote margin")
summary(lm(margins ~ n_uninformed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment