User Tools

Site Tools


gibson:teaching:fall-2012:math445:lab8

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:fall-2012:math445:lab8 [2012/11/01 18:50]
gibson [Math 445 Lab 8: Presidential election]
gibson:teaching:fall-2012:math445:lab8 [2012/11/06 06:24] (current)
gibson [Math 445 Lab 8: Presidential election]
Line 3: Line 3:
  
 Your job is to predict the outcome of today'​s Presidential election ​ Your job is to predict the outcome of today'​s Presidential election ​
-given the last-minute polling data. +given the last-minute polling data, using Monte Carlo simulation.
  
 Specifically,​ given a list of states, their electoral votes, the composite ​ Specifically,​ given a list of states, 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 
-polling percentages,​ you are to run a large number of  simulations of the  +polling percentages,​ you are to run a large number of simulations of the  
-election. For each state, start by assigning the specified composite polling ​ +election ​and determine the likelihood that either candidate will win based  
-percentages to the two candidates. Then determine ​a random number in the range +on the results of those simulations. For each state, start by assigning the  
-between ''​-margin''​ and ''​+margin''​, and transfer that percentage from one  +specified composite polling percentages to the two candidates. Then add to 
-candidate to the otherAlways follow ​the same sign convention, i.e. if the +each candidate'​s percentage ​different ​random number in the range between ​ 
-random number is positive, take the percentage from Obama and give it to Romney.  +''​-margin''​ and ''​+margin''​. ​Compare ​the two percentages ​and award that state'​s ​ 
-Then award that state'​s electoral votes to the candidate with the larger ​ +electoral votes to the candidate with the larger percentage of votes. ​Do this  
-percentage of votes. ​Add up all the electoral votes for each candidate, ​and  +for all fifty states (plus DC), add up all the electoral votes for each candidate,  
-award the ''​n''​th election to the candidate with the greater total number ​of  +and award the ''​n''​th election to the candidate with the majority ​of electoral votes. ​
-electoral votes. ​+
  
-Run a large number of such simulated elections, ​and record ​the number of +Run a large number 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 
-candidates, using bins of width between 0 and 539 (0-for bin 1, 5-for  +candidates, using bins of width 10 between 0 and 540 (0-9.99 for bin 1, 10-14.99 for  
-bin 2, etc). Color the bins corresponding to Romney wins red and the bins  +bin 2, etc). If you can figure out how, color the bins corresponding to Romney ​ 
-corresponding to Obama wins blue. I suggest starting with small number ​ +wins red and the bins corresponding to Obama wins blue, or else just draw vertical  
-of simulated elections, say 100 or 1000, and then increasing ​to a large number +line at the magic number of 270 electoral votes needed ​to win the election outright. 
-(10,000 or 100,000) when your code is debugged and you're confident it's working + 
-correctly. ​+===== Questions =====
  
 Then answer the following questions Then answer the following questions
Line 32: Line 31:
   - Who is most likely to win the presidential election?   - Who is most likely to win the presidential election?
   - What is the probability that the most likely winner will actually win?   - What is the probability that the most likely winner will actually win?
-  - What is the most likely range of electoral votes for the winner? (among the bins of width specified above) +  - What is the most likely range of electoral votes for the winner? (among the bins of width 10 specified above) 
-  ​+  ​- What is the likelihood of a 269-269 electoral vote tie?  
 Turn in print-outs of your codes, your histogram, and your answers to the above questions. ​ Turn in print-outs of your codes, your histogram, and your answers to the above questions. ​
  
-Tips: 
  
