0

I made a simulation in MATLAB that showed that if you stay, you win 37.5% of the time and that if you switch, you win 63.5% of the time. This was done ten times over iterations of 500,000 times (so 5 million times each).

I have always been told that the probability of STAYING should be 1/3 and the probability of SWITCHING should be either 2/3 or 1/2 (depending on whom you ask). What is going on here?

If you'd like to see the code or anything, please let me know.

CODE:

clear

%STAY option

max = 500000;   % number of games played
win = 0;        % win counter
n = 0;          % index counter

while n < max
  game = round(rand(1)*2)+1;      % generate prize door
  player = round(rand(1)*2)+1;    % player selects door

  if (player~=game)
    n=n+1;
  else
     win = win+1;
     n=n+1;
  end
end

display("Wins if STAY:")
win

display("Games played on STAY:")
n

display("Percentage won on STAY option:")
win/n*100

%SWITCH option`

max = 500000;   % number of games played
win = 0;        % win counter
n = 0;          % index counter

while n < max
  game = round(rand(1)*2)+1;      % generate prize door
  player = round(rand(1)*2)+1;    % player selects door

  if (player~=game)
    win = win+1;
    n=n+1;
  else
     % win = win+1;
     n=n+1;
  end
end

display("Wins if SWITCH:")
win

display("Games played on SWITCH:")
n
mrf
  • 43,639
Bark Jr.
  • 619
  • If you don't share the code, we can't tell you much. – user217285 Jul 07 '15 at 19:56
  • Seeing the code would be useful. I also wonder, what is variance in your ten answers? – Plutoro Jul 07 '15 at 19:56
  • 3
    Random number generators in MATLAB are pseudorandom, so you might just be seeing that the random numbers are not generated perfectly. – Michael Burr Jul 07 '15 at 19:56
  • Please post the code, I know MATLAB quite well, so I can probably guess what the issue is. First thoughts are statistical variance ($\frac{2}{3} \approx 66.7%$). – FundThmCalculus Jul 07 '15 at 19:58
  • Something is definitely wrong, I ran this experiment by hand once with three cups and a ball and got better approximations than that with less than 100 trials. – Gregory Grant Jul 07 '15 at 20:00
  • Speaking of the Monty Hall problem, I actually find the Bertrand's Box paradox even more counter-intuitive. In that experiment you have three boxes, one has two gold coins, one has two silver coins and the third box has one of each. If you pick a box at random and pull out a coin at random and it is gold, what is the probability that the second coin in that box is also gold? It really feels like 50/50 but it's actually 2/3. – Gregory Grant Jul 07 '15 at 20:02
  • 1
    It could be that your random generation of doors will generate door $2$ with $50%$ and doors $1$ and $2$ with $25%$ each. A better function would be round(3*rand(1)+1/2) or floor(3*rand(1))+1 – robjohn Jul 07 '15 at 21:00
  • I'm confused by your code. You seem to be generating only two doors, not three. – Alex R. Jul 07 '15 at 21:01
  • 2
    In $\mathtt{MATLAB}$, simply use randi([1,3]) to generate a uniformly random integer between (and including) 1 and 3. – Eff Jul 07 '15 at 21:11

1 Answers1

1

Community wiki answer to expand robjohn's comment into an answer that can be accepted to mark the question answered:

Your expression round(rand(1)*2)+1 generates a number uniformly distributed over $[0,1]$, multiplies it by $2$ to spread it over $[0,2]$, rounds it and shifts it by $1$. Since both numbers are shifted by $1$, we can ignore that. The rounding maps $[0,0.5]$ to $0$, $[0.5,1.5]$ to $1$ and $[1.5,2]$ to $2$. Thus, the probabilities to generate $0$, $1$ and $2$ are $1/4$, $1/2$ and $1/4$, respectively. The probability that two numbers thus produced are equal is indeed $(1/4)^2+(1/2)^2+(1/4)^2=3/8=0.375$.

The comments contain various suggestions how to produce $1$, $2$ and $3$ with equal probability of $1/3$.

joriki
  • 238,052