Skip to content

Commit

Permalink
table descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wmentrekin committed Oct 29, 2020
1 parent 24a0226 commit 1a00414
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 106 deletions.
6 changes: 0 additions & 6 deletions Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ def write_results():
file.close()
file = open("tables/closest_margins.html", 'w')
file.write("""<HTML> <body>
<h2>Closest Projected Margins of Victory</h2>
<table class="center">
{0}
</table>
Expand Down Expand Up @@ -527,7 +526,6 @@ def write_results():
file.close()
file = open("tables/lopsided_margins.html", 'w')
file.write("""<HTML> <body>
<h2>Most Lopsided Projected Margins of Victory</h2>
<table class="center">
{0}
</table>
Expand Down Expand Up @@ -564,7 +562,6 @@ def write_results():
file.close()
file = open("tables/tossups.html", 'w')
file.write("""<HTML> <body>
<h2>Projected Tossup States</h2>
<table class="center">
{0}
</table>
Expand Down Expand Up @@ -608,7 +605,6 @@ def write_results():
file.close()
file = open("tables/flips.html", 'w')
file.write("""<HTML> <body>
<h2>Projected Flipped States</h2>
<table class="center">
{0}
</table>
Expand Down Expand Up @@ -641,7 +637,6 @@ def write_results():
file.close()
file = open("tables/results.html", 'w')
file.write("""<HTML> <body>
<h2>Full Results</h2>
<table class="center">
{0}
</table>
Expand All @@ -662,7 +657,6 @@ def write_results():
file.close()
file = open("tables/win_prob.html", 'w')
file.write("""<HTML> <body>
<h2>Win Probabilities & Expected Electoral Votes</h2>
<table class="center">
{0}
</table>
Expand Down
86 changes: 60 additions & 26 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ <h1>2020 United States Presidential Election Model</h1>
</p>
</header>

<h1>Methods</h1>

<section>
<h1>Methods</h1>
<p>
<b>Disclaimer</b>: This model is not an official prediction. I am in no way attesting to its potential accuracy or claiming it to be correct.
The point of this project was to be a learning exercise for me as well as an outlet for an interest of mine. The data you see here is purely a result
Expand Down Expand Up @@ -103,33 +104,66 @@ <h1>Methods</h1>

<h1>Results</h1>

<div class="container">
<h2>Average Margin of Victory</h2>
<img src="results/map.png" alt="Average Margin of Victory" width="800" height="536">
</div>

<div class="container">
<div class="row">
<div class="col">
<div w3-include-html="tables/closest_margins.html"></div>
</div>
<div class="col">
<div w3-include-html="tables/lopsided_margins.html"></div>
</div>
<div class="col">
<div w3-include-html="tables/tossups.html"></div>
</div>
<div class="col">
<div w3-include-html="tables/flips.html"></div>
</div>
<div class="col">
<div w3-include-html="tables/results.html"></div>
</div>
<div class="col">
<div w3-include-html="tables/win_prob.html"></div>
<section>
<div class="container">
<h2>Average Margin of Victory</h2>
<p>
In the model, there are 10,000 scenarios that were run. This map visualizes the average margin of victory of either candidate in each state on a color scale.
States in blue are projected to be won by former Vice President Joe Biden, whereas states in red are projected to be won by incumbent President Donald Trump.
The darker the color of the state, the larger the margin expected for the winning candidate.
</p>
<img src="results/map.png" alt="Average Margin of Victory" width="800" height="536">
</div>
<div class="container">
<div class="row">
<div class="col">
<h2>Closest Projected Margins of Victory</h2>
<p>
The table below shows states where the winner is projected to win by less than 10% of the vote.
</p>
<div w3-include-html="tables/closest_margins.html"></div>
</div>
<div class="col">
<h2>Most Lopsided Projected Margins of Victory</h2>
<p>
The table below shows states where the winner is projected to win by more than 25% of the vote.
</p>
<div w3-include-html="tables/lopsided_margins.html"></div>
</div>
<div class="col">
<h2>Projected Tossup States</h2>
<p>
The table below shows states where both candidates have at least a 40% chance of winning.
</p>
<div w3-include-html="tables/tossups.html"></div>
</div>
<div class="col">
<h2>Projected Flipped States</h2>
<p>
This table below shows states where the projected winner in 2020 is from a different party than the one which won in 2016.
</p>
<div w3-include-html="tables/flips.html"></div>
</div>
<div class="col">
<h2>Full Results</h2>
<p>
The table below shows the full results of the model in all 50 states and the District of Columbia.
Below you can see, for each state, the projected vote share for either candidate, the chance of victory, and the projected vote margin from the model.
</p>
<div w3-include-html="tables/results.html"></div>
</div>
<div class="col">
<h2>Win Probabilities & Expected Electoral Votes</h2>
<p>
The table below represents the expected value of electoral votes and chance of winning the electoral college for either candidate.
The expected value of electoral votes was found by multiplying both candidates' probabilities of winning in every state by the electoral votes of every state.
The chances of victory are simply a proportion of the scenarios in my model in which either candidate wins the electoral college.
</p>
<div w3-include-html="tables/win_prob.html"></div>
</div>
</div>
</div>
</div>
</section>

<h1>Insights</h1>

Expand Down
Binary file modified results/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions results/win_prob.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Expected Electoral Votes: Joe Biden,327
Expected Electoral Votes: Donald Trump,211
Chance of Victory: Joe Biden,97.64%
Chance of Victory: Donald Trump,2.36%
Chance of Victory: Joe Biden,97.74%
Chance of Victory: Donald Trump,2.26%
33 changes: 16 additions & 17 deletions tables/closest_margins.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<HTML> <body>
<h2>Closest Projected Margins of Victory</h2>
<table class="center">
<tr><td>State</td><td>Projected Margin</td><td>Projected Winner</td></tr>
<tr><td>Arizona</td><td>0.57%</td><td>Joe Biden</td></tr>
<tr><td>Georgia</td><td>1.19%</td><td>Donald Trump</td></tr>
<tr><td>North Carolina</td><td>1.19%</td><td>Joe Biden</td></tr>
<tr><td>Nevada</td><td>1.25%</td><td>Joe Biden</td></tr>
<tr><td>Ohio</td><td>1.26%</td><td>Donald Trump</td></tr>
<tr><td>Florida</td><td>2.06%</td><td>Joe Biden</td></tr>
<tr><td>Wisconsin</td><td>2.64%</td><td>Joe Biden</td></tr>
<tr><td>Texas</td><td>3.47%</td><td>Donald Trump</td></tr>
<tr><td>Michigan</td><td>4.01%</td><td>Joe Biden</td></tr>
<tr><td>Pennsylvania</td><td>4.05%</td><td>Joe Biden</td></tr>
<tr><td>Iowa</td><td>4.46%</td><td>Donald Trump</td></tr>
<tr><td>North Carolina</td><td>0.41%</td><td>Joe Biden</td></tr>
<tr><td>Arizona</td><td>0.58%</td><td>Joe Biden</td></tr>
<tr><td>Ohio</td><td>1.1%</td><td>Donald Trump</td></tr>
<tr><td>Georgia</td><td>1.13%</td><td>Donald Trump</td></tr>
<tr><td>Nevada</td><td>1.24%</td><td>Joe Biden</td></tr>
<tr><td>Florida</td><td>2.0%</td><td>Joe Biden</td></tr>
<tr><td>Wisconsin</td><td>2.61%</td><td>Joe Biden</td></tr>
<tr><td>Texas</td><td>3.48%</td><td>Donald Trump</td></tr>
<tr><td>Michigan</td><td>4.03%</td><td>Joe Biden</td></tr>
<tr><td>Pennsylvania</td><td>4.07%</td><td>Joe Biden</td></tr>
<tr><td>Iowa</td><td>4.47%</td><td>Donald Trump</td></tr>
<tr><td>Virginia</td><td>4.84%</td><td>Joe Biden</td></tr>
<tr><td>Minnesota</td><td>5.03%</td><td>Joe Biden</td></tr>
<tr><td>New Hampshire</td><td>5.48%</td><td>Joe Biden</td></tr>
<tr><td>South Carolina</td><td>7.62%</td><td>Donald Trump</td></tr>
<tr><td>Alaska</td><td>8.19%</td><td>Donald Trump</td></tr>
<tr><td>Colorado</td><td>9.78%</td><td>Joe Biden</td></tr>
<tr><td>Minnesota</td><td>4.91%</td><td>Joe Biden</td></tr>
<tr><td>New Hampshire</td><td>5.39%</td><td>Joe Biden</td></tr>
<tr><td>South Carolina</td><td>7.58%</td><td>Donald Trump</td></tr>
<tr><td>Alaska</td><td>8.11%</td><td>Donald Trump</td></tr>
<tr><td>Colorado</td><td>9.92%</td><td>Joe Biden</td></tr>
</table>
</body>
</HTML>
13 changes: 6 additions & 7 deletions tables/flips.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<HTML> <body>
<h2>Projected Flipped States</h2>
<table class="center">
<tr><td>State</td><td>2016 Winner</td><td>2016 Margin</td><td>2020 Projected Winner</td><td>2020 Projected Margin</td></tr>
<tr><td>North Carolina</td><td>Donald Trump</td><td>3.66%</td><td>Joe Biden</td><td>1.19%</td></tr>
<tr><td>Pennsylvania</td><td>Donald Trump</td><td>0.72%</td><td>Joe Biden</td><td>4.05%</td></tr>
<tr><td>Michigan</td><td>Donald Trump</td><td>0.22%</td><td>Joe Biden</td><td>4.01%</td></tr>
<tr><td>Arizona</td><td>Donald Trump</td><td>3.55%</td><td>Joe Biden</td><td>0.57%</td></tr>
<tr><td>Wisconsin</td><td>Donald Trump</td><td>0.76%</td><td>Joe Biden</td><td>2.64%</td></tr>
<tr><td>Florida</td><td>Donald Trump</td><td>1.2%</td><td>Joe Biden</td><td>2.06%</td></tr>
<tr><td>Pennsylvania</td><td>Donald Trump</td><td>0.72%</td><td>Joe Biden</td><td>4.07%</td></tr>
<tr><td>Michigan</td><td>Donald Trump</td><td>0.22%</td><td>Joe Biden</td><td>4.03%</td></tr>
<tr><td>Arizona</td><td>Donald Trump</td><td>3.55%</td><td>Joe Biden</td><td>0.58%</td></tr>
<tr><td>North Carolina</td><td>Donald Trump</td><td>3.66%</td><td>Joe Biden</td><td>0.41%</td></tr>
<tr><td>Wisconsin</td><td>Donald Trump</td><td>0.76%</td><td>Joe Biden</td><td>2.61%</td></tr>
<tr><td>Florida</td><td>Donald Trump</td><td>1.2%</td><td>Joe Biden</td><td>2.0%</td></tr>
</table>
</body>
</HTML>
9 changes: 4 additions & 5 deletions tables/lopsided_margins.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<HTML> <body>
<h2>Most Lopsided Projected Margins of Victory</h2>
<table class="center">
<tr><td>State</td><td>Projected Margin</td><td>Projected Winner</td></tr>
<tr><td>District of Columbia</td><td>86.79%</td><td>Joe Biden</td></tr>
<tr><td>Wyoming</td><td>46.3%</td><td>Donald Trump</td></tr>
<tr><td>West Virginia</td><td>42.09%</td><td>Donald Trump</td></tr>
<tr><td>Oklahoma</td><td>36.4%</td><td>Donald Trump</td></tr>
<tr><td>North Dakota</td><td>35.78%</td><td>Donald Trump</td></tr>
<tr><td>Massachusetts</td><td>32.48%</td><td>Joe Biden</td></tr>
<tr><td>Massachusetts</td><td>32.46%</td><td>Joe Biden</td></tr>
<tr><td>Hawaii</td><td>32.2%</td><td>Joe Biden</td></tr>
<tr><td>Idaho</td><td>31.79%</td><td>Donald Trump</td></tr>
<tr><td>California</td><td>29.5%</td><td>Joe Biden</td></tr>
<tr><td>California</td><td>29.53%</td><td>Joe Biden</td></tr>
<tr><td>Arkansas</td><td>26.91%</td><td>Donald Trump</td></tr>
<tr><td>Maryland</td><td>26.41%</td><td>Joe Biden</td></tr>
<tr><td>Vermont</td><td>26.4%</td><td>Joe Biden</td></tr>
<tr><td>New York</td><td>25.43%</td><td>Joe Biden</td></tr>
<tr><td>Nebraska</td><td>25.02%</td><td>Donald Trump</td></tr>
<tr><td>New York</td><td>25.4%</td><td>Joe Biden</td></tr>
<tr><td>Nebraska</td><td>25.01%</td><td>Donald Trump</td></tr>
</table>
</body>
</HTML>
Loading

0 comments on commit 1a00414

Please sign in to comment.