====== 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 19:28] gibson [Questions] |
gibson:teaching:spring-2015:math445:lab9 [2016/03/24 07:00] (current) gibson [Background] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Math 445 Lab 8: Predicting Presidential elections with Monte Carlo methods====== | + | ====== Math 445 Lab 9: Predicting Presidential elections with Monte Carlo methods====== |
====Background==== | ====Background==== | ||
Line 9: | Line 9: | ||
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 ===== | ||