2.2 A simpler problem

Download notebook Interact

A simpler problem

Imagine a family with four children.

What is the probability that the family will have exactly three girls?

There are various ways to answer this question. One way, is to use simulation.

Simulation makes a model of the problem. We use the model to generate simulated data. If the model is a good one, the simulated data should look like the real data.

First we need to simulate a family of four children.

Then we need to count the number of girls.

We do this many many times, and see how often we get a count of 3.

For example, we can run the following cell 4 times, to get 4 random numbers. We can chose to consider any random number less than or equal to 0.5 to be a girl. If we count how many random numbers (of 4) are less then or equal to 0.5, we

np.random.uniform()
0.8037022294800268

As we will soon see, we are using a call expression here. np.random.uniform() calls the function, and returns a random number, between 0 and 1.

It’s inconvenient to have to run this cell many times. We really need some machinery to make the computer do that for us. We need expressions, names, call expressions, comparisons and arrays. We will deal with those next.