Homework 3: Election Prediction
Credits: This assignment is modified form of https://courses.cs.washington.edu/courses/cse140/13wi/homework/hw3/homework3.html
Due:
Submit only main.cpp via LMS
In this assignment, you will practice use of vectors, maps, and tuples.
Introduction and background
Election prediction: pundits vs. statisticians
In recent decades there has been a shift to a more scientific approach, in which election results
are predicted statistically using a poll. A small random sample of voters is asked how they will
vote, and from that the result of the entire election is extrapolated.
In the 2012 presidential election, statistician Nate Silver correctly predicted the outcome in
every state, whereas pundits’ predictions varied significantly.
How did Nate Silver do it? In this assignment, you will find out, and you will replicate his results
by using polling data to predict the outcome of the 2012 US presidential election.
Election polls: Which ones to trust?
An election poll is a survey that asks a small sample of voters how they plan to vote. If the
sample of voters is representative of the voting population at large, then the poll predicts the
result of the entire election. In practice, a poll’s prediction must be taken with a grain of salt,
because the sample is only approximately representative of the voting population.
How can you decide which polls to rely upon?
Depending on which poll you trust, you might make a very different prediction.
One approach is to average together the different polls. This is better than trusting any one of
them, but it is still rather crude as some of them may be biased.
Silver’s approach is very sophisticated, but its key idea is to combine different polls using a
weighted average. In a normal average, each data point contributes equally to the result. In a
weighted average, some data points contribute more than others. Silver examined how well
each polling organization had predicted previous elections, and then weighted their polls
according to their accuracy: more biased pollsters had less effect on the weighted average.
The general structure of FiveThirtyEight’s algorithm is:
1. Calculate the average error of each pollster’s predictions for previous elections. This is
known as the pollster’s rank. A smaller rank indicates a more accurate pollster.
2. Transform each rank into a weight (for use in a weighted average). A larger weight
indicates a more accurate pollster. Silver considers a number of factors when
computing a weight, including rank, sample size, and when a poll was conducted. For
this assignment, we simply set weight to equal the inverse square of rank (weight =
rank^-2).
3. In each state, perform a weighted average of predictions made by pollsters. This
predicts the winner in that state.
4. Calculate the outcome of the Electoral College, using the per-state predictions. The
candidate with the most electoral votes wins the election.
The US Electoral College
Why polls are approximate