Day 1¶
Morning - thinking about sampling¶
- 10.00 - 10.15 - Are there too few Brexiteers in the survey? How would we decide?
- 10.15 - 10.45 - another problem of proportions. If a family has 4 children, what is the probability that the family has 3 girls? A simulation.
- 10 minute break
- 10.55 - 11.15 - what is the algorithm?
- 11.15 - 12.00 - the machinery we will need: Print, If and For.
Afternoon - probability and simulation¶
- back for
for
loops in Print, If and For. - lists in Lists.
- solving with simulation; Three girls;
Notebooks from the afternoon:
An explanation of and
and or
: and, or in expressions.
Homework¶
Download the notebook from the link at top of Three girls - it’s a slightly modified solution to the three girls problem we were working on today. Make a copy, that you are going to modify.
Modify the notebook to give the probability of 2 girls, instead of 3 girls. What is that?
Make another copy of the original Notebook for the next problem. The actual probability of having a male child is not 0.5 but 0.513. [1]. To do a better simulation, we need to modify the Notebook to give a 0.513 probability of
"B"
and a 0.487 probability of"G"
. You can’t easily userandom.choice
for this, but you could an expression like this to decide if it is a girl:random.uniform(0, 1) <= 0.487
random.uniform(0, 1)
returns a random number between 0 and 1 - so the number it returns will be<= 0.487
about 48.7% of the time.Modify your new copy of the Notebook to use something like this to give the probability of a girl. You should find that your estimate of the proportion of 3-girl families drops slightly, because girls are slightly less common than boys.
[1] | Official UK government statistics give the birth ratio as 105.3. This the number of boys born for every 100 girls. |