-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
201 lines (187 loc) · 11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!doctype html>
<html>
<head>
<title>2020 US Presidential Election Model</title>
<style>
body {background-color: lightblue; text-align:center}
h1 {color: black; text-align:center}
h2 {color: black; text-align:center}
p {color: black; text-align:center}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
table {
border-collapse: collapse;
border: 2px black solid;
font: 12px sans-serif;
text-align: center;
}
td {
border: 1px black solid;
padding: 5px;
}
</style>
</head>
<script>
function includeHTML() {
var z, i, elmnt, file, xhttp;
/*loop through a collection of all HTML elements:*/
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/*make an HTTP request using the attribute value as the file name:*/
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/*remove the attribute, and call this function once more:*/
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/*exit the function:*/
return;
}
}
};
</script>
<body>
<header>
<h1>2020 United States Presidential Election Model</h1>
<p>
Hi, I'm Wyatt Entrekin, a 3rd-year Industrial Engineering student at the Georgia Institute of Technology
with a strong interest in data analysis and a fascination with electoral politics.
I created this election model as the result of a desire to develop my programming skills and a near obsession with the topic.
Below, you will see the results of the model, an explanation of the methods I used to produce the data you're looking at, and some interesting insights I gathered from these results.
If you have any questions, wish to connect professionally, or are interested in learning more about the project,
feel free to email me at <b>wmentrekin@gmail.com</b>,
connect with me on <b><a href="https://www.linkedin.com/in/wentrekin/">LinkedIn</a></b>,
or check out the code on <b><a href="https://github.com/wmentrekin/2020election">GitHub</a></b>.
</p>
</header>
<h1>Methods</h1>
<section>
<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. I am not in any way a professional election forecaster.
Nonetheless, I hope this peaks your interest.
</p>
<p>
When I first decided to begin working on this model in August, I wanted to challenge myself to learn more about different Python libraries,
such as Scipy, Numpy, Pandas, and Matplotlib and to see if I could come up with anything accurate. I utilized my prior skills in webscraping
and data manipulation while using new knowledge in statistics and data visualization. The entire model is written in Python.
</p>
<p>
This model essentially uses election data from 2016 and polling for this current election cycle to create a rough forecast of the 2020 election.
I gathered data about all 50 states and the District of Columbia from <a href="https://www.census.gov/">the census website</a>,
2016 election data from <a href='https://www.fec.gov/'>the FEC website</a>, 2020 election polling data from <a href='https://www.270towin.com/'>270 to win</a>,
and pollster ratings and bias from <a href='https://fivethirtyeight.com/'>538</a>.
</p>
<p>
After the data was gathered and cleaned, I had three classes of objects: States, Polls, and Pollsters. I wanted to use the data I gathered about each of these objects,
to implement this model. The model thus breaks down into these parts: correcting polls based on the grade and historical bias of their pollsters,
aggregating polls in each state into a singular rating with a vote share for both candidates and margin of error based on the combined margins of all the polls
(for states with no polling data, this rating was simply based on the 2016 election results, as states with no polling data are not assumed to be competitive
or change much in their results from the prior election cycle), combining the prior election results and the ratings for each state into distributions of possible vote share
for each candidate in each state, simulating 10,000 races in each state, and visualizing the data with the map and graphs you see below.
</p>
</section>
<h1>Results</h1>
<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>
</section>
<h1>Insights</h1>
<section>
<p>
The first interesting result that I noted while getting the first results of this model were how some states have very slim projected margins
while the candidate favored to win had very high chances of victory. For example, Donald Trump is expected to win South Carolina and Alaska by
margins of less than 10%, yet has more than 80% chance of victory in both states. Likewise, Joe Biden is expected to win both Minnesota and Virginia by
margins of less than 5%, yet has more than 90% chance of victory in both states. This is probably a result of the polling data in these states having low variance and error.
</p>
<p>
Next, I noticed that the model only predicts four true toss-up states: North Carolina, Arizona, Ohio, and Georgia, all of which Donald Trump won in 2016.
While candidates campaign all over the country, many of the states they visit are, at least statistically, already likely to vote a certain way.
This reflects in the projected flipped states as well, where all of them are expected to flip from Trump to Biden, with Biden projected to win by larger
margins than Trump won them in 2016, with the exception of Arizona and North Carolina, which out of these states, are the more traditionally Republican states.
</p>
<p>
Lastly, my model gives Joe Biden an almost guaranteed victory in the electoral college. While many models and pundits show Biden as the favorite, I am wary of the results of my own model.
In general, I believe that my results don't paint an unrealistic picture, but that some of the numbers can be potentially misleading. The goal was not to definitively predict the winner of the election,
but rather to project the chances of victory and vote shares in each state. Nonetheless, Joe Biden wins in almost every scenario. I believe that my model's victory chances don't necessarily represent an accurate number,
but that they do reflect the narrow path to victory for the incumbent president. While Joe Biden has many paths to the presidency (winning in the Rust Belt, the South, or the Southwest), Trump's chance rely heavily on repeating as closely his
victory in 2016, which relied heavily on slim margins in key states. While this model gives the president decent chances in states he needs to win, such as Wisconsin, Michigan, Pennsylvania, and Florida,
there are not many scenarios where my model has him winning all or enough of them to secure a victory. It shows that Biden can win either by close margins or in a landslide, but that if Trump wins, it will be a narrow victory.
My model, regardless of how accurate it turns out to be, shows that this election is not unlike 2016, in that this is the Democrats' election to lose and that Donald Trump needs to perform in a very specific way to win another term.
Overall, most of the simulations project Joe Biden winning with around 310-340 electoral votes to Donald Trump's 200-230 electoral votes.
</p>
</section>
</body>
<script>
includeHTML();
</script>
</html>