Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

EK 125 Final Project

Allison Glick, Liam Stephenson, Namanjyot Singh


12/10/22

Presidential voting data, 1976 to 2020

Finding our data:


The first step in our project was to import our selected data into matlab from
(https://www.pnas.org/doi/10.1073/pnas.2013581117) . This was a pretty simple process where
we downloaded the data set off of the MIT Election Data Lab as a .csv and then imported it
directly into matlab as a data table. In the data table we have 15 columns with different data sets,
as shown below.

Since we're focusing on just the data that will allow us to predict the future presidential
elections, we don’t need all of the data. So to make the data table easier to work with, we are
going to write some code that will remove the unnecessary data. We were able to accomplish this
through the use of for loops and setting the unnecessary columns of data to [ ]. The data after
running the code can be seen in the below table.

Then we wrote a code to change the ‘Libertarian’ party to ‘Other’, this step simplified
our table and got rid of the non-popular parties that have no chance of winning the election.
Code:

Then we made a copy of the data we imported into a new variable so we could do some
different scrubbing to it. The next step was to make the code easier to work with, so we
converted the arrays in the party names column to strings. This was done by several simple for
loops that set the values equal to different ones. Then in the new data variable we created we
deleted all of the “other” parties since they never won an election once and were thus negligible.

Now we go to the meat of the code where the first step was to use the menu() function to
create a menu that allows the user to select from three options, 2024 Election Predictor,
Comparison, and State Data. After the menu was set up, we had to start setting up the code for
each option. The first step to code was when the value input was 0, this occurs when the user
clicks the “x” button to leave the menu before selecting an option. To just make the program a bit
more user friendly we decided on using the fprintf() function to send a message to the user
saying the program had been successfully closed.

The first big chunk of code is for the first option, the 2024 Presidential Election. To start
we needed to initialize two variables to act as counters that would be used to track the number of
states each party won. By setting them equal to 0 they would then be initialized. Next is a for
loop that goes from 1 to 616 in increments of 2 and is assigned to the variable “qq”. Initially we
tried doing it in increments of 1, but we needed to compare two races in each state and this didn’t
allow for it. So to solve the issue whenever the for loop went up one value, another variable
would be created that would have 1 added to it, this variable is “jj”. This then allowed us to have
new values of the two races in each state every time. Within the for loop there are a couple of
loops. The first one checks if the the number of votes for the party at “qq” is less than the
number of votes at “jj”. After this is another if loop that determines what party gets the point. We
initially messed it up by giving the point to the party with the lower total votes which resulted in
the wrong party getting the points. We solved this by switching it so that the losing party didn’t
get the points. The points were then assigned into the counter by simply just adding 1 to them.

Next we made another if loop to print the different results. If the Republican party won
then an fprintf function is used to print “Republicans are predicted to win the next election”.
Then if the Democrat party won, an fprintf function is used to print “ Democrats are predicted to
win the next election.

Now we're onto the next option provided by the menu function, Comparisons. This one is
significantly more complex than the predictor. Starting off we used several input functions and
fprintf functions to tell the user what they are using and ask them what data they would like to
compare. The user can enter a state's full name and then two separate dates and the code will
access the data and then compare the two years to determine the percent change, whether the
change was positive or negative, and what the votes were at the two points in time. We had quite
a bit of trouble here getting the code to access the correct data. It wasn’t so much an issue with
our code, but matlab was being finicky about copying and pasting. So we had to retype out
everything line by line and it ended up working. How the code does work is by initiating a for
loop through the whole data set, in each loop it first looks at the state name in the data of that
row and compares it to the user input state name. If the name is the same it then moves onto
another if loop that looks at the year for that row, if the year is the same as the user input year
then it moves onto the final if loop which determines what party it is. If the party is Republican
than the data for the number of votes that party got is assigned to a variable, if the party is
democrat it assigns the data to a different variable for Democrat data. After all of this the exact
same loop is initiated again but for the second date. Everything is assigned to different variables.
A simple calculation is run to get the percent change and the values are assigned to variables.
Then we used an if function that would print three different things depending on if the percent
change was positive, negative, or nothing.

The final option we decided on was to let users access the raw data of the dataset. Using
several input and fprintf functions the user is asked which state’s data they wish to access and
during which year. Then they are asked to confirm if the data they input is correct or not. If they
answer yes then a for loop and an several if loops like in the previous option are used to find the
correct data row. Then that row’s data is displayed by simply using the disp() function and
indexing into it. If the user enters no into the prompt asking them if to confirm their input then
the code loops back to the beginning and asks them for the data again, this will happen until the
user input “yes” and then the data will be displayed.
Project deliverables

Synopsis: Electoral college bias and the 2020 presidential election


The electoral college is a very contentious issue within America, it renders the popular vote
irrelevant, denies the presidency to the winner of the popular vote, having all the electoral votes
from one state go to one candidate, regardless of the margin by which the candidate won (except
Maine and Nebraska which both allow split votes but rarely do this). Even more argumentative
than the fact that all the states' votes go to one candidate, the individual vote, actually does not
affect anything. The electoral college representative of each state gets to decide where all the
state's electoral votes go, and the representative usually goes with the majority of the state,
although they have no legal ties to do so. This is why we are a republic rather than a democracy,
since we elect individuals to cast our votes, but these people may cast their votes to where they
see fit. Although the issue of a rogue elector has never changed the outcome of an election, the
"winner takes all" style of delegating votes has swayed the overall results and has repeatedly
screwed the country out of their choice, and the practice of having this electoral college
historically favors the Republican party. Most recently, in 2016, the popular vote (which is the
percentage of individual votes cast) was 48% (65 million) democrat and 45.9% (62 million)
republican. This means, of the American people who voted, around 3 million more individuals
voted democrat, and the country chose the democratic nominee for the president. But due to the
process of the electoral college, and the fact that the republican nominee won a lot of large states
by small margins, he picked up every single electoral college vote in those states, and therefore,
had the majority of electoral college votes, and got to take the presidential seat. The electoral
college bias is that the electoral college undermines the popular vote, and does not always
represent the majority vote of the American people. The electoral college is an ongoing debate,
some people find it an important pillar of the way America's government is built, and others see
it as a destruction of democracy and completely unjust.

High level relevance of data- Summary and background


In our project, we are examining data from each presidential election from 1976 until 2020,
which occurs every four years. We are utilizing the proportion of each state's vote for president,
whether democratic, republican, or other; to forecast what will happen in America's next
presidential election in 2024. Election prediction is such an important aspect of our political
system that nearly everything in politics revolves around it. Politicians base their platform, votes,
campaigning, and pretty much every decision they make in office on polling and election
prediction, because their main goal is to be re-elected, an overarching stress that clouds a
representative's entire time in office. Regardless of which branch of government one is elected
in, they are always thinking about polling predictions when running their campaigns. This is
especially crucial in the presidential election, because it is stated that the first two years of a
president's term are spent on policy and action, while the second two years are spent on
re-election strategy. Presidential nominees have a whole team of experts analyzing various
datasets to assist anticipate which groups will vote, which groups you have locked in, and which
groups you need to focus your campaigning on and decide how all your money is spent. Data
analysis, and therefore money delegation, is the most crucial aspect of one's campaign, but it
influences more than just campaigns; it affects votes and policies of representatives as well. Our
data set shows each state's voting percentage for presidential electors for each political party. We
are only focusing on the two main parties because the other parties are so small they will never
be able to elect a president, and the two main parties are always in a constant battle to control the
executive branch. We are using the data of the past 40 years of presidential elections to predict
the next election’s popular vote. Our data does not take into account the electoral college, but
rather the popular vote in each state and throughout the country. We're keeping an eye on each
states' tendencies, the changes they've made over the years, and where we predict their votes to
go. We are forecasting specific state vote breakdowns and the overall country's percentage of
vote for each political party based on history and current patterns. The 2024 presidential election
is crucial as the executive branch wields significant control over the course of our country, and
anticipating the election now can help citizens prepare for whether their party wins or loses and
the ramifications of both. Furthermore, it may assist individuals campaigning and their teams in
determining which states they are expected to win and which which they are lagging in, as well
as which states to focus for more intense campaigning and which individuals they need to recruit
into their party for this vote. However, the presidential election is not determined only on the
trends and historical votes of each state; one's vote is affected by a variety of elements, including
the economy, foreign relations, social concerns, and a variety of uncontrolled factors that change
on a daily basis. This means that even if we create a forecast based on facts and data, it will not
always tell us what will certainly happen. Elections are unpredictable, polls and data projections
are continuously shifting and inaccurate and erroneous. These polls are extremely significant
because they give us a sense of voting tendencies, but they are not always, or even typically,
correct. There are so many other aspects to consider, and this is just one of them. Many
additional data sets must be considered in order to evaluate and provide a complete picture of
voting trends for each state in the 2024 presidential election.

Works Cited

Ballotpedia ., “Presidential voting trends by State,” Ballotpedia, 2020. [Online]. Available:


https://ballotpedia.org/Presidential_voting_trends_by_state. [Accessed: 10-Dec-2022].

James E. Campbell, “Forecasting the presidential election P»LTA,” presidential forecast, 2020.
[Online]. Available: https://unz.com/PDF/PERIODICAL/BrookingsRev-1996q4/28-34/.
[Accessed: 10-Dec-2022].

K. N. Jordan, “Examining long-term trends in politics and culture through ... - PNAS,” PNAS,
2018. [Online]. Available: https://www.pnas.org/doi/10.1073/pnas.1811987116. [Accessed:
10-Dec-2022].

R. S. Erikson, “Electoral College bias and the 2020 presidential election | PNAS,” PNAS, 2020.
[Online]. Available: https://www.pnas.org/doi/10.1073/pnas.2013581117. [Accessed:
10-Dec-2022].

UC Barbara, “Pool reports of November 29, 2022,” Pool Reports of November 29, 2022 | The
American Presidency Project, 29-Nov-2022. [Online]. Available:
https://www.presidency.ucsb.edu/documents/pool-reports-november-29-2022. [Accessed:
10-Dec-2022].
Graphs
Figure 1 - 13

Figure 1. Representation of total democratic and republican votes each year, republican in red,
democrat in blue

Figure 2. Line graphs representing the total votes in each state in each given year
Figure 3. Democrat and republican votes each year, from each state

Figure 4. Amount of votes, each state casts


Figure 5. Democratic and republican overall votes each year

Figure 6. Republican and Democratic overall votes from each state


Figure 7. Democrat, Republican, and “Other” votes, over the years, from each state

Figure 8. Republican largest, votes over years


Figure 9. Democrat largest, votes over years

Figure 10. ‘Others’ largest, votes over years


Figures 11, 12, 13. Various states breakdowns of voting parties

You might also like