====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:spring-2015:math445:lab9 [2015/03/23 13:43] gibson [This lab] |
gibson:teaching:spring-2015:math445:lab9 [2016/03/24 07:00] (current) gibson [Background] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Math 445 Lab 8: Predicting the Presidential election with Monte Carlo methods====== | + | ====== Math 445 Lab 9: Predicting Presidential elections with Monte Carlo methods====== |
====Background==== | ====Background==== | ||
Statistician Nate Silver made a name for himself in the 2008 Presidential election by correctly | Statistician Nate Silver made a name for himself in the 2008 Presidential election by correctly | ||
- | predicting the Presidential election outcomes for 49 of 50 states and all the Senate races. He used purely statistical methods applied to polling data. His statistical models had two parts. First, he developed models of the bias of individual pollsters based on past elections and used this to form composite, unbiased models of the aggregate polling data in each state. Second, he ran a large number of computer-simulated elections based on the unbiased composite state-by-state poll data and their margins of error. An estimate of the likelihood of either candidate winning the Presidential election was then given by the fraction of simulated elections that that candidate won. | + | predicting the Presidential election outcomes for 49 of 50 states and all 35 Senate races. He used purely statistical methods applied to polling data. His statistical models had two parts. First, he developed models of the bias of individual pollsters based on past elections and used this to form composite, unbiased models of the aggregate polling data in each state. Second, he ran a large number of computer-simulated elections based on the unbiased composite state-by-state poll data and their margins of error. An estimate of the likelihood of either candidate winning the Presidential election was then given by the fraction of simulated elections that that candidate won. |
In the 2012 elections Silver's projections received an enormous amount of attention, and quite a bit of criticism, too. Political pundits derided his work as meaningless number crunching and his 2008 results as lucky. But this time, Silver predicted the Presidential election correctly in all 50 states, and 31 of 33 Senate elections. | In the 2012 elections Silver's projections received an enormous amount of attention, and quite a bit of criticism, too. Political pundits derided his work as meaningless number crunching and his 2008 results as lucky. But this time, Silver predicted the Presidential election correctly in all 50 states, and 31 of 33 Senate elections. | ||
+ | Further reading on Nate Silver, fivethirtyeight.com, and the mathematics of election prediction: | ||
+ | |||
+ | * [[http://en.wikipedia.org/wiki/FiveThirtyEight]] | ||
+ | * [[http://cosmiclog.nbcnews.com/_news/2012/10/30/14809227-political-forecasts-stir-up-a-storm?lite]], | ||
+ | * [[http://www.dailykos.com/story/2012/11/01/1153661/-Nate-Silver-s-Math-Based-Math]] | ||
+ | * [[https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nate%20silver%20controversy | google:"Nate Silver controversy" ]] | ||
==== This lab ==== | ==== This lab ==== | ||
Line 16: | Line 22: | ||
a bunch of simulated elections based on the unbiased poll data). | a bunch of simulated elections based on the unbiased poll data). | ||
+ | ===== Warm-up problem #1: flipping 100 unbiased coins ===== | ||
+ | |||
+ | Before tackling the presidential election, we'll do a few warm-up problems. For the first | ||
+ | warm-up problem, simulate flipping 100 unbiased coins and counting the number of heads. | ||
+ | (An unbiased coin has exactly 50% chance of heads and 50% chance of tails.) | ||
+ | Do this 1000 times. Make a histogram of the number of heads over the 1000 simulations, | ||
+ | with histogram bins from 0 to 10, 10 to 20, etc. Compute the mean, median, and standard | ||
+ | deviation of number of heads over the 1000 trials. | ||
+ | |||
+ | ===== Warm-up problem #2: flipping 100 biased coins ===== | ||
+ | |||
+ | A biased coin has something other than 50-50 chances of going heads or tails. Suppose you have 100 | ||
+ | biased coins and you know the bias of each, i.e. the probability $p$ that each coin will turn up heads. | ||
+ | Do the same computations as in warm-up problem 1 on this set of biased coins (do 1000 trials, | ||
+ | produce a histogram, etc.) Use the following datafile for the biases of the 100 coins: | ||
+ | [[gibson:teaching:spring-2015:math445:lab9:biasedcoins.asc]]. | ||
+ | |||
+ | |||
+ | ===== Warm-up problem #3: flipping 100 coins with uncertain biases ===== | ||
+ | |||
+ | Now suppose you have 100 biased coins, but you don't know exactly what their biases | ||
+ | are. Instead, for each coin, you have an estimated bias $p$ and a margin of error $m$. | ||
+ | To account for this uncertainty, each time you flip a biased coin, change the estimated bias $p$ by a | ||
+ | random number between $-m$ and $m$. Again, run 1000 simulations of flipping these 100 | ||
+ | coins, make a histogram and compute the mean, median, and standard deviation of the | ||
+ | number of heads. Here's a file for biased coins with margins of error: | ||
+ | [[gibson:teaching:spring-2015:math445:lab9:biasedcoins2.asc]] | ||
+ | |||
+ | ===== Monte Carlo simulation of the 2012 Presidential election ===== | ||
+ | |||
+ | Now we're ready to tackle the original problem: a Monte Carlo simulation of | ||
+ | the 2012 Presidential election. | ||
Specifically, given a list of states, the number of their electoral votes, the composite | Specifically, given a list of states, the number of their electoral votes, the composite | ||
polling percentages for each candidate, and the margins of error those | polling percentages for each candidate, and the margins of error those | ||
Line 28: | Line 66: | ||
and award the ''n''th election to the candidate with the majority of electoral votes. | and award the ''n''th election to the candidate with the majority of electoral votes. | ||
- | Run a large number of such simulated elections, keeping track of the number of | + | Run a large number (say, 1000) of such simulated elections, keeping track of the number of |
electoral votes for each candidate in each election. Make a histogram that | electoral votes for each candidate in each election. Make a histogram that | ||
shows the statistical distribution of total electoral votes for one of the | shows the statistical distribution of total electoral votes for one of the | ||
Line 35: | Line 73: | ||
wins red and the bins corresponding to Obama wins blue, or else just draw a vertical | wins red and the bins corresponding to Obama wins blue, or else just draw a vertical | ||
line at the magic number of 270 electoral votes needed to win the election outright. | line at the magic number of 270 electoral votes needed to win the election outright. | ||
- | |||
===== Questions ===== | ===== Questions ===== | ||
- | Then answer the following questions | + | Then answer the following questions (again, pretending that it's still Tuesday, November 6th 2012 and the real outcome is unknown). |
- Who is most likely to win the presidential election? | - Who is most likely to win the presidential election? | ||
Line 70: | Line 107: | ||
Relevant matlab commands; **rand**, **randn**, **sum**, **hist**, and **bar**, plus standard plotting commands such as **xlabel**, **ylabel**, **title**. | Relevant matlab commands; **rand**, **randn**, **sum**, **hist**, and **bar**, plus standard plotting commands such as **xlabel**, **ylabel**, **title**. | ||
- | ===== Background ===== | + | ===== Commentary on Nate Silver and 538.com ===== |
- | + | ||
- | Nate Silver, a sports statistician, pioneered the use of Monte Carlo methods | + | |
- | in election prediction during the 2008 elections ([[http://fivethirtyeight.blogs.nytimes.com/]], [[http://en.wikipedia.org/wiki/FiveThirtyEight]]). In the 2008 elections, His model predicted 49 of 50 states correctly for the Presidential race (missing Indiana, which went to Obama by 1%) and all 35 Senate races correctly. Note that this lab does not cover the subtlest and most difficult aspect of election prediction: producing good composite poll numbers and margins of error from large numbers of pollsters using different methods, sample sizes, and polling dates. There is quite a bit of controversy in the current election over Mr. Silver's methods and his assessment that Obama has an 91% chance of winning the election. See, for example, | + | |
+ | * [[http://en.wikipedia.org/wiki/FiveThirtyEight]] | ||
* [[http://cosmiclog.nbcnews.com/_news/2012/10/30/14809227-political-forecasts-stir-up-a-storm?lite]], | * [[http://cosmiclog.nbcnews.com/_news/2012/10/30/14809227-political-forecasts-stir-up-a-storm?lite]], | ||
* [[http://www.dailykos.com/story/2012/11/01/1153661/-Nate-Silver-s-Math-Based-Math]] | * [[http://www.dailykos.com/story/2012/11/01/1153661/-Nate-Silver-s-Math-Based-Math]] | ||
- | * [[http://2012.talkingpointsmemo.com/2012/11/nate-silver-colbert-report-pundits.php?ref=fpnewsfeed|Nate Silver on Colbert the Colbert Report]] | + | * [[http://2012.talkingpointsmemo.com/2012/11/nate-silver-colbert-report-pundits.php?ref=fpnewsfeed|Nate Silver on the Colbert Report]] |
- | * google:"Nate Silver controversy"| | + | * [[https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nate%20silver%20controversy | google:"Nate Silver controversy" ]] |
===== Data ===== | ===== Data ===== | ||