Sunday, April 19, 2015

The Unintuitive Nature of Randomness

Humans suck at randomness. I mean we really, really don't have a good intuition for what randomness looks like. What follows is an example that illustrates this total intuition blind spot.

Whenever I teach probability in a math class, I like to start with this experiment (partly because I want to show that intuitive BS arguments are likely to be totally false in this class, and partly because this experiment is neat and memorable and I'm pretty into what my students think of me). I split the class into, say, twenty groups. Ten of the groups are told to flip an actual coin and record the results, while the other ten groups are told to make up a plausible-seeming coin flip sequence and write it down. I leave the room for a few minutes, and when I come back I figure out which results are real and which are made up just by looking at the sequences. In practice, I end up being correct about 93% of the sequences, which is a number I just made up (no but it's accurate). Sorcery! I only look at each of the sequences for a few seconds, and I'm sadly not a mental arithmetic savant or anything. So how does it work?

The answer is that I'm using the aforementioned central tenet of human probability-intuition: we don't have it. My one check is this. If there is a run of length 5 or 6 or longer (by a run, I mean that the same result happened in consecutive flips, so for instance the sequence---where here a white coin represents a tail and a black coin represents a head---


has a run of one tail, followed by a run of two heads, etc.), then I guess that this sequence was generated by actual coin flips. If the longest run is of length 4 or less, then I guess that this sequence is made up. Here's why this works most of the time (we'll talk about where these numbers come from later):

  1. The actual probability of having a run of length at least 5 in a sequence of 100 coin flips is around 97%. The probability of having a run of length at least 6 is a bit over 80%.
  2. Most people not only don't know this first fact but assume that long runs are actually pretty unlikely, so most of the time the made up sequences don't have any runs longer than length 3. The probability that a sequence of 100 coin flips has longest run length 3 or less is around 0.03%.
Let's look at an example. Here are a pair of sequences of coin flips. Each one represents a coin that was flipped 50 times in a row (because 100 didn't fit nicely on the page), with the results recorded each time. Does one look more "random" to you than the other?


or



Both look like something that's reasonable to expect as an outcome, but one of these was generated by an actual series of random flips (simulated by a random number generator, anyway) and the other one is made up by hand to "look" random. From the facts outlined above, a good guess is that the first one is the made up one. The first sequence has longest run length 3, which has about a 2% probability of happening, and so is pretty dang unlikely. The second sequence has longest run length 5, and the probability of a sequence of 50 coin flips having a run of length 5 or longer is about 82%. Not definitive, but likely.

The first thing that goes wrong at this point in the class is that someone takes this to mean that sequence 1 is less likely to come up than sequence 2. In fact, both sequences are equally likely. What? But you just said---NOPE. Think about it this way. Each time you flip a coin you have a 1/2 chance of getting heads, and 1/2 chance of getting tails, and these events are independent of each other (there are mathy definitions for what we actually mean by event and independence but our colloquial understanding of these terms will do here). So the probability of getting


is (1/2)(1/2)=1/4. The probability of getting

is (1/2)(1/2)=1/4. OK, you get the idea.

But this seems kind of weird. Suppose that a friend invited you to play a game in which you must pay him $1 every time a coin comes up heads, and you'll get paid $1 every time a coin comes up tails (which certainly seems like, and is, a fair game). If the first ten coin flips are



then this seems legit. Heads and tails have both come up five times, so the game is tied up, and that seems like a reasonable outcome for a fair game. Now suppose that the first ten coin flips are


You'd probably be suspicious as heck because you have yet to make any money and your friend has already won $10 of yours. (If you're not convinced yet: imagine you get another ten heads in a row. Your friend is obviously cheating somehow. Another ten heads, for a total of thirty in a row, and you've cut all ties with this former friend of yours and don't regret it one bit because he's a filthy lying scumbag.) Well, the probability of getting 10 heads in a row is (1/2)10 ≈ 0.00097, so you're right about the fact that he's probably a scumbag. The reason that the outcome that gave five heads and five tails seems less dubious is that there are actually 252 different ways to flip five heads and five tails (because 252 = "10 choose 5," but we won't go into that). There is only one outcome that gives exactly ten heads. So while any particular outcome that consisted of five heads and five tails is only going to occur with minuscule probability (1/2)10, one of these 252 outcomes will occur with probability 252(1/2)10 ≈ .25, or 252 times more often than the all-heads scenario.

So that's a quick example that helps illustrate the fact that human beings just aren't good at "sensing" randomness, and all the education in the world doesn't change our crappy intuition, even if we should know better. In the immortal words of Ygritte and Seth Meyers, when it comes to randomness:



Bonus math stuff

Skip this part if you've had enough.

If you're wondering where the probabilities referenced above come from, here's a first, easier-to-answer question that can improve our misguided intuition. If you repeat the flipping-100-coins experiment many times (like 1,000,000 times), how many runs of length 5 should we get on average? So, we have 100 flips, and a run of 5-in-a-row can start at flip 1, flip 2, flip 3, ... , all the way out to flip 96 (if we started any later than that, we'd run out of coin flips). So there are 96 places for a length 5 run to start. As we discussed above, any particular set of 5 flips is going to be all-heads with probability (1/2)5 and all-tails with probability (1/2)5, for a total probability of 
(1/2)5+(1/2)5=(1/2)4=1/16. 
If we want to figure out the average number of length 5 runs among these 1,000,000 coin-flipping experiments, we can simply add up the average number of length 5 runs among each of the 96 sets of 5 consecutive coin flips. On average, each one of these is a length 5 run 1/16 of the time, so in total we have 96/16 = 6 length 5 runs. Note that the way we're counting them, the sequence 


actually has two length 5 runs, so these aren't necessarily separate runs. But still, if on average there are six in an experiment, intuition says that it should be pretty likely that we find at least one. 

Okay, so that's intuition-building. But we did say that our intuition is not to be trusted, so you really shouldn't be satisfied right now. To get the actual numbers claimed above, we can do some clever but pretty complicated math, or we can simply run a simulation. Here's an example of what a simulation looks like, in a piece of math software called Matlab (there's a free Matlab equivalent called Octave that has most of the same functionality). If you have access to this program, you can run this function as written. If you have some facility with some other programming language, you can write a program like this one. If you have no idea what I'm talking about, just ignore what follows.

function probability = runCounter(run_time,num_flips,n)
% runCounter outputs the proportion of simulations among the run_time
% simulations tested in which there was a run of length n or greater among
% the num_flips flips of a coin.


longest_runs = 0;
run_of_n = zeros(1,run_time);
    
for i=1:run_time
    longest = 1;
    counter = 1;
    flip = 2;

    for j=1:num_flips
        last_flip = flip;
        flip = randi(2)-1;

        if flip == last_flip 
            counter = counter + 1;
            longest = max(longest,counter);
        else
            counter = 1;
        end
    end
    
    if longest >= n     
        run_of_n(i) = 1;
    end
    
    longest_runs = longest_runs + longest;
end

probability = sum(run_of_n)/run_time;

end

No comments:

Post a Comment