Created
November 9, 2012 16:14
-
-
Save tvladeck/4046576 to your computer and use it in GitHub Desktop.
Evaluation of 538's performance
This file contains 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('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