====== 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-2016:math445:lab8 [2016/03/22 08:25] gibson [Problem 3: Simulating the elections in all fifty states and the likelihood that Obama or Romney wins the general election.] |
gibson:teaching:spring-2016:math445:lab8 [2016/03/24 07:02] (current) gibson [Math 445 Lab 8: Predicting Presidential elections with Monte Carlo methods] |
||
---|---|---|---|
Line 6: | Line 6: | ||
* ''if-else'' statements | * ''if-else'' statements | ||
* ''for'' loops | * ''for'' loops | ||
- | * ''hist'' histogram plots | + | * ''histogram'' plots |
====Background==== | ====Background==== | ||
Line 20: | Line 20: | ||
* [[http://cosmiclog.nbcnews.com/_news/2012/10/30/14809227-political-forecasts-stir-up-a-storm?lite|NBC News story on Nate Silver, just prior to 2012 election]], | * [[http://cosmiclog.nbcnews.com/_news/2012/10/30/14809227-political-forecasts-stir-up-a-storm?lite|NBC News story on Nate Silver, just prior to 2012 election]], | ||
* [[http://www.dailykos.com/story/2012/11/01/1153661/-Nate-Silver-s-Math-Based-Math|DailyKos article on Nate Silver, just prior to 2012 election]] | * [[http://www.dailykos.com/story/2012/11/01/1153661/-Nate-Silver-s-Math-Based-Math|DailyKos article on Nate Silver, just prior to 2012 election]] | ||
- | * [[http://2012.talkingpointsmemo.com/2012/11/nate-silver-colbert-report-pundits.php?ref=fpnewsfeed|Nate Silver on the Colbert Report]] | ||
* [[https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=nate%20silver%20controversy | 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" ]] | ||
* [[https://en.wikipedia.org/wiki/Electoral_College_(United_States) | Electoral College, Wikipedia]] | * [[https://en.wikipedia.org/wiki/Electoral_College_(United_States) | Electoral College, Wikipedia]] | ||
Line 46: | Line 45: | ||
a random percentage of voters between -3.4% and 3.4%, and add that percent to | a random percentage of voters between -3.4% and 3.4%, and add that percent to | ||
Obama while subtracting it from Romney. Compare the resulting percentages | Obama while subtracting it from Romney. Compare the resulting percentages | ||
- | and declare the winner of the simulated election to whomever hads the larger | + | and declare the winner of the simulated election to whomever has the larger |
percentage. | percentage. | ||
Line 125: | Line 124: | ||
* 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. | * 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. | ||
- | ===== Data ===== | + | === 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 the 2012 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. |
- | <code> | + | |
- | % Composite Presidential election polling numbers | + | <file matlab P.asc> |
+ | % Composite 2012 Presidential election polling numbers | ||
% from http://fivethirtyeight.blogs.nytimes.com | % from http://fivethirtyeight.blogs.nytimes.com | ||
- | % 2012-11-06 1am | + | % 2012-11-01 1am |
% | % | ||
% O == Obama percentage | % O == Obama percentage | ||
Line 190: | Line 190: | ||
52.5 46.8 2.9 10 % WI | 52.5 46.8 2.9 10 % WI | ||
30.9 67.6 6.0 3 % WY | 30.9 67.6 6.0 3 % WY | ||
- | </code> | + | </file> |