## 1.4 Approximating probabilities - a brief introduction to simulation

Here’s a seemingly simple problem. Flip a fair coin four times and record the results in order. For the recorded sequence, compute *the proportion of the flips which immediately follow a H that result in H*. What value do you expect for this proportion? (If there are no flips which immediately follow a H, i.e. the outcome is either TTTT or TTTH, discard the sequence and try again with four more flips.)

For example, the sequence HHTT means the the first and second flips are heads and the third and fourth flips are tails. For this sequence there are two flips which immediately followed heads, the second and the third, of which one (the second) was heads. So the proportion in question for this sequence is 1/2.

So what value do you expect for this proportion? We think it’s safe to say that most people would answer 1/2. Afterall, it shouldn’t matter if a flip follows heads or not, right? We would expect half of the flips to land on heads regardless of whether the flip follows H, right? We’ll see there are some subtleties lurking behind these questions.

To get an idea of what we would expect for this proportion, we could conduct a simulation: flip a coin 4 times and see what happens. Here are the results of a few repetitions; each repetition consists of an ordered sequence of 4 coin flips for which the proportion in question is measured. (**Flips which immediately follow H are in bold.**)

Repetition | Outcome | Flips that follow H | H that follow H | Proportion of H following H |
---|---|---|---|---|

1 | HHTT |
2 | 1 | 0.5 |

2 | HTTH |
1 | 0 | 0 |

3 | TTTH | 0 | NA | try again |

4 | THHH |
2 | 2 | 1 |

5 | HHTT |
2 | 1 | 0.5 |

6 | HHHT |
3 | 2 | 0.667 |

We can keep repeating the above process to investigate what happens in the long run. Rather than actually flipping coins, we use a computer to run a simulation. The table and plot below summarize the results of 1,000,000 repetitions of the simulation^{7}. While you can’t see the individual “dots” in the plot, each dot would represent a sequence of 4 coin flips (with at least one flip following a H) and the value plotted being plotted is the proportion of H following H for that sequence. The results could be summarized in a table like Table 1.1, albeit with 1,000,000 rows (after discarding rows with no flips immediately following H.)

We asked the question: *what would you expect* for the proportion of the flips which immediately follow a H that result in H? That depends on how we define what’s “expected”. If we are interested in the value that is most likely to occur when we flip a coin four times, then the answer is 0: we see that in the long run a little over 40% of the sets resulted in a proportion of 0, while only about 30% of sets resulted in a value of 1/2. We see that the plot is not centered at 1/2; a higher percentage of repetitions resulted in a proportion below 1/2 than above 1/2. We think that most people would find this surprising.

Another way to interpret “expected” is as “average”. Just as probability can be interpreted as long run relative frequency, there is a concept called *expected value* which can be interpreted as the *long run average value*. After 1,000,000 repetitions, each involving a set of four fair coin flips, we have 1,000,000 simulated values of the proportion of H following H, as recorded in the rightmost column of Table 1.1. We could then average these values: add up the values in the column and divide by 1,000,000. It turns out that average value is 0.405, which is not 1/2. Again, we think most people find this surprising.

A quick note: the term “expected value” is somewhat of a misnomer. We are *not* saying that if we flip a coin four times we would expect the proportion of H following H for that set of flips to be 0.405. In fact, the simulation shows that on any single set of four fair coin flips, the only possible values for the proportion of H following H are 0, 1/2, 2/3, and 1. So in a set of four coin flips it’s not possible to see a proportion of 0.405. Rather, 0.405 is the *average value of the proportion of H following H that we would expect to see in the long run over many sets of four fair coin flips*. We will return to this idea later.

We will return to this example several times throughout the book to investigate these results more closely. For now, just observe that

- The study of probability can involve some subtleties and our intuition isn’t always right.
- Simulation is an effective way of investigating probability problems, and can reveal interesting and suprising patterns.

Section XXX covers how to program the simulation and analyze the results.↩