diff --git a/README.md b/README.md index 289b080..be9424d 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,98 @@ -# Nuño's deads imple election simulator +# Nuño's simple electoral college simulator -## First round: just consider the base rates. +## About + +This is a simple model of the US electoral college. It aims to be conceptually simple and replicable. Currently, it incorporates data from the electoral history in each state, since the 2000 election, as well as polls, if they exist. + +Other projects, like [538](https://en.wikipedia.org/wiki/FiveThirtyEight), [Nate Silver's substack](https://www.natesilver.net/) or [Gelman's model](https://github.com/TheEconomist/us-potus-model) are to this project as a sportscar is to a walking stick. They are much more sophisticated, and probably more accurate. However, they are also more difficult to understand and to design. + +## How to run + +### Prerequisites + +This model is written in go, an elegant language developed by Rob Pike, Ken Thompson and Robert Griesemer at Google. You can find installation instructions for all major platforms [here](https://go.dev/dl/). The website this + +Once you have go and git, you install the model with + +``` +git clone [repo] +cd 2024-election-modelling +go install +``` + +And run the model with: + +``` +go run main.go +``` + +In addition, on Linux you can update the polls with make: + +``` +make polls +``` + +## What stories does the model tell? + +### The naïve baserate story + +Consider Ohio. Bush won the state in 2000 and 2004, Obama in 2008 and 2012, and Trump again in 2016 and 2020. The base rate, the historical frequency for republicans in Ohio is therefore 4/6. + +A straightforward way of getting at a probability of an electoral college win is to just take the historical frequency for each state, and sample from it many times, and then build up the different electoral college results from those samples. + +If we do so, however, Republicans end up with only a 25% chance of winning the 2024 election. + +Why is this? Well, consider the number of electoral college votes in the last few elections: + +| Year | Republican electoral college votes | Democrat electoral college votes | +| ---- | --- | --- | +| 2000 | 271 | 266 | +| 2004 | 286 | 251 | +| 2008 | 173 | 365 | +| 2012 | 206 | 332 | +| 2016 | 304 | 227 | +| 2020 | 232 | 232 | + +Essentially, Obama won by much more than Bush, Trump or Biden. But our naïve model doesn't see that those results were correlated. + +So the story here is that our model is not very sophisticated. But another might be that Obama was much more popular than Biden, and if Democrats can tap into that again, they will do better. + +### The polls story + +If we only look at polls (and use baserates when there are no polls—which happens for states like Alabama, which lean strongly towards one party already), this time the Republicans win by a mile: with 95% probability. + +What's happening here is that: + +- There aren't that many polls yet +- For the polls that do exist, Trump polling very well in Pennsylvania, Wisconsin, Arizona, Michigan, Florida, Nevada, Georgia, North Carolina + - Trump is also polling decently in Minessota; Biden is polling well in Colorado +- In part, this is because Biden is just [unpopular](https://projects.fivethirtyeight.com/biden-approval-rating/), or at least more than [Trump](https://projects.fivethirtyeight.com/polls/favorability/donald-trump/) +- In part though, polls currently also ask about the third party vote: for Robert F. Kennedy, Kayne West and Jill Stein (Green party). + - In a normal democracy, like in Spain, a protest party could amass some electors, and use them as bargaining chips to govern together with one of the other major parties. For instance, this is what happened with Ciudadanos in Spain. Perhaps third parties performing strongly could conceivably, create pressure to reform the US electoral system. + - In the US, with the system as currently exists, these votes seem to favour Trump. + +## Roadmap + +### To do + +- [ ] Print states & polls separately +- [ ] Add graphs +- [ ] Consider conditional probabilities + - See how other models account for the correlation +- [ ] Add uncertainty using Laplace's law of succession? + - Maybe only do this for contested states? Alabama is not going to turn Democratic? +- [ ] Exclude partisan polls => not that many of them +- [ ] Histogram distributions of electoral college votes + +### Done + +Incorporate base rates: - [x] Get past electoral college results since 2000 - [x] Get number of electors for each state with the new census - [x] Combine the two to get an initial base rates analysis -This initial approach gives a 25% to republicans winning in the 2024 election. Why is this? Well, consider the number of electoral college votes: - -| Year | Republican electoral college votes | -| ---- | --- | -| 2000 | 271 | -| 2004 | 286 | -| 2008 | 173 | -| 2012 | 206 | -| 2016 | 304 | -| 2020 | 232 | - -| Year | Democrat electoral college votes -| ---- | --- | -| 2000 | 266 | -| 2004 | 251 | -| 2008 | 365 | -| 2012 | 332 | -| 2016 | 227 | -| 2020 | 232 | - -When Democrats won with Obama, they won by a lot, whereas when Republicans won with Bush and Trump, they won by a smaller amount. Or, in other words, this initial approach *doesn't take into account that states are correlated*. - -Remedy: consider the conditional probabilities? But how? Or, relax assumptions using Laplace's law? - -- [ ] Consider conditional probabilities - - See how other models account for the correlation -- [ ] Add uncertainty using Laplace's law of succession? - - Maybe only do this for contested states? Alabama is not going to turn Democratic? - -## Second round: just consider polls +Consider polls: - [x] Download and format - [x] Read @@ -46,17 +103,7 @@ Remedy: consider the conditional probabilities? But how? Or, relax assumptions u - [x] Another extreme: Aggregate very naïvely, add up all samples together? - [x] Aggregate polls? - [x] Exclude polls older than one month? -- [ ] Exclude partisan polls -- [ ] ... -https://stats.stackexchange.com/questions/274211/calculating-the-probability-of-someone-winning-from-a-poll +General -This time, the republicans win by a mile. - -What is happening? -- Trump polling ok in Minessota, -- No polls in Iowa yet -- Trump polling very well in Pennsylvania, Wisconsin, Arizona, Michigan, Florida, Nevada, Georgia, North Carolina - - In part because of the Kennedy/West/Stein vote. -- Biden is poling well in Colorado -- Not that many polls yet, in general +- [x] Work on README diff --git a/main.go b/main.go index 9f8a048..2e69ff9 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ type Poll struct { /* Globals */ var r = rand.New(rand.NewPCG(uint64(100), uint64(2224))) -var dev = true +var dev = false /* Load data from csvs */ func readStates() ([]State, error) { @@ -321,7 +321,8 @@ func sampleFromState(state State) VotesForEachParty { if dev { fmt.Printf("\n\tAggregating all polls naïvely says chance of R win: %f", p_republican_according_to_polls) } - p_republican = 0.75*p_republican_according_to_polls + 0.25*p_baserate_republican + weight_polls := 1.0 + p_republican = weight_polls*p_republican_according_to_polls + (1.0-weight_polls)*p_baserate_republican } @@ -363,7 +364,7 @@ func main() { return } - n_sims := 10 + n_sims := 100_000 p_republicans := 0.0 for i := 0; i < n_sims; i++ {