<jupyter_start><jupyter_text>*Adapted from [<NAME>](https://www.albertbridgecapital.com/post/heads-i-win-2).* IntroductionI took a bit of a hiatus from this blogging thing due to the on-going prep work for my Tensorflow certification. Came across this pseudo Monty Hall problem, and the results are so delightfully unintuitive that I thought I should do a quick post to celebrate this. Problem set up1. Imagine if you're told that a couple has two children, and one of them is a girl. What is the probability that the other child is also a girl?2. As an extension, what if you're told specifically that the *older* child is a girl? Does this change your answer? DiscussionI think it's ridiculously intuitive to simply say 50%, similar to the [Monty Hall Problem](https://en.wikipedia.org/wiki/Monty_Hall_problem). This answer comes from our intuition that children's genders are essentially a coin flip (clearly not a biologist). Having a son doesn't, *shouldn't* increase your odds of subsequently having either a son or a daughter, right?As it turns out, it really depends on how you frame this problem, which why this is a marvellous lesson on why we can't trust our statistical intuition.Let's address the first problem by drawing out the possible space of solutions. Given that a couple has 2 children, there are 4 possible gender combinations:|   | Child 1 | Child 2 ||---|---|---|| 1 | Boy | Boy || 2 | Boy | Girl || 3 | Girl | Boy || 4 | Girl | Girl |Having been told that one of the two children is a girl, that leaves only possibilities 2, 3, and 4. $\frac{1}{3}$ of these cases will have a girl as the unknown child, and $\frac{2}{3}$ will have a boy. So the answer to our first question is not 50% as we first intuited, but 33%! Let's confirm this via simulation:<jupyter_code>child1 <- sample(c('M','F'), 100000, replace = T)
child2 <- sample(c('M','F'), 100000, replace = T)
families <- data.frame(child1, child2)
families %>%
  filter(child1 == 'F' | child2 == 'F') %>%
  mutate(bothGirls = if_else(child1 == 'F' & child2 == 'F', 1, 0)) %>%
  summarise(mean(bothGirls))<jupyter_output><empty_output><jupyter_text>As expected, conditional on the information that one of the two children is a girl, the remaining child is more likely to be a boy!What if we knew the birth order of the girl? Suppose now we know that (i) at least 1 child is a girl, and (ii) the first child is a girl. By the logic above, we are now restricted only to cases 3 and 4, and we should now see that the probability of the second child being a girl has increased to 50%.<jupyter_code>families %>%
  filter(child1 == 'F') %>%
  mutate(bothGirls = if_else(child2 == 'F', 1, 0)) %>%
  summarise(mean(bothGirls))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0968096809680968, 'fraction_numerical': 0.02016868353502017, 'mean_word_length': 4.522267206477733, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '539130', 'license': 'MIT', 'n_tokens_mistral': 834, 'n_tokens_neox': 752, 'n_words': 400, 'path': '_jupyter/2020-07-26-monty-hall-redux.ipynb', 'repo_name': 'yjtek/yjtek.github.io', 'size': '2733'}