What is wrong with my method for predicting the election?

  • Context: JavaScript 
  • Thread starter Thread starter SlurrerOfSpeech
  • Start date Start date
  • Tags Tags
    Method
Click For Summary

Discussion Overview

The discussion revolves around a method for predicting election outcomes using probabilistic modeling based on electoral votes from various states. Participants explore the validity of the approach, the calculations involved, and the implications of the results obtained.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a method of selecting subcollections of states to predict the probability of a candidate winning based on electoral votes.
  • Another participant points out that the extrapolation from a small sample size may lead to inaccurate results, suggesting that the calculations are significantly off.
  • A participant expresses confusion about consistently obtaining a result around 0.99 instead of the expected 0.50, given equal chances for both candidates.
  • Code snippets are provided to illustrate the method, including functions for calculating winning chances and checking electoral vote sufficiency.
  • One participant suggests using statistical measures like medians or means with a distribution instead of iterating over all outcomes, emphasizing the importance of controlling variance.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the validity of the method or the reasons for the unexpected results. Multiple competing views and uncertainties remain regarding the approach and its calculations.

Contextual Notes

The discussion includes limitations related to the sample size, the assumptions made in the calculations, and the potential for significant variance in the results based on the chosen method.

SlurrerOfSpeech
Messages
141
Reaction score
11
Given the fact that there are 51 states and districts, there are 251 subcollections of the 51 states, which I can't possibly iterate over entirely. So what I do is find 210 subcollections of states whose electoral votes summed are 270 or greater. I then sum together the probabilities of Trump winning each of those 210 collection of states. Finally, I multiply that sum by 241.

Anything wrong with that? Because I'm getting a results that seems wrong.
 
Technology news on Phys.org
You're extrapolating a small sample - comparing to (##2^{51}##), by a huge number (##2^{41}##) so the result is way off.
 
Can you help me figure out why this is always calculating to ~0.99? It should be calculating to ~0.50 since I put an equal chance of an R or D winning.

Code:
const VOTES_TO_WIN = 270;

// State name, number of electoral votes, and Republican and
// Democrat nominee polling percent average taken from
// RealClearPolitics.com, rounded to nearest integer
const dataByState = {
    'Washington' : { ElectoralVotes : 12, RChance: 50, DChance: 50 },
    'Oregon': { ElectoralVotes: 7, RChance: 50, DChance: 50 },
    'California': { ElectoralVotes: 55, RChance: 50, DChance: 50 },
    'Idaho' : { ElectoralVotes: 4, RChance : 50, DChance: 50 },
    'Nevada' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Montana' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'Wyoming' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'Colorado' : { ElectoralVotes: 9, RChance : 50, DChance: 50 },
    'New Mexico' : { ElectoralVotes: 5, RChance : 50, DChance: 50 },
    'Utah' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Arizona' : { ElectoralVotes: 11, RChance : 50, DChance: 50 },
    'North Dakota' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'South Dakota' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'Nebraska' : { ElectoralVotes: 5, RChance : 50, DChance: 50 },
    'Kansas' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Oklahoma' : { ElectoralVotes: 7, RChance : 50, DChance: 50 },
    'Texas' : { ElectoralVotes: 38, RChance : 50, DChance: 50 },
    'Minnesota' : { ElectoralVotes: 10, RChance : 50, DChance: 50 },
    'Iowa' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Missouri' : { ElectoralVotes: 10, RChance : 50, DChance: 50 },
    'Arkansas' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Lousiana' : { ElectoralVotes: 8, RChance : 50, DChance: 50 },
    'Wisconsin' : { ElectoralVotes: 10, RChance : 50, DChance: 50 },
    'Illinois' : { ElectoralVotes: 20, RChance : 50, DChance: 50 },
    'Tennessee' : { ElectoralVotes: 11, RChance : 50, DChance: 50 },
    'Mississippi' : { ElectoralVotes: 6, RChance : 50, DChance: 50 },
    'Alabama' : { ElectoralVotes: 9, RChance : 50, DChance: 50 },
    'Michigan' : { ElectoralVotes: 16, RChance : 50, DChance: 50 },
    'Indiana' : { ElectoralVotes: 11, RChance : 50, DChance: 50 },
    'Kentucky' : { ElectoralVotes: 8, RChance : 50, DChance: 50 },
    'Ohio' : { ElectoralVotes: 18, RChance : 50, DChance: 50 },
    'West Virginia' : { ElectoralVotes: 5, RChance : 50, DChance: 50 },
    'Virginia' : { ElectoralVotes: 13, RChance : 50, DChance: 50 },
    'North Carolina' : { ElectoralVotes: 15, RChance : 50, DChance: 50 },
    'South Carolina' : { ElectoralVotes: 9, RChance : 50, DChance: 50 },
    'Georgia' : { ElectoralVotes: 16, RChance : 50, DChance: 50 },
    'Florida' : { ElectoralVotes: 29, RChance : 50, DChance: 50 },
    'D.C.' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'Maryland' : { ElectoralVotes: 10, RChance : 50, DChance: 50 },
    'Delaware' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'New Jersey' : { ElectoralVotes: 14, RChance : 50, DChance: 50 },
    'Pennsylvania' : { ElectoralVotes: 20, RChance : 50, DChance: 50 },
    'Connectuicut' : { ElectoralVotes: 7, RChance : 50, DChance: 50 },
    'Rhode Island' : { ElectoralVotes: 4, RChance : 50, DChance: 50 },
    'Massachusetts' : { ElectoralVotes: 11, RChance : 50, DChance: 50 },
    'New York' : { ElectoralVotes: 29, RChance : 50, DChance: 50 },
    'Vermont' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'New Hampshire' : { ElectoralVotes: 4, RChance : 50, DChance: 50 },
    'Maine' : { ElectoralVotes: 4, RChance : 50, DChance: 50 },
    'Alaska' : { ElectoralVotes: 3, RChance : 50, DChance: 50 },
    'Hawaii' : { ElectoralVotes: 4, RChance : 50, DChance: 50 }
};

