Make a Coin-Flip Simulation

Top  Previous  Next

How To... > Create Simulations > Simulation Examples > Make a Coin-Flip Simulation

_img461

The section Have Fathom Randomly Generate Data showed how to flip a coin using a function for choosing at random. Here we’ll flip coins by sampling.

Suppose we are interested in the question “On the average, how many times will we have to flip a coin before we get three heads in a row?”

1.Make a collection with one attribute, Face, and two cases, “H” and “T.”
2.Name this collection Coin. It represents the coin and its two faces.

_img146

3.With the Coin collection selected, choose Collection | Sample Cases.
4.Show the inspector for the sample collection, and go to the Sample panel.
5.Configure the Sample panel as shown. (Double-click the formula area to create an Until formula.)

The Until condition tells Fathom to keep sampling until the three most recent values for the attribute Face are all “H.”

6.Go to the Measures panel.
7.Create a new measure named NumberOfFlips.
8.Double-click the Formula cell for NumberOfFlips, and give it the formula count().

 

 

_img462

 

_img463

 

The formula count(), when you don’t specify count of what, gives the number of cases in the collection, in this case, the number of flips it took to get three heads in a row.

9.With the sample collection selected, choose Collection | Collect Measures.

You should see a new collection named Measures from Sample of Coin. Fathom collects five measures immediately.

_img464

10. Double-click the measures collection to show its inspector.

11. If necessary, go to the Collect Measures panel.

12. Change the 5 to 95.

The panel should look similar to the one shown.

13. Click Collect More Measures.

You can graph this data as you normally would.

The plotted mean is the average number of flips, or “wait time,” it took to get three heads in a row.