Jump to content

U.S. presidential election modelling


VenusPrincess

Recommended Posts

The FiveThirtyEight model is currently giving Biden an ~87% chance of winning. My own model gives Biden a ~74% chance of winning, details below. I ran 1,000,000 simulations Monte Carlo style, where the outcomes in each state are independent of one another. I split states into five categories:

1) Safe Republican - Assigned a probability of 1 to vote Republican

2) Safe Democrat - Assigned a probability of 0 to vote Republican

3) Won by Trump in 2016 but leans Democrat (Maine 2, Michigan, Pennsylvania, Wisconsin) - Assigned a probability of 0.4 to vote Republican

4) Won by Trump in 2016 and leans Republican (Florida, Iowa, Ohio) - Assigned a probability of 0.6 to vote Republican

5) Formerly safe Republican but could possibly flip (Arizona, Nebraska 2, North Carolina, Texas) - Assigned a probability of 0.9 to vote Republican

After 1,000,000 simulations these were the results:

Republicans: 234295
Democrats: 741461
Ties: 24244
Total: 1000000

Just in case anyone wants to play around with the probabilities here is the header file:

#ifndef STATE_H
#define STATE_H

#define LEANDEM 0.4 /* Trump won in 2016 but leans democrat */
#define KEEP 0.6 /* Trump won in 2016 and leans republican */
#define FLIP 0.9 /* Polls indicate may flip democrat */

struct state {
	char* name;		/* name of state */
	int votes;		/* number of electoral votes */
	double probr;		/* probability of voting republican */
} states[] = {
	"Alabama", 9, 1,
	"Alaska", 3, 1,
	"Arizona", 11, FLIP,
	"Arkansas", 6, 1,
	"California", 55, 0,
	"Colorado", 9, 0,
	"Connecticut", 7, 0,
	"Delaware", 3, 0,
	"District of Columbia", 3, 0,
	"Florida", 29, KEEP,
	"Georgia", 16, 1,
	"Hawaii", 4, 0,
	"Idaho", 4, 1,
	"Illinois", 20, 0,
	"Indiana", 11, 1,
	"Iowa", 6, KEEP,
	"Kansas", 6, 1,
	"Kentucky", 8, 1,
	"Louisiana", 8, 1,
	"Maine 1", 3, 0,
	"Maine 2", 1, LEANDEM,
	"Maryland", 10, 0,
	"Massachusetts", 11, 0,
	"Michigan", 16, LEANDEM,
	"Minnesota", 10, 0,
	"Mississippi", 6, 1,
	"Missouri", 10, 1,
	"Montana", 3, 1,
	"Nebraska 1", 4, 1,
	"Nebraska 2", 1, FLIP,
	"Nevada", 6, 0,
	"New Hampshire", 4, 0,
	"New Jersey", 14, 0,
	"New Mexico", 5, 0,
	"New York", 29, 0,
	"North Carolina", 15, FLIP,
	"North Dakota", 3, 1,
	"Ohio", 18, KEEP,
	"Oklahoma", 7, 1,
	"Oregon", 7, 0,
	"Pennsylvania", 20, LEANDEM,
	"Rhode Island", 4, 0,
	"South Carolina", 9, 1,
	"South Dakota", 3, 1,
	"Tennessee", 11, 1,
	"Texas", 38, FLIP,
	"Utah", 6, 1,
	"Vermont", 3, 0,
	"Virginia", 13, 0,
	"Washington", 12, 0,
	"West Virginia", 5, 1,
	"Wisconsin", 10, LEANDEM,
	"Wyoming", 3, 1
};

#endif

Here is the main loop:

#include <stdio.h>
#include <stdlib.h>
#include "state.h"
#include "time.h"

#define NDISTRICTS 53
#define RUNS 1000000

main()
{
	int dem;
	int rep;
	srand(time(NULL));
	double sample;
	int demwins = 0;
	int repwins = 0;
	int ties = 0;
	for (int i = 0; i < RUNS; i++)
	{
		dem = 0;
		rep = 0;
		for (int j = 0; j < NDISTRICTS; j++)
		{
			sample = (double)rand() / (RAND_MAX + 1.0);
			if (sample < states[j].probr) rep += states[j].votes;
			else dem += states[j].votes;
		}
		if (dem > 269) demwins++;
		else if (rep > 269) repwins++;
		else ties++;
	}
	int total = demwins + repwins + ties;
	printf("Republicans: %d\n", repwins);
	printf("Democrats: %d\n", demwins);
	printf("Ties: %d\n", ties);
	printf("Total: %d\n", total);
}

 

Link to comment
Share on other sites

10 hours ago, Sensei said:

@VenusPrincess

Why are you adding 1 in the line:


sample = (double)rand() / (RAND_MAX + 1.0);

rand() result can be up to RAND_MAX, so

RAND_MAX / ( RAND_MAX + 1 ) will never ever give you sample = 1.0 ...

32767 / 32768 = 0.999969482421875

I think I did it out of habit, it may have been important to exclude sample =1.0 in some other application where I did something similar. But here you are correct, I don't think it's necessary to add the 1.0

