-
-
Save NaimKabir/108c2992c9c6c8f0f09e2586e641f30f to your computer and use it in GitHub Desktop.
To be even more general, taking into account uniform distributions on overall partyline voting 25% - 75%, Republican non-partyline voting 75% - 95%, and Dem/Indep non-partyline voting 10% - 40%, so a better monte carlo is done over 1000 precincts. The result is largely the same, with even less of a slope, and a bit more scatter. Again, I don't see how the data Dr. Shiva showed is possible. Something is going on in those counties. We need access to the data he is seeing.
import numpy as np
import matplotlib.pyplot as plt
num_precincts = 1000 # let's deal with 1000 precincts.
r_partyline_percentages = np.random.rand(num_precincts) # modeling the fraction of REP PARTYLINE voters in a precint, randomly from [0-1]
p_NR_partyline = 0.5np.random.rand(num_precincts) + 0.25 # prob range of fraction of OVERALL PARTYLINE vote in a precint [0.25-0.75]
p_NR_demindep = 0.3np.random.rand(num_precincts) + 0.1 # prob range of fraction of DEM/INEPPENDENT vote for Trump in a precint [0.1-0.4]
p_NR_rep_non_partyline = 0.2*np.random.rand(num_precincts) + 0.75 # prob range of fraction of REP NON-PARTYLINE vote for Trump in a precint [0.75-0.95]
non_r_pop_size_dem = 100
split_votes_dem = np.random.binomial(non_r_pop_size_dem, p_NR_demindep, num_precincts) # simulating binomial weighted for non-partyline dem/indep
split_trump_percentage_demindep = split_votes_dem / non_r_pop_size_dem
non_r_pop_size_rep = 100
split_votes_rep = np.random.binomial(non_r_pop_size_rep, p_NR_rep_non_partyline, num_precincts) # simulating binomial weighted for non-partyline rep
split_trump_percentage_rep = split_votes_rep / non_r_pop_size_rep
rep_non_partyline_percentages = r_partyline_percentages # assumes Republican voter breakout is the same whether party-line voting or non-partyline
demindep_percentages = (1-rep_non_partyline_percentages) # dem/indepent non-partyline percentage is rest of non-partyline voter population
trump_partyline_percentages = p_NR_partyliner_partyline_percentages # partyline voter tally for trump
trump_nonpartyline_percentages = (1-p_NR_partyline)(split_trump_percentage_reprep_non_partyline_percentages + split_trump_percentage_demindepdemindep_percentages) # non-partyline voter tally for trump
total_trump_vote_percentages = trump_partyline_percentages + trump_nonpartyline_percentages # add total Trump vote up by percentages
diffs = total_trump_vote_percentages - r_partyline_percentages
plt.scatter(r_partyline_percentages100, diffs100)
plt.xlim(0,100)
plt.ylim(-50,50)
plt.xlabel('% republican straight-ticket votes')
plt.ylabel('% individual trump votes - % straight ticket votes')
plt.savefig('diff')
You HAVE to incorporate Dem voters. Some of Trumps votes came from them! And they are part of the Y-axis, by his own definition, they are part of the overall Trump candidate vote. The subset of potential dem/independent voters that voted for Trump come from the non-party-line voters. Here is an updated code, cleaned up the subset definitions. There is a shallow curve to the analysis, but nowhere near what you are showing, and with reasonable numbers fairly shallow....
import numpy as np
import matplotlib.pyplot as plt
p_NR_partyline = 0.5
p_NR_rep_non_partyline = 0.8
p_NR_demindep = 0.3
num_precincts = 1000 # let's deal with 1000 precincts.
r_partyline_percentages = np.random.rand(num_precincts) # modeling the fraction of R PARTYLINE voters in a precint, randomly from [0-1]
non_r_pop_size_dem = 100
split_votes_dem = np.random.binomial(non_r_pop_size_dem, p_NR_demindep, num_precincts) # simulating
split_trump_percentage_demindep = split_votes_dem / non_r_pop_size_dem
non_r_pop_size_rep = 100
split_votes_rep = np.random.binomial(non_r_pop_size_rep, p_NR_rep_non_partyline, num_precincts) # simulating
split_trump_percentage_rep = split_votes_rep / non_r_pop_size_rep
rep_non_partyline_percentages = r_partyline_percentages
demindep_percentages = (1-rep_non_partyline_percentages)
trump_partyline_percentages = p_NR_partyliner_partyline_percentages
trump_nonpartyline_percentages = (1-p_NR_partyline)(split_trump_percentage_reprep_non_partyline_percentages + split_trump_percentage_demindepdemindep_percentages)
total_trump_vote_percentages = trump_partyline_percentages + trump_nonpartyline_percentages
diffs = total_trump_vote_percentages - r_partyline_percentages
plt.scatter(r_partyline_percentages100, diffs100)
plt.xlim(0,100)
plt.ylim(-50,50)
plt.xlabel('% republican straight-ticket votes')
plt.ylabel('% individual trump votes - % straight ticket votes')
plt.savefig('diff')