const states = Object.keys(dataByState);

// Helper for using the above map to get a chance of winning
// from a given poll difference
const calcWinChance = (diff) => {
    const conv = pollConversion.find((x) =>
        x.DiffRange[0] <= diff && x.DiffRange[1] >= diff
    );
    return conv && conv.ChanceWin;
}// Helper returns true or false depending on whether a given
// collection of states has enough combined electoral votes
// to win an election
const hasSufficientVotes = (states) => {
    const votes = states.reduce((sum,state) =>
        sum += dataByState[state].ElectoralVotes
    , 0);
    return votes >= VOTES_TO_WIN;
};

// Helper for getting the combination of states corresponding
// to the inputted bit pattern i
const getCombo = (i) => {
    let combo = [];
    for(var j = 0; j < states.length; ++j)
       if((i >> j) & 1)
           combo.push(states[j]);  
    return combo;      
}

// To be filled out, combos will be a map of a bit pattern
// to the corresponding array of state names
let combos = {};

// Set time limit on
const now = new Date();
const timeout = now.setSeconds(now.getSeconds() + 1); // 1 seconds

// Run simulation
const rangetop = Math.pow(2,states.length) + 1;
while(new Date() < timeout)
{
    const rand = Math.floor(Math.random() * rangetop); 
    if(!combos.hasOwnProperty(rand))
        combos[rand] = getCombo(rand);
}

// Sum up the probabilites of the R candidate winning each
// combination of states that add up to a succifient number
// of electoral votes
let RSum = 0;
const keynums = Object.keys(combos);
console.log("num combos = " + keynums.length);//TEST
keynums.forEach((num) => {
  
    const comboStates = combos[num];
  
    // state combo not counted if it doesn't add up
    // to enough electoral votes
    if(!hasSufficientVotes(comboStates))
        return;
  
    // mutltipy together the probabilities of the R
    // winning the state combo
    let RProb = 1;
    comboStates.forEach((state) => {
        RProb *= dataByState[state].RChance / 100;
    });
    const otherStates = states.filter((state) => !comboStates.includes(state));
    otherStates.forEach((state) => {
        RProb *= dataByState[state].DChance / 100; 
    });

    RSum += RProb;
});

const multiplier = Math.pow(2, states.length + 1) / keynums.length;
RSum *= multiplier;

alert("RSum = " + RSum);
 
Hey SlurrerOfSpeech.

Are you trying to do a probabilistic/statistical estimate?

If so you could look at doing medians or means with a distribution as opposed to iterating over every outcome and use probabilities to gauge whether an outcome for some group/organization will occur.

The issue you should have is controlling the variance and depending on the constraints you have, you can shrink them dramatically if the information exists.
 
chiro said:
Hey SlurrerOfSpeech.

Are you trying to do a probabilistic/statistical estimate?

If so you could look at doing medians or means with a distribution as opposed to iterating over every outcome and use probabilities to gauge whether an outcome for some group/organization will occur.

The issue you should have is controlling the variance and depending on the constraints you have, you can shrink them dramatically if the information exists.

I will try this. Thanks. :)
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 70 ·
3
Replies
70
Views
9K
  • · Replies 12 ·
Replies
12
Views
14K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 39 ·
2
Replies
39
Views
7K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K