Cross Validated Asked by pst0102 on February 6, 2021
I’m creating an elections index that’s adjusted by how close the results are expected to be for a number of upcoming races in the US. My simulated results include discrete values like seat counts for the Senate and House, and continuous values like the two party margin for governors races. But I’m having a hard time coming up with a comparable measure for how close these races are expected to be. My initial idea was to calculate the probability of a tie for each of them, but this doesn’t make sense for the House which has an odd number of seats, or for the governors races which have continuous percentages as outcomes.
My next approach was to normalize the simulated results and calculate the probability of outcomes across a small interval around the center:
import numpy as np
def normed_prob(a, bounds, interval=[0.475, 0.525]):
a = (a - bounds[0]) / (bounds[1] - bounds[0]) # Normalize over [0,1]
inside = a[(a > interval[0]) & (a < interval[1])] # Count occurrences
return len(inside)/len(a) # Calculate probability
# Fake election outcomes
dem_electoral_votes = np.round(np.random.normal(loc=269, scale=538*0.05, size=10000))
dem_house_seats = np.round(np.random.normal(loc=217.5, scale=435*0.05, size=10000))
dem_governor_margins = np.random.normal(loc=0.5, scale=0.05, size=10000)
az_senate_seats = np.round(np.random.normal(loc=15, scale=30*0.05, size=10000))
print(
'Presidential: {},'.format(normed_prob(dem_electoral_votes, bounds=[0, 538])),
'House: {},'.format(normed_prob(dem_house_seats, bounds=[0, 435])),
'Governor: {},'.format(normed_prob(dem_governor_margins, bounds=[0, 1])),
'AZ State Senate: {}'.format(normed_prob(az_senate_seats, bounds=[0, 30]))
)
# Presidential: 0.38, House: 0.3854, Governor: 0.3844, AZ State Senate: 0.2572
But this leads to weird outcomes like the Arizona State Senate above where, because the outcomes are discrete values that only range from 0-30, the arbitrary interval I choose "cuts off" more outcomes from this simulation than the others.
So my questions are:
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP