Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created November 9, 2012 16:14
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/4046576 to your computer and use it in GitHub Desktop.
Save tvladeck/4046576 to your computer and use it in GitHub Desktop.
Evaluation of 538's performance
library('hash')
states = hash()
.set(states,
"CO" = 0.8, "FL" = 0.5, "IA" = 0.84, "NBC2" = 0.87,
"NH" = 0.85, "NC" = 0.74, "VA" = 0.79, "AZ" = 0.98,
"MNC2" = 0.95, "MI" = 0.99, "MT" = 0.98, "NV" = 0.93,
"NM" = 0.99, "OH" = 0.91, "PA" = 0.99, "WI" = 0.97)
run.simulation <- function()
{
num.wrong <- 0
for (key in keys(states))
{
rand <- runif(1)
if(rand > states[[key]]) num.wrong <- num.wrong + 1
}
return(num.wrong)
}
number.wrong <- c()
for(i in 1:10000) results <- append(number.wrong, run.simulation())
hist(number.wrong)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment