Sam Trenholme's webpage
Support this website or listen to my music

Predicting the election


October 15 2012

I am discussing politics again. As per my previous promise, I will not waste my readers' time with my personal opinions. Instead, I am looking at a couple of models of the election and predicting the winner.

Finding a model to use for the vote

Right now, Nate Silver at is saying Obama has about a 66% chance of winning. This comes from, admittedly, a left-leaning source, so take that number with as much (or little) salt as needed -- if anyone knows of a more right-leaning source with state-by-state win prediction percentages, I will gladly run a simulation with their numbers. (Update Nerd wallet uses the same methodology as I do, and Obama shows a 67.4% chance of winning when I run their numbers).

What I have done is write down the chance of Obama or Romney getting a given state from his state-by-state numbers and then ran a simulation which assumes a given state going for a candidate does not affect the other states.

In more detail, using a strong random number generator (details below), I rolled a 1000-sided dice for each state and/or district with electoral votes. In this model, for example, Florida has a 63.3% percent chance of voting for Romney, so if the dice rolled a 367 or higher, I gave the state to Romney; otherwise I gave it to Obama.

I did this for all states and districts 100,000 times. The results were as follows:

Obama  81.9%
Romney 16.8%
Tie     1.3%
I wonder why Nate is getting a 66.6% chance for Obama from the same numbers; perhaps he is coupling results more than I have (for example, if Romney gets Iowa in a given simulation, Nate probably lowers Obama's chances of getting Florida).

As an aisde, I also ran this simulation against some more liberal numbers from Huffpost; their numbers give Obama a 98.1% chance of winning.

New Hampshire

While New Hampshire has only four electoral votes, it is still a very key swing state. Right now, Nate's model gives New Hampshire a 71.4% chance of going for Obama (which is higher than, which currently says that Romney has a 2% lead in this state).

What I have done is go through the results of my 100,000 run simulation and compared the chances of winning depending on how New Hampshire goes. Here are my results:

Obama wins New Hampshire
Obama wins election    83.5%
Electoral vote tie      1.4%
Romney wins election   15.1%

Romney wins New Hampshire
Obama wins election    77.9%
Electoral vote tie      1.0%
Romney wins election   21.1%

While New Hampshire has under 1% of the electoral votes in the nation, its influence on the election results, according to my model (loosely based on Nate's model) is 6%.

In summary: Voters in New Hampshire are best off getting out and voting, and voting for one of the two main candidates this election cycle. (Update The Nerd wallet numbers show a nearly identical 6% effect on the outcome).

The random number generator

The random number generator I am using is something oddball called RadioGatun. While RadioGatun is rather obscure, its direct successor, Keccak, just won the SHA-3 competition. This is a very good number generator for using with this kind of simulation; I ran a bunch of statistical tests against it a couple of years ago and it passes with flying colors.

For the record, here is the source code to the core of the random number generator:

/* Public domain crypto-strong random number generator; no warranty */
#include <stdint.h>
#define rgp uint32_t
#define rgf(a) for(c=0;c<a;c++)
#define rgn rgf(3){w[c*13]^=s[c];u[16+c]^=s[c];}rgk(u,w);
void rgk(rgp *a,rgp *b){rgp A[19],x,m=19,o=13,c,y,r=0,q[3],i=o;rgf(3){q
(c+1)%m]^A[(c+4)%m];}a[0]^=1;rgf(3){a[c+o]^=q[c];}}void rgl(rgp *u, rgp
*w,char *v){rgp s[3],q,c,r,x,d=0;rgf(19){u[c]=0;}rgf(39){w[c]=0;}for(;;
s[r]|=x<<q;if(d){rgn;rgf(16){rgk(u,w);}return;}}}rgn;}}rgp rgi(rgp *m,
rgp *b){static int a=2;a&2?rgk(m,b):0;a^=3;return m[a];}

Previous entry Next entry Blog index