Created
July 13, 2015 01:15
-
-
Save hobson/7ec4091bec74f6157824 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Attempt to confirm results in paper by Miller and Sanjurjo | |
["Confused by the Gambler's and Hot Hand Falacy?..."](http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2627354) | |
Calculate the probability of a streak of length 2 in a coin flip | |
for a small sequence of attempts ("finite sequence of iid Bernoulli trials"). | |
The fencepost counting issue means you have to ignore one of the flips. | |
Perhaps this is what causes Miller and Sanjurjo to get 0.4 instead of 0.5. | |
"the conditional relative frequency... is 0.4 not 0.5" | |
""" | |
from random import randint | |
h, t = 0, 0 | |
# L is the streak length but is unused (2 is hard coded into the logic) | |
L, M, N = 2, 1000, 4 | |
for i in range(M): | |
flip0 = randint(0, 1) | |
for j in range(N-1): | |
flip1 = randint(0, 1) | |
if flip0: | |
h += flip1 | |
t += not flip1 | |
flip0 = flip1 | |
print float(h) / float(h + t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment