This article aims to be a simple explanation of the Monty Hall problem. The Monty Hall problem is a famous thought experiment that when understood deepens our understanding of probability.

The Monty Hall Problem

Here is how it works. You are playing the t.v. show game Let’s Make a Deal. Monty Hall is the host of the show. Let’s Make a Deal is a game in which there are 3 doors, behind one of which is a car and behind each of the two remaining doors is a goat. Your goal is to choose the door with the car. You choose a door. It is not revealed whether it has a car or a goat. Then Monty Hall opens one of the remaining two doors that has a goat (note: at least one of the remaining two remaining doors always has a goat). Now one door is open with a goat, and two remain closed, one of which has the car. Monty Hall offers you a deal. His offer to you: do you want to change your choice to the remaining closed door?

Question:

Should you keep your first pick, or will you be better off changing your choice to the remaining closed door?

Answer:

You are better off by changing your first choice and taking Monty Hall’s offer. Your probability of winning changes from 1/3 to 2/3.

It is widely discussed that this answer is counter-intuitive. How can that be?  I believe it helps to consider a slight variation of the question.

Variation of Question:

If you played the game 1,000 times with Monty Hall, would you be better off taking his offer and changing your choice to the remaining closed door each time?

Let’s start with a simple simulation of playing the game just 9 times. The table below shows 9 games in which each game you choose door 1 (column 2).  We assume that the winning door with the car is randomly selected by the game show host and it is appears behind each door 3 times, that is 1/3 of the time (see column 3).

From the table below we can see that if you kept your first choice (door 1) in each game and did not accept Monty Hall’s offer, the winning door 1 would occur 3 times, or 1/3 of the time (compare the matches between column 2 and column 3). The table shows the winning door (column 3) and the  door with a the goat that is opened by Monty Hall (column 4). This means that the remaining door is closed (column 5). This closed door in column 5 represents Monty Hall’s offer to you to change your selection to this door. From the table below we see that if you changed your selection to accept Monty Hall’s offer each time, you will win 6 of 9 times, or 2/3 of the time (compare the matches between column 2 and column 5).

GameYour door choiceThe door with the carThe door with the goat opened by Monty HallMonty Hall’s offer to change to this doorIf you don’t changeIf you change
1112 or 32 or 3WinLose
2112 or 32 or 3WinLose
3112 or 32 or 3WinLose
41232LoseWin
51232LoseWin
61232LoseWin
71323LoseWin
81323LoseWin
91323LoseWin
       
     Win 1/3 of the timeWin 2/3 of the time

Assumptions

  • your first choice is always the same door
  • the door with the car is randomly seleced and tus the car appears behind each of the doors 1/2 of the time:

Simulating playing the game 1000 times

In the first simulation above, we assumed your first choice was always the same. Let’s change this simulation in two ways:

  1. You randomly chose your first door (ie you do not always chose the same door)
  2. You play the game 1,000 times

Below is some R code that simulates the Monty Hall problem for this scenario. You can copy the code into your favorite R IDE or run it inData Camp’s online R console – DataCamp Light.

Let’s start with playing the game 10 times (set numberofgames <- 10) After running the script that simulates playing the game 10 times the last line prints:

"If you play 10 times and change your door choice each time, you will win 60 % of the time"
"If you play 10 times and keep your first choice each time, you will win 40 % of the time"

Ok 60% and 40% are not precisely 66% and 33%.   After running the script 3 times, I get:

  • 80% and 20%
  • 60% and 40%
  • 70% and 30%

We can see that due to a small sample (10), we don’t get the same answer every time. This is similar to the situation that if we flipped a coin 4 times, which has a 50% chance of heads and a 50% chance of tails, it may not result in exactly 2 heads and 2 tails. Let’s increase the number of times playing the game from 10 to 1000. After running the script multiple times (ie playing the game 1000 times over and over), the program shows 66% and 33% most of the time. By increasing it to 10,000 games, it is 66% and 33% every time.

Conclusion: It is better to change your first choice.

If you played 1000 times, the evidence is clear that you would be better off taking Monty Hall’s offer to change your door selection each time.

Monty Hall Simulation – R code

numberofwins <- 0

numberofgames <- 1000

for (j in 1:numberofgames)
{
  alldoors <- c(1, 2, 3)
  doorwithcar <- sample(1:3, 1)
  myfirstpick <- sample(1:3, 1)
  reveal <- alldoors[which(alldoors != doorwithcar & alldoors != myfirstpick)]
  revealed <- sample(c(reveal, reveal), 1)
  cbind(doorwithcar, myfirstpick, revealed)
  mysecondpick <- alldoors[which(alldoors != myfirstpick & alldoors != revealed)]
  cbind(doorwithcar, myfirstpick, revealed, mysecondpick)
  if (mysecondpick == doorwithcar)
  {
    numberofwins <- numberofwins + 1}
}

winrate_change <- round(sum(numberofwins / (numberofgames)*100), digits = 5)

winrate_dontchange <- round(sum(100 - winrate_change), digits = 5)

print(c(paste("If you play", numberofgames, "times and change your door choice each time, you will win", winrate_change,"% of the time")))

print(c(paste("If you play", numberofgames, "times and keep your first choice each time, you will win", winrate_dontchange,"% of the time")))