-  ​* Start with a small number of simulated electionssay 100and then increase to a large number (10,000 or 100,000) when you're confident your code is working correctly.  +===== Tips ===== 
-  * You can also develop your code using simulated data, for example, just ten states with 50-50 chances for each candidate ​and zero or a very small margin of error.+ 
 + 
 +  ​* Start with a small number of simulated elections ​(say 100and then increase to a large number (say 10,000) when you're confident your code is working correctly.  
 +  * You can also develop your code using simulated data, for example, just ten states ​all with the same polling numbers ​and a very small margin of error. 
 +  * Try to use as few for-loops as possible. If you are really on fire, you can do it with just one for-loop that loops over the number of trials.  
 +  * Changing the colors of histogram bins in Matlab is not as easy as one might hope. You'll need to take data returned from the **hist** function and replot it with the **bar** command. See http://​www.mathworks.com/​matlabcentral/​newsreader/​view_thread/​290534 for an example of how to do this. 
 + 
 +===== Broader questions =====
  
 Some further questions you might also address Some further questions you might also address
  
-  * The margins of error reported in the table are really 95% confidence levels, corresponding to two standard deviations of a Gaussian distribution. Modify your code so that the random number added to each is from a Gaussian distribution with standard deviation of one-half the margin of error. ​ Does this significantly change your results?+  * The margins of error reported in the table are really 95% confidence levels, corresponding to two standard deviations of a Gaussian distribution. Modify your code so that the random number added to each percentage ​is from a Gaussian distribution with standard deviation of one-half the margin of error. ​ Does this significantly change your results?
   * Does doubling or halving the margins of error significantly change your results?   * Does doubling or halving the margins of error significantly change your results?
   * How many elections do you need to simulate in order to get reliable answers?   * How many elections do you need to simulate in order to get reliable answers?
-  * The lab as written assumes a two-party presidential election. ​Do you think we should ​include third-party candidates? ​If you do, does it change the results significantly?​ +  * The lab as written assumes a two-party presidential election. ​Should ​we include third-party candidates? ​Why or why not? How would you revise your code to include a third party? Would it change the results significantly?​ 
-  * We are trusting that the polling data form an accurate estimate of the actual votes cast, to within the margins of error. ​Is this valid assumptionWhy or why not? +  * We are trusting that the polling data form an accurate estimate of the actual votes cast, to within the margins of error. ​The data reported below was obtained from [[http://​fivethirtyeight.blogs.nytimes.com/​]],​ and is claimed by its compiler to be unbiased and statistically reliable estimate, though there is fair amount of controversy about this, split along party and ideological lines. Do you think the given polling data is fair and accurateIs there a reason to suspect it is or is not?
   * Do you believe your own election prediction? Why or why not?   * Do you believe your own election prediction? Why or why not?
  
  
-Relevant matlab commands; **rand**, **randn**, **sum**, **hist**, 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 =====
  
 Nate Silver, a sports statistician,​ pioneered the use of Monte Carlo methods ​ 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]]). 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 80% chance of winning the election. See, for example, ​[[http://​cosmiclog.nbcnews.com/​_news/​2012/​10/​30/​14809227-political-forecasts-stir-up-a-storm?​lite]],​  +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://​www.dailykos.com/​story/​2012/​11/​01/​1153661/​-Nate-Silver-s-Math-Based-Math]],​ or google "Nate Silver controversy"​.+
  
 +  * [[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://​2012.talkingpointsmemo.com/​2012/​11/​nate-silver-colbert-report-pundits.php?​ref=fpnewsfeed|Nate Silver on Colbert ​  the Colbert Report]]
 +  * google:"​Nate Silver controversy"​| ​
 +===== Data =====
  
 Here's some current polling data, taken from [[http://​fivethirtyeight.blogs.nytimes.com]] on 2012-11-01. You can load this into Matlab as a matrix ''​P''​ by cutting and pasting the data into a text file ''​P.asc''​ and running ''​load P.asc''​ within Matlab. If you don't believe this polling data, feel free to use something you trust more.  Here's some current polling data, taken from [[http://​fivethirtyeight.blogs.nytimes.com]] on 2012-11-01. You can load this into Matlab as a matrix ''​P''​ by cutting and pasting the data into a text file ''​P.asc''​ and running ''​load P.asc''​ within Matlab. If you don't believe this polling data, feel free to use something you trust more. 
Line 62: Line 74:
 % Composite Presidential election polling numbers % Composite Presidential election polling numbers
 % from http://​fivethirtyeight.blogs.nytimes.com % from http://​fivethirtyeight.blogs.nytimes.com
-% 2012-11-01+% 2012-11-06 1am
 % %
 %  O == Obama percentage ​ %  O == Obama percentage ​
Line 70: Line 82:
 % %
 % O    R    M    EV      state % O    R    M    EV      state
-36. 62. 3.  9   ​% ​ AL +36. 62. 3.  9   ​% ​ AL 
-38. 60. 6.  3   ​% ​ AK +38. 59. 6.  3   ​% ​ AK 
-45. 53. 4. ​11 ​  ​% ​ AZ +46. 53. 3. ​11 ​  ​% ​ AZ 
-37. 60. 4.  6   ​% ​ AR +38. 59. 3.  6   ​% ​ AR 
-58.2  40.5  ​3. ​55 ​  ​% ​ CA +58.2  40.5  ​2. ​55 ​  ​% ​ CA 
-50. 48. 3.  9   ​% ​ CO +50. 48. 3.  9   ​% ​ CO 
-55. 43. 3.  7   ​% ​ CT +56. 42. 3.  7   ​% ​ CT 
-59. 39. 5.  3   ​% ​ DE +59. 39. 5.  3   ​% ​ DE 
-92.  6. ​3.2 ​  ​3 ​  ​% ​ DC   +93.  6. ​3.2 ​  ​3 ​  ​% ​ DC   
-49. 50. 3.2  29   ​% ​ FL +49. 49. 2.7  ​29 ​  ​% ​ FL 
-44. 54. 3. ​16 ​  ​% ​ GA +45. 54. 2. ​16 ​  ​% ​ GA 
-67. 31. 4.9   ​4 ​  ​% ​ HA +66. 32. 3.9   ​4 ​  ​% ​ HA 
-31. 66. 4.  4   ​% ​ ID +32. 66. 4.  4   ​% ​ ID 
-59. 40. 3. ​20 ​  ​% ​ IL +59. 39. 3. ​20 ​  ​% ​ IL 
-43. 55. 3. ​11 ​  ​% ​ IN +45. 53. 3. ​11 ​  ​% ​ IN 
-51. 48. 3.  6   ​% ​ IA +51. 47. 3.  6   ​% ​ IA 
-37. 61. 6.  6   ​% ​ KA +38. 61. 6.  6   ​% ​ KA 
-39. 59. 4.  8   ​% ​ KY +40. 58. 4.  8   ​% ​ KY 
-40. 58. 6.  8   ​% ​ LA +39. 59. 3.  8   ​% ​ LA 
-56.1  42. 4.  4   ​% ​ ME +56.1  42. 3.  4   ​% ​ ME 
-60. 38. 3. ​10 ​  ​% ​ MD +61. 38. 3. ​10 ​  ​% ​ MD 
-58. 39. 4. ​11 ​  ​% ​ MA +59. 39. 3. ​11 ​  ​% ​ MA 
-52. 45. 3. ​16 ​  ​% ​ MI +53. 45. 2. ​16 ​  ​% ​ MI 
-52.8  45. 3. ​10 ​  ​% ​ MN +53.8  45. 2. ​10 ​  ​% ​ MN 
-39. 60. 5.  6   ​% ​ MS +39. 60. 5.  6   ​% ​ MS 
-45. 54. 3. ​10 ​  ​% ​ MO +45. 53. 2. ​10 ​  ​% ​ MO 
-44. 53. 4.  3   ​% ​ MT +45. 53. 3.  3   ​% ​ MT 
-39. 60. 3.  5   ​% ​ NE +40. 58. 3.  5   ​% ​ NE 
-51. 47. 3.  6   ​% ​ NV +51. 47. 2.  6   ​% ​ NV 
-51. 48. 4.  4   ​% ​ NH +51. 47. 3.  4   ​% ​ NH 
-55. 44. 3. ​14 ​  ​% ​ NJ +55. 43. 3. ​14 ​  ​% ​ NJ 
-53. 45. 4.  5   ​% ​ NM +54. 44. 3.  5   ​% ​ NM 
-62. ​36.9  ​3.2  29   ​% ​ NY +62. ​36.9 ​ 2.8  ​29 ​  ​% ​ NY 
-48. 51. 3. ​15 ​  ​% ​ NC   +48. 50. 2. ​15 ​  ​% ​ NC   
-41. 57. 4.3   ​3 ​  ​% ​ ND +42. 56. 3.9   3   ​% ​ ND 
-50. 48. 3.2  18   ​% ​ OH +51. 47. 2.7  ​18 ​  ​% ​ OH 
-33. 66. 4.  7   ​% ​ OK +33. 65. 3.  7   ​% ​ OK 
-52.7  44. 4.  7   ​% ​ OR +53.7  44. 3.  7   ​% ​ OR 
-52. 46. 3. ​20 ​  ​% ​ PA +52. 46. 2. ​20 ​  ​% ​ PA 
-62. 36. 4.  4   ​% ​ RI +61. 36. 4.  4   ​% ​ RI 
-43. 56. 4.  9   ​% ​ SC +43. 56. 4.  9   ​% ​ SC 
-41. 57. 4.  3   ​% ​ SD +42. 56. 4.  3   ​% ​ SD 
-39. 59. 4. ​11 ​  ​% ​ TN +41. 57. 3. ​11 ​  ​% ​ TN 
-41. 57. 3. ​38 ​  ​% ​ TX +41. 58. 3. ​38 ​  ​% ​ TX 
-26. 71. 4.  6   ​% ​ UT +27. 70. 4.  6   ​% ​ UT 
-65. 33. 5.  3   ​% ​ VT +66. 32. 4.  3   ​% ​ VT 
-50. 49. 2. ​13 ​  ​% ​ VA +50. 48. 2. ​13 ​  ​% ​ VA 
-55. 43. 3. ​12 ​  ​% ​ WA +56. 42. 3. ​12 ​  ​% ​ WA 
-40. 58. 5.  5   ​% ​ WV +41. 57. 4.  5   ​% ​ WV 
-51. 47. 3. ​10 ​  ​% ​ WI +52. 46. 2. ​10 ​  ​% ​ WI 
-30. 68. 6.  3   ​% ​ WY+30. 67. 6.  3   ​% ​ WY
 </​code>​ </​code>​
gibson/teaching/fall-2012/math445/lab8.1351821000.txt.gz · Last modified: 2012/11/01 18:50 by gibson