So I checking the state of the Democratic Nomination polls today and I saw this head scratcher:
- Quinnipiac 10/17 - 10/21 21 28 15 10 5 ... Warren +7
- CNN 10/17 - 10/20 34 19 16 6 6 ... Biden +15
Both polls were taken over the same time period. Both polls have a large sample size of 1587 and 1003 respondents respectively. Theoretically the margin of error for each poll is listed at +/- 3.7% to 4.6% and yet there is a 22% difference! How is this possible?
I know that the margin of error is only 95% accurate so I wanted to simulate this properly. I wrote a quick python script to do a poll over a simulated infinite population that voted according to the RCP averages. After 1 million trials, the biggest difference between polls I ever got was 14% with poll A showing Biden +14% and poll B showing a statistical tie.
Is it possible the polling institutions are being dishonest or fudging the numbers somehow?
import random
def get_poll(sample_size):
'''Returns Biden's polling advantage vs Warren over the sample size'''
warren = 0
biden = 0
for person in range(0, sample_size):
r = random.random()
if r < .218:
warren += 1
elif .218 < r < .490:
biden += 1
return biden/sample_size - warren/sample_size
big = 0
for trial in range(int(1e6)):
random.seed()
a = get_poll(1587)
b = get_poll(1003)
spread = abs(a-b)
if spread > big:
big = spread
print("\nPoll A: Biden advantage:", int(a * 100))
print("Poll B: Biden advantage:", int(b * 100))
print("Spread:", int(spread * 100))
if not trial % 10000 and trial:
print("Test number:", str(int(trial/1000))+'k')
Output:
Poll A: Biden advantage: 0
Poll B: Biden advantage: 14
Spread: 14