Monty Hall’s paradox — solve it by simulation!

Dec 18, 2018 · 5 min read

Hi! Have you heard about Monty Hall’s paradox? I mean come on, it’s in every book about Bayesian statistics! Thing is even though I know a formal solution to it, it is still counter-intuitive to me, and that why it called a paradox.

A few days ago I was discussing this with my wife, and I found that it’s the same case for her. She has major in analytical chemistry by the way. My major is in computational chemistry, so we both come from the same world. In natural science, we need to confirm everything in an experiment.

So I made a simulation of Monty Hall’s game to illustrate this paradox to my wife.

If you know what it is please skip this paragraph :)

Paradox based on a popular (in the US) show, you may find different versions with doors or with boxes. In a general case, you have three doors, behind one of the doors you have a price. Initially, the price was hidden randomly. And you have a host (Monty Hall obviously) that know where the price is. And then this happened:

1. You are picking a door, where you think the price may be.
2. Host opens one of the remain two doors and shows that there is no price behind this door. He can always do that because he knows where the price is.
3. Now you have only two doors remains — one that you chose initially and another door. You allowed to change your mind and pick remain door instead of the door that you chose initially.
4. The main question is: Should you change your initial decision?

Now, it seems like there is no point to this question! Initially, when you’ve had 3 options, you’ve had a 33% chance to choose correctly, now you have only two options left, so your chances are 50%, right?

The paradox is, that your chances are actually different. You more likely to win, if you change your initial decision. And this is counter-intuitive! Let’s solve this with help of Bayesian formula.

The formal solution to Monty’s Hall paradox

Let’s use the Bayesian formula to solve this!

where p(H) — a probability of the hypothesis before getting new data D — prior,

p(H|D) — a probability of the hypothesis given new data D — posterior,

p(D|H) — a probability of the data given hypothesis — likelihood,

p(D) — a probability of the data — normalize constant

We have 3 hypotheses A, B, and C, represent that price behind door 1, 2, or 3. Hypothesis A means that price behind door A, B behind door B and so on. D in our case is when the host choosing door B and there is no price behind it.

Let’s create a table.

Because initially price was hidden behind the door randomly, the prior probability that price is behind one of the doors is 1/3.

So far so go! Now, let’s think about likelihood.

1. If the price behind door A, the host can open doors B or C. In that case probability of him open door B is 1/2. But since that price behind door A, the probability that price not behind door B is 1.
2. If the price behind door B, the host can only open door C, so the probability of him opens door B is 0
3. If the price behind door C, the host can open door B with probability 1.

Next is easy

Wow! So you are more likely to win (66%) if you change your initial answer. Key to understanding is simple: Host is affecting the probability because he is not choosing randomly which door to open.

So I made a simple experiment to simulate the paradox. You have options to always keep your choice same as an initial answer or always change your initial choice. Please, find Gist below, the repository can be also found on a GitHub

Results:

Below you can find a visualization of the experiment. In a 1000 experiments, I’ve got a 67% chance to win if player changing his initial choice, and only 34% chance to win if I would always keep my initial choice unchanged. Results are very close to the formal solution with the Bayesian formula.

• Computational statistics if fun! And at least for me, it super clearly illustrates the solution.
• Monty Hall’s paradox is not easy to digest, even when you now correct answer, that can be obtained in different ways.

Thanks for reading that! Feedbacks are always welcome on LinkedIn or GitHub

Previous articles: