Skip to content
Browse files

Updated with new poll results (5/11/2012)

  • Loading branch information...
1 parent 995e40d commit 70979353490063e55b09a0adaeb900b636d7141c @chris-taylor committed
View
1,786 data/2012-pres-polls.csv
906 additions, 880 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
6 forecast/USElectionForecast2004.csv
@@ -34,9 +34,9 @@ New Mexico,REP,65%
New York,DEM,100%
North Carolina,REP,99%
North Dakota,REP,100%
-Ohio,REP,61%
+Ohio,REP,62%
Oklahoma,REP,100%
-Oregon,DEM,99%
+Oregon,DEM,100%
Pennsylvania,DEM,97%
Rhode Island,DEM,100%
South Carolina,REP,100%
@@ -48,5 +48,5 @@ Vermont,DEM,96%
Virginia,REP,96%
Washington,DEM,96%
West Virginia,REP,87%
-Wisconsin,REP,50%
+Wisconsin,DEM,50%
Wyoming,REP,100%
View
4 forecast/USElectionForecast2008.csv
@@ -2,7 +2,7 @@ State,Winner,Confidence
Alabama,REP,100%
Alaska,REP,100%
Arizona,REP,92%
-Arkansas,REP,99%
+Arkansas,REP,98%
California,DEM,100%
Colorado,DEM,100%
Connecticut,DEM,100%
@@ -42,7 +42,7 @@ Rhode Island,DEM,100%
South Carolina,REP,100%
South Dakota,REP,93%
Tennessee,REP,94%
-Texas,REP,99%
+Texas,REP,100%
Utah,REP,100%
Vermont,DEM,100%
Virginia,DEM,100%
View
22 forecast/USElectionForecast2012.csv
@@ -1,20 +1,20 @@
State,Winner,Confidence
Alabama,REP,99%
Alaska,REP,100%
-Arizona,REP,70%
+Arizona,REP,93%
Arkansas,REP,100%
California,DEM,100%
-Colorado,DEM,60%
+Colorado,REP,50%
Connecticut,DEM,100%
Delaware,DEM,100%
District of Columbia,DEM,100%
-Florida,REP,63%
+Florida,REP,75%
Georgia,REP,93%
Hawaii,DEM,100%
Idaho,REP,100%
Illinois,DEM,100%
Indiana,REP,100%
-Iowa,DEM,81%
+Iowa,DEM,82%
Kansas,REP,97%
Kentucky,REP,97%
Louisiana,REP,97%
@@ -25,27 +25,27 @@ Michigan,DEM,99%
Minnesota,DEM,100%
Mississippi,REP,95%
Missouri,REP,99%
-Montana,REP,99%
+Montana,REP,100%
Nebraska,REP,100%
-Nevada,DEM,91%
-New Hampshire,DEM,59%
+Nevada,DEM,90%
+New Hampshire,DEM,68%
New Jersey,DEM,100%
New Mexico,DEM,100%
New York,DEM,100%
-North Carolina,REP,73%
+North Carolina,REP,67%
North Dakota,REP,100%
Ohio,DEM,99%
Oklahoma,REP,100%
-Oregon,DEM,92%
+Oregon,DEM,93%
Pennsylvania,DEM,99%
Rhode Island,DEM,100%
South Carolina,REP,80%
-South Dakota,REP,96%
+South Dakota,REP,86%
Tennessee,REP,100%
Texas,REP,98%
Utah,REP,100%
Vermont,DEM,100%
-Virginia,DEM,74%
+Virginia,DEM,76%
Washington,DEM,100%
West Virginia,REP,97%
Wisconsin,DEM,95%
View
52 forecast/USElectionForecastFormatted2004.txt
@@ -0,0 +1,52 @@
+State Winner Confidence
+District of Columbia DEM 100%
+New York DEM 100%
+Maryland DEM 100%
+Rhode Island DEM 100%
+Oregon DEM 100%
+California DEM 99%
+New Jersey DEM 99%
+Massachusetts DEM 98%
+Minnesota DEM 98%
+Pennsylvania DEM 97%
+Illinois DEM 97%
+Maine DEM 96%
+Washington DEM 96%
+Vermont DEM 96%
+Connecticut DEM 90%
+Michigan DEM 90%
+Delaware DEM 85%
+New Hampshire DEM 67%
+Wisconsin DEM 50%
+Florida REP 50%
+Iowa REP 50%
+Hawaii REP 54%
+Ohio REP 62%
+New Mexico REP 65%
+West Virginia REP 87%
+Mississippi REP 88%
+Arkansas REP 95%
+Virginia REP 96%
+Missouri REP 96%
+Nevada REP 97%
+Colorado REP 99%
+North Carolina REP 99%
+Arizona REP 100%
+South Dakota REP 100%
+North Dakota REP 100%
+South Carolina REP 100%
+Georgia REP 100%
+Indiana REP 100%
+Alabama REP 100%
+Nebraska REP 100%
+Alaska REP 100%
+Montana REP 100%
+Idaho REP 100%
+Kansas REP 100%
+Kentucky REP 100%
+Louisiana REP 100%
+Oklahoma REP 100%
+Tennessee REP 100%
+Texas REP 100%
+Utah REP 100%
+Wyoming REP 100%
View
52 forecast/USElectionForecastFormatted2008.txt
@@ -0,0 +1,52 @@
+State Winner Confidence
+California DEM 100%
+District of Columbia DEM 100%
+Hawaii DEM 100%
+Illinois DEM 100%
+Iowa DEM 100%
+Massachusetts DEM 100%
+Michigan DEM 100%
+Minnesota DEM 100%
+New Hampshire DEM 100%
+New Jersey DEM 100%
+New York DEM 100%
+Oregon DEM 100%
+Pennsylvania DEM 100%
+Washington DEM 100%
+Wisconsin DEM 100%
+Connecticut DEM 100%
+Virginia DEM 100%
+Delaware DEM 100%
+Rhode Island DEM 100%
+Maine DEM 100%
+Ohio DEM 100%
+Colorado DEM 100%
+Vermont DEM 100%
+Maryland DEM 100%
+New Mexico DEM 99%
+Florida DEM 99%
+Nevada DEM 98%
+North Carolina DEM 73%
+North Dakota DEM 61%
+Missouri REP 50%
+Indiana REP 81%
+Montana REP 87%
+Arizona REP 92%
+South Dakota REP 93%
+Tennessee REP 94%
+Georgia REP 98%
+Arkansas REP 98%
+West Virginia REP 99%
+Nebraska REP 99%
+Texas REP 100%
+Kansas REP 100%
+Louisiana REP 100%
+South Carolina REP 100%
+Kentucky REP 100%
+Mississippi REP 100%
+Alaska REP 100%
+Alabama REP 100%
+Idaho REP 100%
+Oklahoma REP 100%
+Utah REP 100%
+Wyoming REP 100%
View
104 forecast/USElectionForecastFormatted2012.csv
@@ -1,52 +1,52 @@
-State Winner Confidence
-California DEM 100%
-Connecticut DEM 100%
-Delaware DEM 100%
-D.C. DEM 100%
-Hawaii DEM 100%
-Illinois DEM 100%
-Maryland DEM 100%
-Massachusetts DEM 100%
-Minnesota DEM 100%
-New Jersey DEM 100%
-New Mexico DEM 100%
-New York DEM 100%
-Rhode Island DEM 100%
-Vermont DEM 100%
-Washington DEM 100%
-Michigan DEM 99%
-Ohio DEM 99%
-Pennsylvania DEM 99%
-Maine DEM 97%
-Wisconsin DEM 95%
-Oregon DEM 92%
-Nevada DEM 91%
-Iowa DEM 81%
-Virginia DEM 74%
-Colorado DEM 60%
-New Hampshire DEM 59%
-Alaska REP 100%
-Arkansas REP 100%
-Idaho REP 100%
-Indiana REP 100%
-Nebraska REP 100%
-North Dakota REP 100%
-Oklahoma REP 100%
-Tennessee REP 100%
-Utah REP 100%
-Wyoming REP 100%
-Alabama REP 99%
-Missouri REP 99%
-Montana REP 99%
-Texas REP 98%
-Kansas REP 97%
-Kentucky REP 97%
-Louisiana REP 97%
-West Virginia REP 97%
-South Dakota REP 96%
-Mississippi REP 95%
-Georgia REP 93%
-South Carolina REP 80%
-North Carolina REP 73%
-Arizona REP 70%
-Florida REP 63%
+State Winner Confidence
+California DEM 100%
+Connecticut DEM 100%
+District of Columbia DEM 100%
+Massachusetts DEM 100%
+New York DEM 100%
+Vermont DEM 100%
+Washington DEM 100%
+Maryland DEM 100%
+Hawaii DEM 100%
+New Jersey DEM 100%
+Delaware DEM 100%
+Minnesota DEM 100%
+Rhode Island DEM 100%
+Illinois DEM 100%
+New Mexico DEM 99%
+Ohio DEM 99%
+Pennsylvania DEM 99%
+Michigan DEM 99%
+Maine DEM 97%
+Wisconsin DEM 95%
+Oregon DEM 93%
+Nevada DEM 91%
+Iowa DEM 82%
+Virginia DEM 76%
+New Hampshire DEM 68%
+Colorado DEM 50%
+North Carolina REP 67%
+Florida REP 75%
+South Carolina REP 80%
+South Dakota REP 86%
+Georgia REP 93%
+Arizona REP 93%
+Mississippi REP 95%
+Louisiana REP 97%
+Kentucky REP 97%
+Kansas REP 97%
+West Virginia REP 97%
+Texas REP 98%
+Missouri REP 99%
+Alabama REP 99%
+Alaska REP 100%
+Nebraska REP 100%
+Montana REP 100%
+Tennessee REP 100%
+Indiana REP 100%
+Oklahoma REP 100%
+Arkansas REP 100%
+North Dakota REP 100%
+Wyoming REP 100%
+Idaho REP 100%
+Utah REP 100%
View
52 forecast/USElectionForecastFormatted2012.txt
@@ -0,0 +1,52 @@
+State Winner Confidence
+California DEM 100%
+Connecticut DEM 100%
+District of Columbia DEM 100%
+Massachusetts DEM 100%
+New York DEM 100%
+Vermont DEM 100%
+Washington DEM 100%
+Maryland DEM 100%
+Hawaii DEM 100%
+New Jersey DEM 100%
+Delaware DEM 100%
+Minnesota DEM 100%
+Rhode Island DEM 100%
+Illinois DEM 100%
+New Mexico DEM 100%
+Ohio DEM 99%
+Pennsylvania DEM 99%
+Michigan DEM 99%
+Maine DEM 97%
+Wisconsin DEM 95%
+Oregon DEM 93%
+Nevada DEM 90%
+Iowa DEM 82%
+Virginia DEM 76%
+New Hampshire DEM 68%
+Colorado DEM 50%
+North Carolina REP 67%
+Florida REP 75%
+South Carolina REP 80%
+South Dakota REP 86%
+Georgia REP 93%
+Arizona REP 93%
+Mississippi REP 95%
+Louisiana REP 97%
+Kansas REP 97%
+Kentucky REP 97%
+West Virginia REP 97%
+Texas REP 98%
+Missouri REP 99%
+Alabama REP 99%
+Alaska REP 100%
+Nebraska REP 100%
+Montana REP 100%
+Indiana REP 100%
+Tennessee REP 100%
+Oklahoma REP 100%
+Arkansas REP 100%
+Wyoming REP 100%
+Idaho REP 100%
+North Dakota REP 100%
+Utah REP 100%
View
49 master.matlab
@@ -21,10 +21,24 @@ function master(year,window,method)
fprintf(' P(GOP win) = %6.2f%%\n',100*result.pGopWin)
fprintf(' P(Tie) = %6.2f%%\n',100*result.pTied)
+ % Probability of particular vote ranges
+ ranges = {[0 309]
+ [310 329]
+ [330 349]
+ [350 369]
+ [370 389]
+ [390 538]};
+ fprintf('Probability of democratic EV total:\n');
+ for ii = 1:length(ranges)
+ r = ranges{ii};
+ loc = result.demVotes >= r(1) & result.demVotes <= r(2);
+ prob = mean(loc);
+ fprintf(' %3d-%3d: %4.0f%%\n',r(1),r(2),100*prob);
+ end
+
% Write output file
fname = sprintf('forecast/USElectionForecast%s.csv',num2str(year));
fid = fopen(fname,'w');
-
fprintf(fid,'State,Winner,Confidence\n');
for ii = 1:length(result.state)
@@ -40,6 +54,26 @@ function master(year,window,method)
end
fclose(fid);
+ % Write nicely formatted output file
+ fname = sprintf('forecast/USElectionForecastFormatted%s.txt',num2str(year));
+ fid = fopen(fname,'w');
+ fprintf(fid,'State Winner Confidence\n')
+ [tmp idx] = sort(result.pStateGop);
+
+ for ii = 1:length(result.state)
+ if result.pStateDem(idx(ii)) > 0.5
+ party = 'DEM';
+ conf = 100 * result.pStateDem(idx(ii));
+ else
+ party = 'REP';
+ conf = 100 * result.pStateGop(idx(ii));
+ end
+ fprintf(fid,'%-23s%-8s%-.0f%%\n',result.state{idx(ii)},party,conf);
+ end
+ fclose(fid);
+
+
+
% Plot a histogram of electoral college votes
ev = loadElectoralVotes;
totalEV = sum(ev.ev);
@@ -50,20 +84,19 @@ function master(year,window,method)
plot([totalEV totalEV]/2, ylimits, 'r');
hold off
-
- xlabel('Total electoral college votes (DEM)')
- ylabel('Number of simulations')
- legend({'Electoral college votes','Required to win'})
+ xlabel('Total electoral college votes (DEM)');
+ ylabel('Number of simulations');
+ legend({'Electoral college votes','Required to win'});
% If looking at 2004 or 2008 data, assess forecasts
if ismember(year,[2004 2008])
assessment = compareForecast(year);
- fprintf('Forecast performance:\n')
+ fprintf('Forecast performance:\n');
fprintf(' %d / 51 correctly forecast\n',assessment.nCorrect);
- fprintf('Incorrect predictions:\n')
+ fprintf('Incorrect predictions:\n');
for ii = 1:length(assessment.wrong)
- fprintf(' %s\n',assessment.wrong{ii})
+ fprintf(' %s\n',assessment.wrong{ii});
end
end
View
2 runModel.matlab
@@ -1,6 +1,6 @@
function results = runModel(data)
- nSimulation = 1e5; % Number of times to simulate each state
+ nSimulation = 1e5; % Number of times to simulate each state
nRespondents = 150; % Number of poll respondents (assumed)
results.state = data.state;
View
19 switchExtensions.matlab
@@ -0,0 +1,19 @@
+function switchExtensions(from,to)
+%SWITCHEXTENSIONS Rename all files with the extension 'from' to have
+%extension 'to'.
+
+ contents = dir();
+
+ for ii = 1:length(contents)
+
+ [directory filename extension] = fileparts(contents(ii).name);
+
+ if strcmp(extension,from)
+ old_name = [filename from];
+ new_name = [filename to];
+ movefile(old_name,new_name);
+ end
+
+ end
+
+end

0 comments on commit 7097935

Please sign in to comment.
Something went wrong with that request. Please try again.