First, we set all of known quanities as given by the problem.
sample.size = 1000
republican= .48
democrat = .52
Then, for ease of accounting, we treat Republicans as 0s and Democrats as 1. Then, we sample a population with the requisite weights, sum up that vector, and repeat 100 times.
# 0 is republican, 1 is democrat
rounds <- c()
for (i in 1:100){
rounds[i]<-sum(sample(c(0, 1), size = sample.size, replace = TRUE, prob = c(republican, democrat)))/sample.size
}
length(rounds[rounds<.50])/1000
## [1] 0.009
In the first case, our simulation incorrectly predicted the winner 1% of the time.
republican.2 = 49
democrat.2 = 51
rounds <- c()
for (i in 1:100){
rounds[i]<-sum(sample(c(0, 1), size = sample.size, replace = TRUE, prob = c(republican.2, democrat.2)))/sample.size
}
length(rounds[rounds<.50])/100
## [1] 0.23
In the second case, our simulation incorrectly predicted the winner 22% of the time.
sample.size.2 = 3000
rounds <- c()
for (i in 1:100){
rounds[i]<-sum(sample(c(0, 1), size = sample.size.2, replace = TRUE, prob = c(republican.2, democrat.2)))/sample.size.2
}
length(rounds[rounds<.50])/100
## [1] 0.08
sort(rounds)
## [1] 0.4853333 0.4896667 0.4910000 0.4920000 0.4920000 0.4926667 0.4960000
## [8] 0.4983333 0.5000000 0.5003333 0.5003333 0.5003333 0.5003333 0.5006667
## [15] 0.5020000 0.5023333 0.5026667 0.5026667 0.5030000 0.5033333 0.5033333
## [22] 0.5033333 0.5033333 0.5036667 0.5036667 0.5046667 0.5050000 0.5050000
## [29] 0.5050000 0.5050000 0.5053333 0.5060000 0.5063333 0.5063333 0.5063333
## [36] 0.5063333 0.5066667 0.5070000 0.5070000 0.5073333 0.5073333 0.5073333
## [43] 0.5073333 0.5076667 0.5080000 0.5083333 0.5086667 0.5090000 0.5093333
## [50] 0.5100000 0.5103333 0.5103333 0.5110000 0.5110000 0.5116667 0.5116667
## [57] 0.5116667 0.5120000 0.5123333 0.5123333 0.5123333 0.5126667 0.5126667
## [64] 0.5130000 0.5133333 0.5133333 0.5136667 0.5143333 0.5150000 0.5150000
## [71] 0.5153333 0.5153333 0.5156667 0.5160000 0.5166667 0.5170000 0.5170000
## [78] 0.5170000 0.5173333 0.5173333 0.5176667 0.5176667 0.5190000 0.5190000
## [85] 0.5200000 0.5203333 0.5203333 0.5203333 0.5213333 0.5213333 0.5213333
## [92] 0.5216667 0.5223333 0.5230000 0.5256667 0.5266667 0.5266667 0.5270000
## [99] 0.5273333 0.5330000
Even with a larger sample size, the smaller gap between the parties resulted in our simulation incorrectly predicted the winner 8% of the time.