<jupyter_start><jupyter_text>Exercises on the three-girl simulation problemThese exercises follow on from the [three girls section](../03/three_girls).Run this cell first:<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>10000 familiesNow you have seen how to simulate 10 families, with a 2D array.Copy and paste from the code above, into the cell below, andchange what you need to change, to simulate 10000 families of4 children.  It will have these steps:* make a 2D array of random numbers between 0 and 1, with 10000  rows and 4 columns.* make a new array of the same shape, with `True` where the random  number corresponds to "girl" and `False` when the number corresponds to "boy"* count the number of girls (`True` values) in each row.* count the number of times there were exactly 3 girls.* divide by the number of rows to give an estimate for the  proportion of 4-child families with exactly 3 girls.<jupyter_code># Simulate 10000 families of 4 children.
# Show proportion with 3 girls.
# Your code below<jupyter_output><empty_output><jupyter_text>No girls in a family of 4.Estimate the chances that a 4-child family will have no girls.  You can copy the code from the cell above, and modify it, or you may be able to use variables from the code above, to get the answer, without repeating the simulation.<jupyter_code># Show proportion with 0 girls.
# Your code below<jupyter_output><empty_output><jupyter_text>For extra points - the answer above is easier to work out withprobability than the chance of three girls.  What's the exact answer, from probability?  3 girls in a family of 5.Simulate the chances that a family with 5 children will haveexactly 3 girls.<jupyter_code># Simulate 10000 families of 5 children.
# Show proportion with 3 girls.
# Your code below<jupyter_output><empty_output><jupyter_text>3 or fewer girls in a family of 5.Simulate the chances that a family with 5 children will have 3 orfewer girls.Hint: `<=` tests whether the thing on the left is *less than or equal to* the thing on the right.<jupyter_code>3 <= 4
3 <= 3
3 <= 2
my_array = np.array([1, 2, 3, 4])
my_array <= 2<jupyter_output><empty_output><jupyter_text>Hints done, now:<jupyter_code># Proportion of families of 5 children with 3 or fewer girls.
# Your code below
# Simulate 10000 families of 5 children.
# Show proportion with 3 girls.
# Your code below<jupyter_output><empty_output><jupyter_text>More realistic simulationNow we are back to the situation of exactly 3 girls in a family of 4.In fact, when you have a child, the probability of having a girlis slightly less than 0.5.In fact, the [proportion of boys born in theUK](https://www.gov.uk/government/statistics/gender-ratios-at-birth-in-great-britain-2010-to-2014)is 0.513.  Hence the proportion of girls is 1-0.513 = 0.487.With that probability of having a girl, what are the chances of having exactly three girls in a family of four?<jupyter_code># Simulate 10000 familes of 4 children.
chance_of_girl = 0.487
# Estimate chance of having exactly 3 girls.
# Your code here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06731391585760518, 'fraction_numerical': 0.035275080906148865, 'mean_word_length': 4.876425855513308, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 29, 'https://': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '220200', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 980, 'n_tokens_neox': 875, 'n_words': 437, 'path': 'notebooks/exercises/three_girl_simulations.ipynb', 'repo_name': 'matthew-brett/dsfe', 'size': '3090'}