# The Bayesian and the Frequentist – III

For another story, I read the following problem on a Google+ site yesterday: You have three cards in your pocket, one with two red sides, one with two blue sides and one with a red and a blue side. You take one out of your pocket, place it on the table, and it shows a blue side. What is the probability that the other side is also blue?

That fits into my Credo that the quickest way to get order into our thinking is to imagine or actually do a simulation. So let us do that first without trying any abstract thoughts about the problem.

The simulation is obviously to draw one of the three cards with equal probability. Then to take one of the sides with equal probability. Then we have to discard the cases where the side is red. This time, we make a small Java program. I try to design one that is easily understandable.

public class MC
{
static final int red=0,blue=1;

public static int random (int n)
{
return (int)(Math.random()*n);
}

public static void main (String a[])
{
int C[][]={{red,red},{blue,blue},{red,blue}};

int n=100000000;
int found=0;
int valid=0;
for (int i=0; i<n; i++)
{
int card=random(3),side=random(2);
int otherside=1-side;
if (C[card][side]==blue)
{
valid++;
if (C[card][otherside]==blue) found++;
}
}
System.out.println("Found : "+(double)found/valid);

}
}


We can do 100 million simulations in about one seconde. The result is 0.66666164. Of course, we can also do it in EMT with its matrix language or with a TinyC program. With the matrix language, I can only get up to 10 million iterations. Extending the stack would help. But then it is still slower.

>C=[1,0,0;1,0,1]
1             0             0
1             0             1
>n=10000000;
>i=intrandom(n,2); j=intrandom(n,3);
>Sel=mget(C,i'|j'); Other=mget(C,(3-i)'|j');
>sum(Sel==1 && Other==1)/sum(Sel==1)
0.666787938524


So the result seems to be 2/3 probability for the other side to be blue. It is not difficult to understand. We always reject the card with two red sides. And we reject the card with one red side half of the time, but we always accept the card with two blue sides. Thus it is twice as likely to have blue on the other side.

The Bayesian trick does indeed help in this case. But it makes things more mysterious. Let us call BB the event that the card with two blue sides is drawn, and B the event that we see a blue side. Then

$$P(\text{BB}|\text{B}) = P(\text{B}|\text{BB}) \cdot \dfrac{P(\text{BB})}{P(\text{B})} = 1 \cdot \dfrac{1/3}{1/2} =\dfrac{2}{3}.$$

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.