Exponential Decay Simulation

Posted on May 9, 2012


This comes from a Fathom listserv query by David Petro:

1. Flip 1000 coins

2. Remove the heads and count up the tails

3. Flip the remaining tails again

4. Repeat 2 & 3 until no coins remain

5. Graph the number of tails after each experiment.

This is what I have tried

I Have a collection of two cases (H and T), Sample from this (1000 times the first time and collect measures as to how many Heads there are in the sample and then resample but this time only sample 1000-#Heads times (these would represent the number of tails left and is built into the sample condition ). It is supposed to collect measures until the total number of heads is greater than 1000 but it only does the experiment once.

Do any of you Fathom Big Brains have some insight here?

David has a really interesting approach in his file, but I’m not sure how to make it work. There might be a way—but I don’t see it right now. The problem is that Fathom doesn’t have a way to create or destroy cases programatically except though collecting measures. You really need to make or get rid of coins, and you can’t do that.

So I’ll explain how I would approach the same situation:

You do want the number of coins in each “generation.” So imagine the end result: a column called “nCoins” with 1000 at the top, and fewer in each row until it gets to zero.

To make it easier, let’s have another column called “heads,” for the number of heads. I used 20 cases to be reasonably sure of getting to zero before the end of the collection.

Then the formula for nCoins is

prev(nCoins) – prev(heads)

To avoid the prev( ) default problem in the first row (it defaults to zero), change it to:

prev(nCoins, 1000) – prev(heads)

Then you need a formula for heads. That’s the number of heads you get in nCoins flips:

randomBinomial( nCoins, 0.5 )

This is not as cool as using the actual coins, but it works. What remains is dealing with the end. That can be tricky, but this works: make a new column, hasCoins. Give it this formula:

Then you can write a measure, lastTurn = max(hasCoins) and collect it, for example, to show the distribution of how many turns it takes to deplete the coins.

How many turns does it take to deplete 1000 coins?

This attribute can also be the x-axis for the exponential decay: