Wednesday
Oct122016

Nate Silver is Probably a Dog, I Dyslexiate

I'm a fan of fivethirtyeight.com

Nate has state by state election outcome polls - and so for fun (my idea of fun sure isn't everyones), I wanted to repeat some of his analysis - specifically 100,000 randomized state by elections with Mathematica:

 

(*Oct 11*)
data1={{"Alabama",0.5,99.5, 9},{"Alaska",30.4,69.2,3}, {"Arizona",48.2,51.8,11},{"Arkansas",2.4,97.6,6}, {"California",99.8,0.2,55}, {"Colorado", 83.7, 16.3,9}, {"Connecticut", 98.1, 1.9, 7}, {"Delaware", 94.9, 5.1, 3}, {"Distric of Columbia", 99.9, 0.1, 3},{"Florida",71.1,28.9,29},{"Georgia",29.8,70.2,16},{"Hawaii",99.7,0.3,4},{"Idaho",1.5,98.4,4}, {"Illinois", 98.9, 1.1, 20}, {"Indiana",12.7,87.3,11}, {"Iowa", 55.2, 44.8,6}, {"Kansas", 10.5, 89.5, 6},{"Kentucky", 3.8, 96.2, 8} ,{"Lousiana", 3.5,96.5,8},{"Maine",86.9,13.1,2}, {"Maryland",99.9,0.1,10},{"Massachusetts",99.7,0.3,11},{"Michigan",90,10,16},{  "Minnesota",86.6,13.4,10},{"Mississippi",4.7,95.3,6},{"Missouri",19.3,80.7,10},{"Montana",13.9,86.1,3},{"Nebraska",4.4, 95.6,2}, {"Nevada",72.4,27.6,6},{"New Hampshire",83.2,16.8,4},{"New Jersey", 96.6, 3.5, 14},{"New Mexico",93.2,6.2,5}  , {"New York", 99.6,0.4,29},{"North Carolina",  67.6,32.4,15},{"North Dakota", 7,92.9,3},{"Ohio",60.7,39.3,18}, {"Oklahoma",1,99,7},{"Oregon", 96.7,3.3,7},{"Pennsylvania",87.2,12.8,20},{"Rhode Island",96.5,3.5,4}, {"South Carolina",14.3,85.7,9},{"South Dakota",18.1,81.8,3},{"Tennessee",3.8,96.2,11},{"Texas",13.5,86.5,38},{"Utah",2.3,97.6,6},{"Vermont",98.1,1.9,3},{"Virgina", 90.6,9.4,13},{"Washington",97.7,2.3,12},{"West Virgina", 1, 99, 5},{"Wisconsin", 87.2, 12.8, 10},{"Wyoming",2,97.9,3}};
(* Oct 21 *)
data2={{"Alabama",0.4,99.6, 9},{"Alaska",32.6,67.3,3}, {"Arizona",56,44,11},{"Arkansas",1.8,98.2,6}, {"California",99.9,0.1,55}, {"Colorado", 88.9, 11.1,9}, {"Connecticut", 97.6, 2.4, 7}, {"Delaware", 94.7,5.3, 3}, {"Distric of Columbia", 99.9, 0.1, 3},{"Florida",86.2,13.8,29},{"Georgia",31.7,68.3,16},{"Hawaii",99.6,0.4,4},{"Idaho",3.2,96.8,4}, {"Illinois", 99.1, 0.9, 20}, {"Indiana",15.3,84.6,11}, {"Iowa",56.5, 43.5,6}, {"Kansas", 10.7, 89.3, 6},{"Kentucky", 4.7, 95.3, 8} ,{"Lousiana", 1.5,98.5,8},{"Maine",87.7,12.3,2}, {"Maryland",99.9,0.1,10},{"Massachusetts",99.7,0.3,11},{"Michigan",93,7,16},{  "Minnesota",86.5,13.5,10},{"Mississippi",4.7,95.3,6},{"Missouri",19.3,80.7,10},{"Montana",13.9,86.1,3},{"Nebraska",4.4, 95.6,2}, {"Nevada",72.4,27.6,6},{"New Hampshire",86.8,13.1,4},{"New Jersey", 97.5,2.5, 14},{"New Mexico",93.8,5.9,5}  , {"New York", 99.8,0.2,29},{"North Carolina",  70.1,29.9,15},{"North Dakota", 9.2,90.8,3},{"Ohio",61.7,38.3,18}, {"Oklahoma",0.9,99.1,7},{"Oregon", 95.7,4.3,7},{"Pennsylvania",87.9,12,20},{"Rhode Island",97.1,2.9,4}, {"South Carolina",14.2,85.8,9},{"South Dakota",15.5,884.4,3},{"Tennessee",3.3,96.7,11},{"Texas",16.1,83.9,38},{"Utah",9.5,76.3,6},{"Vermont",98.15,1.95,3},{"Virgina", 93.4,6.6,13},{"Washington",97.9,2.1,12},{"West Virgina", 1.2, 98.8, 5},{"Wisconsin", 89.6, 10.4, 10},{"Wyoming",2.5,97.5,3}};   
(* Nov 7 *)
data3={{"Alabama",0.1,99.9, 9},{"Alaska",23.5,76.4,3}, {"Arizona",30,70,11},{"Arkansas",0.6,99.4,6}, {"California",99.9,0.1,55}, {"Colorado", 76.5, 23.5,9}, {"Connecticut", 96.3, 3.7, 7}, {"Delaware", 88.5,11.5, 3}, {"Distric of Columbia", 99.9, 0.1, 3},{"Florida",53.6,46.4,29},{"Georgia",19.4,80.6,16},{"Hawaii",98.8,1.2,4},{"Idaho",0.7,99.3,4}, {"Illinois", 98.3, 1.7, 20}, {"Indiana",2.5,97.5,11}, {"Iowa",29.5, 70.8,6}, {"Kansas", 2.9,97.1, 6},{"Kentucky", 0.5, 99.5, 8} ,{"Lousiana", 0.7,99.3,8},{"Maine",79.7,20.3,2}, {"Maryland",99.9,0.1,10},{"Massachusetts",99.9,0.1,11},{"Michigan",77.2,22.7,16},{  "Minnesota",85.7,14.2,10},{"Mississippi",1.9,98.1,6},{"Missouri",3.6,96.4,10},{"Montana",3.9,96,3},{"Nebraska",1.8, 98.2,2}, {"Nevada",57.5,42.5,6},{"New Hampshire",68.3,31.6,4},{"New Jersey", 96.7,3.3, 14},{"New Mexico",80.6, 19.2,5}  , {"New York", 99.7,0.3,29},{"North Carolina",  54.3,45.7,15},{"North Dakota", 1.9,98.1,3},{"Ohio",36.8,63.2,18}, {"Oklahoma",0.1,99.9,7},{"Oregon", 94.1,5.9,7},{"Pennsylvania",75.6,24.5,20},{"Rhode Island",92.2,7.8,4}, {"South Carolina",11,89,9},{"South Dakota",5.1,94.9,3},{"Tennessee",2.4,97.6,11},{"Texas",5,95,38},{"Utah",3.5,83.7,6},{"Vermont",98,2,3},{"Virgina", 84.5,15.5,13},{"Washington",97.9,2.1,12},{"West Virgina", 0.2, 99.8, 5},{"Wisconsin", 82.6, 17.4, 10},{"Wyoming",1,99,3}};   
data=data3; Vote:=RandomChoice[{data[[#,2]],data[[#,3]]}-> {1,-1}]&/@ Range[Length[data]];
test=Table[Vote,{100000}];H=Total[data[[All,4]](test[[#]]+1)/2]&/@ Range[Length[test]];T=Total[data[[All,4]](test[[#]]-1)/(-2)]&/@ Range[Length[test]];
ListPlot[{Sort[Counts[H]],Sort[Counts[T]  ]},PlotRange-> {{0,538},{0,1750} }  , PlotLegends->{"HC","DT"}, TargetUnits->{"EC Votes","n/100000"},AxesLabel->Automatic,GridLines->{{270},{0}}]


data=data3; Vote:=RandomChoice[{data[[#,2]],data[[#,3]]}-> {1,-1}]&/@ Range[Length[data]];
test=Table[Vote,{100000}];H=Total[data[[All,4]](test[[#]]+1)/2]&/@ Range[Length[test]];T=Total[data[[All,4]](test[[#]]-1)/(-2)]&/@ Range[Length[test]];
ListPlot[{Sort[Counts[H]],Sort[Counts[T]  ]},PlotRange-> {{0,538},{0,1750} }  , PlotLegends->{"HC","DT"}, TargetUnits->{"EC Votes","n/100000"},AxesLabel->Automatic,GridLines->{{270},{0}}]

 

 

 

Beautiful bell curves aside, what are the odds?  Quantile[T, {0.01, 0.5, 0.99}] show Trump's odds at less than 1% with this state by state poll based model - which is perhaps not firmly attached to reality in a number of ways.  Nate Silver's rather more beautiful output lists 13.8% odds for Turnip as it appears he weights his model with a secret sauce of moving average, random forest and neural networks, a dash of common sense and with a pinch of accounting for historic poll variance.  Or perhaps he's just adding a well judged 7% layer of fat to those two bell curves.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
« A thought on this Fall's Election | Main | The brighter side of cultural appropriation »