I wanted to do a Monte Carlo simulation for some of the electoral districts in my state in the upcoming US midterms. My methodology essentially was as follows:
- I have a list of populations and vote percentages per district averaged over the last few elections
- To simulate one district, I generated one random number per voter and then checked if it was above or below the percentage of Democrats out of 100. If it was below, the vote was counted as a Democratic one, and as a Republican one if not. All of the votes are then tallied to see who wins the district.
- I then ran the simulation 100 times to generate a probability for which side would win the election in the election.
The thing that is confusing me is that I get much less variance than I expected. If the vote percentage is exactly 50/50, I get about 50% for the result of the election (as one would expect). But if I make it 49/51 democrat/republican, the republican wins 100% of the time. And if I make it 51/49 democrat/republican, the democrat wins 100% of the time. In real life, I would expect there to be more variance between these -- there should be at least some cases where a democrat could win in a 49/51 district, right?
Here's the MWE of my code, in Python:
def sim_district(population, percent_dem): votes = np.random.rand(population) dem = len([x for x in votes if x <= percent_dem])#tallies democrat votes rep = len([x for x in votes if x > percent_dem])#tallies republican votes if dem > rep: return True #democrat election win else: return False #republican election win demwins = 0 repwins = 0 for x in range(100): if(sim_district(87559, 0.51)): demwins += 1 #tallies democrat election wins else: repwins += 1 #tallies republican election wins print(demwins/(demwins + repwins)) #with an average democratic vote share of 51%, I get democrats winning this district 100 out of 100 times
I guess my question is: am I doing something wrong statistically/mathematically that's resulting in less variance in the results? Is this just the law of large numbers saying that simulating 80,000 votes in a 49/51 district will always result in the 51 winning (as opposed to simulating 10 or 100 votes)? Or is it just my expectation of 49/51 having more variance that is incorrect?
rbinom(100, 87559, .51)[R code] often exceed $8759/2,$ and shouldn't be. $\endgroup$