On a side note the implementation is flawed in a few ways. From stackoverflow:

Quote

Simply speaking, rand() / (RAND_MAX + 1.0) generates a floating-point random number between 0 (inclusive) and 1.0 (exclusive). More precisely (see http://en.cppreference.com/w/cpp/numeric/random/RAND_MAX for reference), the maximal number returned can be RAND_MAX / (RAND_MAX + 1.0). However, in the context of Monte-Carlo simulations there are several important points about such random number generator because RAND_MAX is usually 32767:

  1. The number of different random numbers that can be generated is too small: 32768. Often they run many more Monte-Carlo simulations - millions or billions - but such a limited random number generator makes pointless to run more than 32768 simulations
  2. The generated numbers are too coarse-grained: you can get 1/32768, 2/32768, 3/32768, but never anything in between.
  3. Limited states of random number generator engine: after generating RAND_MAX random numbers, implementations usually start to repeat the same sequence of random numbers.

But I don't think it's worth spending the extra time to fix it. I can't imagine it will have a huge impact on the estimate which is just a fun back of the napkin type calculation anyway.

Edited by VenusPrincess
Link to comment
Share on other sites

Quote

The number of different random numbers that can be generated is too small: 32768.

Correct. Using built-in C/C++ srand()/rand(). But you are free to use alternative pRNG..

Pick up one

https://en.wikipedia.org/wiki/List_of_random_number_generators

Quote

Often they run many more Monte-Carlo simulations - millions or billions - but such a limited random number generator makes pointless to run more than 32768 simulations

That's not true (i.e. it can be easily bypassed).. You just need to restart with different random seed at random moment.. but you have to use milliseconds, microseconds or nanoseconds timers to initialize random seed for a start.

1 hour ago, VenusPrincess said:

The generated numbers are too coarse-grained: you can get 1/32768, 2/32768, 3/32768, but never anything in between.

That's also not true (i.e. it can be easily bypassed).. You just need to generate two or more random values, rather than just one. e.g. ( rand() * ( RAND_MAX+1 ) + rand() ) will give you RAND_MAX ^2 = 1 073 741 824 values between. Casting to float (32 bit) will even cut some digits (mantissa of single IEEE 754 has 23 bits). If intended to be used with double (64 bit), you can use 4x rand() merged together like above in a row.

1 hour ago, VenusPrincess said:

But I don't think it's worth spending the extra time to fix it. I can't imagine it will have a huge impact on the estimate which is just a fun back of the napkin type calculation anyway.

People learn on mistakes. So they must be clearly stated. If somebody will read these posts in the future, must know that there was some issue with it. Otherwise will think it's correct and will repeat your mistake by himself/herself.

 

1 hour ago, VenusPrincess said:

On a side note the implementation is flawed in a few ways. From stackoverflow:

In your link there is example source code with much better implementation of pRNG code (with high precision timer, and better quality pRNG)... and you cut it out in your reply..

Edited by Sensei
Link to comment
Share on other sites

16 hours ago, VenusPrincess said:

Not you I guess. You're too smart to care about stuff like this. You're a proper nihilist like all great intellectuals.

Sure. I was short. I can accept your neg rep. That said, my central point remains: Why should we bother with your remedial model here when models from others (like FiveThirtyEight, whom you cited yourself) are far more informed, advanced, inclusive, and accurate? 

16 hours ago, VenusPrincess said:

You're too smart to care about stuff like this.

Stuff like what? You put this into the Politics forum. Had you put into Computer Science instead then my response would have been much different. 

Link to comment
Share on other sites

I ran my own 'model' also.

Against :
1 - Don't like his domestic policy.
2 - Don't like his foreign policy.
3 - Don't like where the Country is headed.
4 - Don't like his lack of coronavirus response.
5 - Don't like him personally.

For :
1 - The ability of some Americans to wallow in their ignorance continues to surprise me.

That's 5 against re-election, and one slim hope for D Trump's re-election.
So I give him 5 to 1 odds.

My coding is not as pretty ( last time I coded anything elaborate, was using FORTRAN, though I dabbled in assembly, Forth, Pascal and various flavors of Basic ), but gives similar results.
What do you think INow ?

 

Link to comment
Share on other sites

2 hours ago, Sensei said:

Correct. Using built-in C/C++ srand()/rand(). But you are free to use alternative pRNG..

Pick up one

If I have time I might implement something better, could be interesting to see how it affects the estimate.

59 minutes ago, iNow said:

Sure. I was short. I can accept your neg rep. That said, my central point remains: Why should we bother with your remedial model here when models from others (like FiveThirtyEight, whom you cited yourself) are far more informed, advanced, inclusive, and accurate? 

Stuff like what? You put this into the Politics forum. Had you put into Computer Science instead then my response would have been much different. 

I didn't neg you. People might be interested in trying their own probability weights which is why I shared.

Link to comment
Share on other sites

1 hour ago, MigL said:

What do you think INow ?

I think your model is about as good as the OPs. I also think it’s closer than you suggest. Biden is up in polls nationally, but we don’t vote nationally. We vote state by state, and our votes aren’t even what matter. What matters is how electors in the electoral college act when they meet on December 14.

Link to comment
Share on other sites

2 hours ago, MigL said:

The ability of some Americans to wallow in their ignorance continues to surprise me.

If only it was just ignorance. At this point we see full frontal insanity. And I do not mean that in a partisan way. I mean taking what kids post on a trolling board seriously and make it mainstream, kind of of insane. I mean, there are just so many things just over the top (A prophetic internet troll? Satanic child sacrifices?), it is honestly scary that folks think them to be true and effing run for congress.

Link to comment
Share on other sites

2 hours ago, iNow said:

our votes aren’t even what matter

You really are a nihilist. Irrationally so. Why are you so jaded?

2 hours ago, iNow said:

What matters is how electors in the electoral college act when they meet on December 14.

Faithless electors are not common, so yes your votes do matter.

2 hours ago, iNow said:

I think your model is about as good as the OPs.

Ignoring problems with not accounting for the covariance between state outcomes, do you think the probability weights are very far off?

Link to comment
Share on other sites

10 hours ago, Sensei said:

Correct. Using built-in C/C++ srand()/rand(). But you are free to use alternative pRNG..

Pick up one

https://en.wikipedia.org/wiki/List_of_random_number_generators

C++ supports state-of-the-art random number generation. So it would be easiest to use a c++ compiler for the code (I expect that it should compile the C parts just fine) and pick an rng that is provided by the language standard library. So: Pick up to one: http://www.cplusplus.com/reference/random/ .

 

I do not expect that the choice of the rng matters for this case. But it is a good habit to never run a Monte-Carlo simulation without a good rng, and including one is really easy in most programming languages.

Link to comment
Share on other sites

On 10/23/2020 at 1:12 PM, Culture Citizen said:
!

Moderator Note

Please avoid throwing links at people under the assumption they'll understand exactly how you're applying an argument from them. It's against the rules to require anyone to go offsite in order to participate in a conversation. Give some context or provide specific quotes from the article so the membership doesn't have to dig to find your meaning.

 
Link to comment
Share on other sites

On 10/25/2020 at 7:28 AM, Phi for All said:
!

Moderator Note

Please avoid throwing links at people under the assumption they'll understand exactly how you're applying an argument from them. It's against the rules to require anyone to go offsite in order to participate in a conversation. Give some context or provide specific quotes from the article so the membership doesn't have to dig to find your meaning.

 

You assume I presented an argument, or/and entertained conversation.

Link to comment
Share on other sites

On 10/19/2020 at 7:28 PM, MigL said:

I ran my own 'model' also.

Against :
1 - Don't like his domestic policy.
2 - Don't like his foreign policy.
3 - Don't like where the Country is headed.
4 - Don't like his lack of coronavirus response.
5 - Don't like him personally.

For :
1 - The ability of some Americans to wallow in their ignorance continues to surprise me.

That's 5 against re-election, and one slim hope for D Trump's re-election.
So I give him 5 to 1 odds.

My coding is not as pretty ( last time I coded anything elaborate, was using FORTRAN, though I dabbled in assembly, Forth, Pascal and various flavors of Basic ), but gives similar results.
What do you think INow ?

 

I give him at least a pass on that one (note that this is policy not rhetoric)

2-Not particularly enamoured by the Dems either

So i'm 4-2 or 2-1.

I think it would be best (read least worst) if he lost just decisively enough that the decision is clear democratically. Hopefully by not so much that the Democrats see it as an endorsement of their identity politics, but that's probably not possible...if they win through the electoral college they no doubt dominate the popular vote.

Link to comment
Share on other sites

3 hours ago, J.C.MacSwell said:

Hopefully by not so much that the Democrats see it as an endorsement of their identity politics, but that's probably not possible...if they win through the electoral college they no doubt dominate the popular vote.

Like it or not, a big part is a referendum on identity politics. One, which is basically based on white supremacy or the other which at least outwardly embraces the diversity as a result of demographic shifts.

Link to comment
Share on other sites

Yeah. This whole “Democrats use identity politics” line rings hollow for me as we see identity being almost the sole driver of Republican turnout. It’s probably time to update that stale talking point, JCM. 

Link to comment
Share on other sites

4 hours ago, CharonY said:

Like it or not, a big part is a referendum on identity politics. One, which is basically based on white supremacy or the other which at least outwardly embraces the diversity as a result of demographic shifts.

You need a third party that rejects both.

Link to comment
Share on other sites

5 hours ago, CharonY said:

How would folks identify with them instead?

 

9 hours ago, CharonY said:

One, which is basically based on white supremacy or the other which at least outwardly embraces the diversity as a result of demographic shifts.

Respectfully where possible. Recognize and stop the political weaponization of it. One can call out white supremacy without calling everyone who might consider voting for Trump as supporting it, and one can embrace diversity without condoning or participating in the worst aspects of it.

 

8 hours ago, iNow said:

Yeah. This whole “Democrats use identity politics” line rings hollow for me as we see identity being almost the sole driver of Republican turnout. It’s probably time to update that stale talking point, JCM. 

Democrats using identity politics rings hollow for you because you feel the Republicans do it more?

Edited by J.C.MacSwell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.