The Monty Hall Problem

In the 1970s, there was a game show called Let’s Make a Deal. Monty Hall was the hos, this is where the name of the problem comes from. At some point in the game, contestants were asked to pick one of three doors. Behind one door, there was a prize. The other two had a goat behind them. And this basically meant that you lost.

This is a problem of discrete probability.

If the contestant did not pick the prize (a car) door on his or her first try, Monty Hall would open one of the two remaining doors and show the contestant that there was no prize behind that door. So you’re left with two doors, the one you picked and one door that you do not know what’s behind it. So then Monty Hall would ask, do you want to switch doors?

Many people incorrectly think both chances are 1 in 2, since there’s only two doors left and there’s a prize behind one of them. That this is, in fact, wrong, that you have a higher chance if you switch.
Here, we’re going to use a Monte Carlo simulation to show that this is the case.

This code shows the probability using to not switch strategy (not change the door when the goat appears).

b <- 10000

stick <- replicate(b, {
    doors <- as.character(1:3)
    prize <- sample(c("car", "goat", "goat"))
    prize_door <- doors[prize == "car"]
    my_pick <- sample(doors, 1) # random sample of pick
    show <- sample(doors[!doors %in% c(my_pick, prize_door)], 1) # show not the door with the prize and neather the door that we pick
    stick <- my_pick
    stick == prize_door
})
mean(stick)
[1] 0.3355

This code shows the probability using the switch strategy (change the door when the goat appears).

b <- 10000

switch <- replicate(b, {
    doors <- as.character(1:3)
    prize <- sample(c("car", "goat", "goat"))
    prize_door <- doors[prize == "car"]
    my_pick <- sample(doors, 1) # random sample of pick
    show <- sample(doors[!doors %in% c(my_pick, prize_door)], 1) # show not the door with the prize and neather the door that we pick
    stick <- my_pick
    switch <- doors[!doors %in% c(my_pick, show)]
    switch == prize_door
})
mean(switch)
[1] 0.6734

So if we run the simulation, we actually confirm that. We get that the proportion of times we win is 0.6717, which is about 2/3. The Monte Carlo estimate confirms the 2 out of 3 calculation.