e-Mathematics > Probability and Statistics
for 3470-001 student.

Monty Hall Problem

Suppose you're on a game show, and you're given a choice of three doors: Behind one door is a prize; behind the others, goats. You pick a door, say No. 1, and the show's host, Monty Hall, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" How can you improve your chance of winning the game with your response?

To get the idea of the game show, visit here. To find out an interesting history of this problem, go to the youtube video by Zachary Crockett at Priceonomics.

There are three possible strategies:

  1. Stick with the one you have chosen. Thus, say “no” to Monty.
  2. Switch it. Thus, say “yes” to Monty.
  3. Flip a coin to decide it. Thus, say “yes” with probability 1/2 (and “no” with probability 1/2).

We can simulate the show's outcome at least 1000 times for each strategy, and determine which strategy you should adopt for the best result. Here is a code to simulate the Monty Hall problem:

First we write a function monty.experiment() to determine the outcome according three different strategies. The variable "doors" is an array data of either [1,0,0], [0,1,0], or [0,0,1], where "1" indicates the prize. It returns three values, either 0 (= goat) or 1 (= prize), for your original pick, the pick switched, a pick by coin-tossing.

monty.experiment = function(doors){
  your.pick = 1;
  if(doors[2] == 0){
    monty.suggest = 3;
  }else{
    monty.suggest = 2;
  }

  if(sample(c("H","T"),1) == "H"){
    coin.pick = your.pick;
  }else{
    coin.pick = monty.suggest;
  }

  doors[c(your.pick,monty.suggest,coin.pick)]
}

Then call it in the simulation repeatedly for n=1000 times.

n = 1000;
prob = rep(1/3,3);
success = data.frame(your.pick=NA,monty.suggest=NA,coin.pick=NA);
success.rate = data.frame(your.pick=NA,monty.suggest=NA,coin.pick=NA);
for(i in 1:n){
  doors = rmultinom(1,1,prob);
  success[i,] = monty.experiment(doors);
  success.rate[i,] = colMeans(success);
}

At the end you should visualize the success rate for each strategy in a different color.

plot(c(1,n), c(0,1), type='n', xlab='Trials', ylab='Success rate')
legend(x=0.7*n, y=1.0, lty=1, col=c(2,3,4), legend=names(success.rate));
lines(1:n, success.rate$your.pick, col=2)
lines(1:n, success.rate$monty.suggest, col=3)
lines(1:n, success.rate$coin.pick, col=4)
print(success.rate[n,])

Sample R code. You can download montyhall.R, and run it.

Programming Note.

success = data.frame(V1=NA,V2=NA,V3=NA)
is used to create a data frame (an array) with variable names V1,V2, and V3. You can find all the trial results by
success
In the plot, the change of success rates is drawn by using the command lines for each of the three strategies. Then
legend(..., legend=names(success))
puts a little box in the graphic display for legends from the variable names.


© TTU Mathematics