Monty Hall Problem

On a game show, you are shown three closed doors labeled \(A\), \(B\), and \(C\), behind one of which is a prize. After you select one of the doors, the host opens one of the remaining doors which does not contain the prize. At this point, you can either open your original door or switch your original choice and open the last door. The million dollar question is whether it is better for you to stay with your original choice or switch.

We will investigate this problem, known as the Monty Hall problem, first through simulation and then through probability theory. Throughout, we will assume that the prize is placed randomly, chosen uniformly from the three doors.

Simulation

For our simulation, we imagine that the game is played 10,000 times. Keeping track of whether each strategy wins or loses in each game, we can find the proportion of wins for each strategy.

For each simulated game, the prize door and original guess door are stored in vectors, using the sample function with replacement.

n <- 10000
labels <- c("A", "B", "C")

prize <- sample(labels, n, replace = TRUE)

guess <- sample(labels, n, replace = TRUE)

Checking the strategy of staying with your original door is relatively straightforward. We check if corresponding entries in the two vectors are equal, then sum the resulting logical vector. Dividing by 10,000 gives the proportion of wins.

noswitch.prob <- sum(guess == prize) / n

In this simulation, we find that not switching results in winning 0.3287 of the games.

For the strategy of switching doors, we make use of a function that implements this strategy.

swap <- function (guess, prize) {
        w <- 1:length(guess)
        for (i in 1:length(guess)) {
                if (guess[i] != prize[i]) {
                       w[i] <- prize[i]
                } else {
                        diff <- setdiff(c("A", "B", "C"), guess[i])
                        w[i] <- sample(diff, 1)
                }
        }
        return(w)
}

We out this strategy using the swap function on the guess and prize vectors simulated above.

guess.switch <- swap(guess, prize)

switch.prob <- sum(guess.switch == prize) / n

In this simulation, the strategy of switching doors results in winning 0.6713 of the games. In these 10,000 runs of the game, we see that switching will win you about \(\frac{2}{3}\) of the games you play, while staying with your original guess will have you win about \(\frac{1}{3}\) of the games.

To verify that these simulated win proportions are not too dependent on the number of simulated games, we will rerun the simulation for all values between 1 game and 3,000 games. With the goal of plotting the win proportions later, we construct a data frame with columns corresponding to the number of games and each strategy.

sims.df <- data.frame(n = 1:3000, 
                      no_switch = rep(0, times = 3000), 
                      switch = rep(0, times = 3000))

A new function, run.sim will loop over the rows of the data frame, simulating a corresponding number of games and computing the win proportions for each strategy.

run.sim <- function(y, labs) {
        for (index in 1:nrow(y)) {
                m <- y[index,1]

                prize <- sample(labs, m, replace = TRUE)

                guess <- sample(labs, m, replace = TRUE)

                y[index,2] <- sum(guess == prize) / m

                guess.switch <- swap(guess, prize)
                y[index,3] <- sum(guess.switch == prize) / m
        }
        return(y)
}

We then call the run.sim function on the data frame to obtain the simulation results.

sims.df <- run.sim(sims.df, labels)

Summarizing the results, we see that over all numbers of simulation games, the strategy of keeping your original door wins with the following summary statistics.

pander(summary(sims.df$no_switch))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0 0.3242 0.3333 0.3329 0.3418 0.8333

Likewise, the summary statistics for the strategy of switching are

pander(summary(sims.df$switch))
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.1667 0.6582 0.6667 0.6671 0.6758 1

Note that the median values across all numbers of simulated games are in line with our findings from a single run of 10,000 simulated games. To visualize these win proportions plotted against the number of games, we first convert the data frame to long format, then create the plot using the ggplot2 package.

sims.df.long <- gather(sims.df, "strategy", "probability", -n)

ggplot(sims.df.long, aes(x = n, y = probability, color = strategy)) +
        geom_line() + 
        xlab("Number of Games") +
        ylab("Probability of Winning") +
        ggtitle("Monty Hall Simulations") +
        geom_hline(yintercept = 1/3, alpha = 0.5) +
        geom_hline(yintercept = 2/3, alpha = 0.5)

It is reasonable to hypothesize, based on these simulated results, that the true probability of winning when you switch is \(\frac{2}{3}\), while the true probability of winning when you do not switch is \(\frac{1}{3}\). In the next section, we will prove that this claim is indeed true.

Probability Calculations

To prove the claim derived from the simulated game outcomes, we will use the Law of Total Probability. First, we define the following events

Here, we assume that the player chooses one of the three doors with equal probabilities. Then, the Law of Total Probability states \[P(S) = P(S \vert R)P(R) + P(S \vert \overline{R})P(\overline{R}).\] If the prize is behind your original choice of door, then switching will always make you lose. Thus, \(P(S \vert R) = 0\). On the other hand, if you do not originally choose the door with the prize, then the host must open the other door that does not contain the prize. In this case, switching will cause you to choose the door with the prize, and so \(P(S \vert \overline{R})=1\). Therefore, \[P(S)=0\cdot\frac{1}{3}+1\cdot\frac{2}{3}=\frac{2}{3}.\]

Using similar reasoning, \[P(T) = P(T \vert R)P(R) + P(T \vert \overline{R})P(\overline{R}).\] However, we now have \(P(T \vert R) = 1\) and \(P(T \vert \overline{R})=0\). In this case, we see \[P(T)=1\cdot\frac{1}{3}+0\cdot\frac{2}{3}=\frac{1}{3}.\]