Will Your Vote Decide the Next President?

Well, election season is in full swing – I tell you, just in case you haven't noticed from the obnoxiously aggressive TV ads and all of the yard signs. Having the right to vote is a wonderful opportunity that many fellow world citizens don't have. I have often wonder, however, how influential my singular vote can be. In this article, I'm going to attempt to address this question using one of my favorite tools – simulation!
I enjoy using simulation to solve problems – I wrote a series on simulation earlier this year – check it out if that seems interesting.
In this article, we'll cover these topics:
- Setting up the simulation
- Simulating your vote swinging your state election
- Simulating your state swinging the overall election
- Estimating the overall probability that your vote decides the president
- Why (I think) you should still vote
Setting up the simulation approach
Before we get into the simulation, we need to get everything set up. There are multiple elements for us to consider, so we'll go through them here.
What needs to happen for your vote to swing an election?
Two things need to happen for your vote to decide the presidential election – (1) your vote needs to be the deciding vote for your candidate in your state and (2) your state needs to provide your candidate with enough electoral votes to win the presidency. We will simulate these two separately and then combine them at the end.
What inputs do we need for the simulation?
We need multiple inputs and estimations for those inputs for our simulation:

Code setup
The code setup will have two classes that interact with each other. The first class will need an instance for each state. It will store methods and attributes related to individual state Elections – this class will be called ‘state.' The second class will take multiple state instances as attributes and will have other attributes and methods that are needed to simulate state and national election – this class will be called ‘simulate_elections.'
Simulation outputs
The Simulation will run state and/or national elections multiple times. The primary output will be the number of times that your vote swung the election (state or national, whichever one we are simulating at the time) out of the total number of simulations. We can interpret this as an estimate of the probability that your vote swings the national election.
Okay, with the simulation plan mapped out, let's get going on the code and then run some simulations!
Simulating your vote swinging a state
For the presidential election, most states have a "winner take all" popular vote for the president. This just means whoever gets the majority of the votes in the state wins the whole state. Maine and Nebraska are the exceptions, but for this article, we are going to just assume they act like the other states. They have a relatively small number of electoral votes – as long as we are not simulating the probability of a Maine or Nebraska resident swinging the election our estimates shouldn't be too far off (sorry Mainer and Nebraskan readers!).
Condition for your vote to swing the state
So, with the "winner take all" assumption, what has to happen for your vote to swing a state? It's actually pretty simple: your state needs to be in a perfect tie without your vote. Then, your vote comes in and breaks the tie for your candidate. Ok, now that we understand what needs to happen, let's figure out how we can estimate the probability of a perfect tie.
Estimating the probability of a popular vote tie with simulation
We are going to use the binomial probability distribution a lot in our simulation. This is a really cool distribution and I encourage you to check it out if you are not familiar with it. It is out of the scope of this article, so I'm not going to go into any details here.
When simulating, you often have to make at least a few simplifying assumptions. In this section, I'm going to make the assumption that there are only two candidates (Trump and Harris) and votes that don't go to one of them go to the other. In reality there are other candidates that will secure a couple of votes. For our purposes we are not going to factor them in though.
Right, let's get started with the simulation! There are multiple components that we need to consider when simulating the probability of your vote deciding your state's candidate.
We covered a comprehensive list of inputs in the last section. The inputs required for state simulation are a subset of that list and are below:
- The number of registered voters
- Voter turnout
- The probability of a voter voting for a specific candidate (Harris or Trump)
- Which candidate you are voting for
Simulating the number of voters
We first need to simulate the number of registered voters that will actually vote. To do this, we can use the binomial distribution. When simulating the number of voters, we put the number of registered voters as n and the historical voter turnout as the probability of success. This will give us a random number of voters based on the probabilities provided by the binomial distribution.

Let's do a quick example – I live in the great state of Texas, we have 17.2mm registered voters with a historical voter turnout of 58%. Here is what 10 simulations for number of voters would look like:

Using the binomial distribution sounds kind of complicated; why can't we just multiply registered voters by the historical voter turnout (for Texas, that would be 17.2mm*0.58)? The main problem with this approach is that for each of our simulated elections, we will have the exact same number of voters. This is a problem because of how we define winning a state. There must be a tie and our vote must break the tie. If the number of voters is always the same, the number of voters will always be odd or even. If the number is odd, we will never swing the election (because there can be no ties)! This will mess up our simulation – randomly simulating the number of registered voters avoids this trap, and is also more realistic.
Let's go through a quick example to explain why you can't swing an election if an odd number of voters turnout. Let's pick the odd number of 99 for our example. In a near perfect split, 49 people voted for your candidate and 50 did not. If you then vote for your candidate you have caused a tie, not a swing (and we aren't going to get into how ties are broken here)! If it is the other way, 50 for your candidate and 49 not. Your candidate has already won and your vote still doesn't swing the state. Either way, an odd number of voters before you show up to the poll will rob you of your power to swing the election!
Simulating the state election
Okay, we now have a way of simulating the number of votes that are cast. Our next task is to determine the probability of the popular vote in your state resulting in a tie. The first thing we need to do is rescale our poll numbers to accommodate our ‘two-party' assumption.
Let's go back to Texas and give an example of simulating the votes for Trump (republican). At the time of this writing, Trump is polling at 50% and Harris is polling at 46%. Because of our two-party assumption, we have to scale these two numbers so that they add up to 100%, otherwise our simulation will be off. The calculation to do this is simple – an illustration is below.

Alright, with our poll numbers rescaled, we have everything we need to estimate the probability of a tie. There are multiple ways of doing this, the easiest and most computationally efficient way is using the binomial probability mass function. It is essentially the opposite of the binomial probability distribution. For the binomial probability mass function, we input a number of successes (in this case, votes needed for a tie), total trials (number of votes cast) and the probability of success (scaled poll numbers) and it returns the probability of the specific outcome. The probability we get is the probability of an exact tie in our state!

Alright, we've gone through all of the logic to simulate a state's election. It's been a lot of design talk, let's write some Python code and finally simulate the probability of swinging an election in our state!
This article has excerpts from the code base in this repo : Simulation GitHub Link – feel free to modify and run your own simulations