Heads and Tails
November 30th, 2006Interesting talk on statistics (no, really) from TED:
Peter Donnelly gives some evidence that people are bad at estimating probabilities. One example he gives is the following:
Given a fair coin, how many times do you need to flip the coin to produce the pattern
HTH? How many times to produceHTT?
Seems like they should be equal, right?
They’re not.
from random import choice
"""
I watched this guy's talk:
http://tedblog.typepad.com/tedblog/statistics/index.html
And didn't believe him.
Now I believe him.
"""
def avg(seq): return float(sum(seq)) / len(seq)
def game(pattern):
"""count number of flips required to produce pattern"""
s = ''
i = 0
while not s.endswith(pattern):
i += 1
s += choice(['h', 't'])
return i
def tournament(pattern, numgames):
"""average many games"""
return pattern, avg([game(pattern) for i in range(numgames)])
for pattern in ['hth', 'htt']: print tournament(pattern, 100000)
Here’s the output:
$ python coins.py
('hth', 10.009219999999999)
('htt', 7.99892)
The explanation in the video is pretty good, but it still makes my eyes cross because for some reason I want ‘htt’ to be less common than ‘hth’, which is exactly wrong.