Since directly modeling the conditional distribution wouldn't be trivial, an easier way to do it is by using rejection sampling: iterate over a set of randomly generated family configurations, and reject those that do not match the given fact, i.e. those not containing at least a son born on a Tuesday. From the configurations that passed the test, the proportion of those having the other child also a son (born on whatever day), should yield the answer (which of course is not 1/2, as intuition first strongly suggests):
from __future__ import division from random import * n = 0 n_times_other_child_is_son = 0 while n < 100000: child1 = choice('MF') + str(randint(0, 6)) child2 = choice('MF') + str(randint(0, 6)) children = child1 + child2 if 'M2' not in children: continue if children[0::2] == 'MM': n_times_other_child_is_son += 1 n += 1 print n_times_other_child_is_son / n # should be close to 13/27
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.