The Monty Hall problem
Tags: math, statistics, probability, montyhall
Published: 2023-01-25 06:25:38

Suppose you're on a game show, and you're given the choice of three doors: {% katex inline %}a{% endkatex %}, {% katex inline %}b{% endkatex %}, and {% katex inline %}c{% endkatex %}. Behind one door is a car; behind the others, goats. You pick a door, say {% katex inline %}a{% endkatex %}, and the host, who knows what's behind the doors, opens another door, say {% katex inline %}b{% endkatex %}, which has a goat. He then says to you, "Do you want to pick door {% katex inline %}c{% endkatex %}?" Is it to your advantage to switch your choice?

![Monty Hall problem](https://sketchviz.com/@santisbon/b6be69bd1b29b3321e02344721d833ea/a175e9b7c9808640067acb202ec7626e9a26afdb.sketchy.png)


We'll go through three different explanations for the solution. I've found that different explanations will "click" with different people depending on their background and way of thinking. The first two will be mathematically rigorous and the last will be more informal but useful for building an intuition for why the math works out the way that it does.

## Explanation #1 
### Conditional probability

What is the probability that the host would choose that door to open?

* If the car is in box {% katex inline %}a{% endkatex %} then he could open either {% katex inline %}b{% endkatex %} or {% katex inline %}c{% endkatex %} to reveal a goat. The probability is {% katex inline %}1/2{% endkatex %}.
* If the car were in box {% katex inline %}b{% endkatex %} there's no way he would open {% katex inline %}b{% endkatex %}. The probability is {% katex inline %}0{% endkatex %}.
* If the car is in box {% katex inline %}c{% endkatex %} then Monty would *definitely* open box {% katex inline %}b{% endkatex %} to reveal a goat. The probability is {% katex inline %}1{% endkatex %}. 

**So what's the probability that the prize is in box {% katex inline %}c{% endkatex %} given that he opened {% katex inline %}b{% endkatex %}?**

Luckily, we have a way of calculating a probability based on prior knowledge. That is, the probability of an event happening given the fact that another event has already happened:

> :information_source: **Bayes' Theorem**
> {% katex %}P(A|B)={P(B|A)P(A) \over P(B)}{% endkatex %}

But wait, where did that come from?
> :bulb: It can be derived from the conditional probability that tells us in how many cases do both events {% katex inline %}A{% endkatex %} and {% katex inline %}B{% endkatex %} happen out of the cases where {% katex inline %}B{% endkatex %} happens:
>
> {% katex inline %}P(A|B)={P(A \cap B) \over P(B)}{% endkatex %}
>
> Similarly, {% katex inline %}P(B|A)={P(A \cap B) \over P(A)}{% endkatex %}
>
> which means
>
> {% katex inline %}P(A \cap B)=P(B|A)P(A){% endkatex %}
>
> and substituting in the expression for conditional probability yields Bayes' Theorem:
> {% katex %}P(A|B)={P(B|A)P(A) \over P(B)}{% endkatex %}

So the probability that the car is in box {% katex inline %}c{% endkatex %} given that he opened {% katex inline %}b{% endkatex %} is:
{% katex %}P(Car_c|Open_b)={P(Open_b|Car_c)P(Car_c) \over P(Open_b)}{% endkatex %}

There are three possibilities for the denominator {% katex inline %}P(Open_b){% endkatex %}:
* {% katex inline %}Car_a (Open_b|Car_a)=\frac 1 3 \cdot \frac 1 2=\frac 1 6{% endkatex %}
* {% katex inline %}Car_b(Open_b|Car_b)=\frac 1 3 \cdot 0=0{% endkatex %}
* {% katex inline %}Car_c(Open_b|Car_c)=\frac 1 3 \cdot 1=\frac 1 3{% endkatex %}

so we'll add them up and plug them into our formula:

{% katex %}P(Car_c|Open_b)={1 \cdot \frac 1 3 \over \frac 1 6+\frac 1 3}={\frac 1 3 \over \frac 1 2}={\frac 2 3}{% endkatex %}

giving us a {% katex inline %}2/3{% endkatex %} probability that the car is in the other box and therefore **you should switch**.

## Explanation #2
### Odds

There is another way to see Bayes' Theorem: As a way to understand two competing hypotheses {% katex inline %}H_1{% endkatex %} and {% katex inline %}H_2{% endkatex %}. We start by having some prior belief about the odds of those two. After observing some data, what are the **new** odds of the two hypotheses given the new data? In other words, how do we update our belief based on new evidence?

> :information_source: 
> Let's start by specifying what we mean by *odds*. We mean how large is one probability relative to the other. Let's put it as a ratio. For example, if prior to seeing any data one hypothesis has {% katex inline %}3/4{% endkatex %} probability of being true and the other has {% katex inline %}1/4{% endkatex %}:
> 
> {% katex %}\frac {P(H_1)} {P(H_2)}=\frac {3/4} {1/4}=\frac 3 1{% endkatex %}
> 
> Meaning the odds of {% katex inline %}H_1{% endkatex %} to {% katex inline %}H_2{% endkatex %} are {% katex inline %}3{% endkatex %} to {% katex inline %}1{% endkatex %}.

So how do we incorporate the new data {% katex inline %}D{% endkatex %} into our belief? 

> :bulb: By calculating the new probability of each hypothesis given the new data.
> 
> {% katex %}\frac {P(H_1|D)} {P(H_2|D)}=\frac {\frac {P(H_1 \cap D)} {P(D)}} {\frac {P(H_2 \cap D)} {P(D)}}=\frac {P(H_1 \cap D)} {P(H_2 \cap D)}{% endkatex %}
> 
> Now we'll use a mathematical trick of multiplying and dividing **by the same number** to get the same value but expressed in terms of the **probability of seeing the observed data given each hypothesis**.
> 
> {% katex %}=\frac {P(H_1 \cap D)} {P(H_2 \cap D)} \cdot \frac {P(H_2)} {P(H_1)} \cdot \frac {P(H_1)} {P(H_2)}{% endkatex %}
> 
> {% katex %}=\frac {\frac {P(H_1 \cap D)} {P(H_1)}} {\frac {P(H_2 \cap D)} {P(H_2)}} \cdot \frac {P(H_1)} {P(H_2)}{% endkatex %}
> 
> So,
> {% katex %}\frac {P(H_1|D)} {P(H_2|D)}=\frac {P(D|H_1)} {P(D|H_2)} \cdot \frac {P(H_1)} {P(H_2)}{% endkatex %}
> 
> And so we have that as a ratio, the posterior odds equal the prior odds times the probabilities of generating the new data.
 
Now let's apply this to the Monty Hall Problem. Let 
{% katex inline %}H_1={% endkatex %}*Your door has the prize*
{% katex inline %}H_2={% endkatex %}*Your door has a goat*
{% katex inline %}D={% endkatex %}*The host reveals a goat*

{% katex %}\frac {P(H_1|D)} {P(H_2|D)}=\frac {1/1} {1/1} \cdot \frac {1/3} {2/3}=3/6=1/2{% endkatex %}

Meaning {% katex inline %}H_2{% endkatex %} is twice as likely as {% katex inline %}H_1{% endkatex %} given the new data and therefore **you should switch**. If you want to convert that to probabilities:

{% katex %}P(H_1)=\frac 1 {1+2}=1/3{% endkatex %}

{% katex %}P(H_2)=\frac 2 {1+2}=2/3{% endkatex %}

This is also a nice way to see that the new data did not change the odds. You had a {% katex inline %}1/3{% endkatex %} chance of getting the prize before the reveal and still do after the reveal if you keep your choice.

## Explanation #3
### An intuition

The explanations above using Bayes' Theorem are not the only way to look at this problem, though. You can arrive at the same result by realizing that the door you chose has a {% katex inline %}1/3{% endkatex %} probability of containing the prize. That means there’s a {% katex inline %}2/3{% endkatex %} probability that the prize is somewhere else. Then the game’s host makes it easy for you by turning the “somewhere else” into a single door.

In fact, you can generalize it like this: for a game with {% katex inline %}n{% endkatex %} doors, choosing one gives you a {% katex inline %}1/n{% endkatex %} chance of winning. That means {% katex inline %}(n-1)/n{% endkatex %} chance that the prize is somewhere else. When the host knowingly eliminates {% katex inline %}n-2{% endkatex %} doors with goats by opening them, they leave only one door you could switch to with, as we established, a probability of {% katex inline %}(n-1)/n{% endkatex %} of containing the prize. Do this mental exercise with 100 doors or a billion doors and it'll become clear.

---

Still not convinced? You could just play the game yourself with 3 doors and keep track of how many times you win by switching. The more you play the closer and closer you'll get to winning {% katex inline %}2/3{% endkatex %} of the time when you switch.