2
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ I don't see what you are doing or why, so probably shouldn't comment, but seems you're surprised that rbinom(100, 87559, .51) [R code] often exceed $8759/2,$ and shouldn't be. $\endgroup$
    – BruceET
    Jul 6, 2022 at 23:13
  • 1
    $\begingroup$ to be honest, I hadn't realized that what I was doing was actually a binomial distribution. What I was trying to find was basically a way to get a win probability given average vote shares; seems like this was the wrong way to go about doing that. $\endgroup$
    – evamvid
    Jul 6, 2022 at 23:15

1 Answer 1

2
$\begingroup$

There is probably nothing wrong in your code.

I have to admit I didn't check the code itself. We are at CrossValidated, not Code Review, after all, so I'll argue statistically.

What you are looking for is the probability that sampling $80,000$ votes with a success probability of $0.49$ gives less than half successes, or at most $39,999$. This is simply the cumulative distribution function (CDF) of the binomial distribution with parameters $n=80,000$ and $p=0.49$, evaluated for $k=39,999$. In Python:

from scipy.stats import binom
binom.cdf(39999,80000,0.49)
# 0.9999999921577211

It is practically certain that your voting will yield the results you have observed.

Conclusion: people's political preferences and voting is probably not very well described by a simple binomial distribution. But now we are in Politics territory...

$\endgroup$
3
  • $\begingroup$ This is a good explanation of the code. But it is difficult to see how you can draw any conclusions at all about people or voting from this analysis. $\endgroup$
    – whuber
    Jul 6, 2022 at 15:09
  • $\begingroup$ @whuber: as I wrote, that's probably a question for Politics.SE. But I would say that if the simple binomial model with underlying propensities to vote one way or another were true, then I personally would expect far less changes from one election to the next. Then again, that intuition of mine may well be mistaken. $\endgroup$ Jul 6, 2022 at 15:13
  • 1
    $\begingroup$ From one election to the next, the proportions of voters change--for all sorts of reasons. This analysis therefore concerns, at best, a single election. $\endgroup$
    – whuber
    Jul 6, 2022 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.