σ Probability & statistics

The Monty Hall problem: why you should switch doors

The Monty Hall problem explained with three arguments and a Python simulation: switching wins 2 times out of 3, and here is where the error comes from.

The Monty Hall problem is probably the most debated probability puzzle ever. It is named after the host of an American television game show and became famous in 1990, when a column by Marilyn vos Savant published the correct solution and received thousands of letters of protest, including from people with mathematical training. It is worth studying not as a curiosity but because it shows precisely how intuition fails when we ignore the way the information was generated.

The precise statement

There are three closed doors. Behind one is a car, behind the other two a goat. The rules, which are worth spelling out in full, are these:

  1. The contestant chooses a door.
  2. The host, who knows where the car is, always opens one of the other two doors, always choosing a door with a goat.
  3. If he has two goat doors to choose from, he opens one at random.
  4. The host always offers the contestant the chance to switch to the last closed door.

Should you switch? The intuitive answer is «it makes no difference, two doors remain, so it is fifty-fifty». The correct answer is: switching wins with probability 2/3, staying with probability 1/3.

First argument: the initial choice does not change

When the contestant chooses, they have a 1/3 probability of having picked the car. Opening a goat door gives no information about their door: the host can always show a goat, whatever is behind the chosen door. So the probability that the initial door hides the car remains 1/3. Since the car must be somewhere, the remaining 2/3 concentrates on the only other closed door.

Second argument: enumerating the cases

Suppose the contestant always picks door 1 and consider where the car can be:

Car behind Host opens Does staying win? Does switching win?
Door 1 Door 2 or 3 Yes No
Door 2 Door 3 No Yes
Door 3 Door 2 No Yes

Each of the three rows has probability 1/3. Switching wins in two rows out of three. The «always switch» strategy loses only when the initial choice was right, which happens one time in three.

Third argument: a hundred doors

If the argument is not convincing, you can exaggerate the problem. There are a hundred doors, the contestant picks one, and the host, knowing where the car is, opens ninety-eight goat doors, leaving only one closed besides the chosen one. It is obvious that the surviving door, spared by an informed host out of ninety-nine possible ones, is suspicious: it contains the car with probability 99/100. The three-door version works the same way, just less conspicuously.

A simulation to convince yourself

When intuition resists, the computer helps. This short program repeats the game a hundred thousand times:

import random

def play(switch):
    doors = [0, 1, 2]
    car = random.choice(doors)
    choice = random.choice(doors)
    openable = [d for d in doors if d != choice and d != car]
    opened = random.choice(openable)
    if switch:
        choice = next(d for d in doors if d not in (choice, opened))
    return choice == car

n = 100_000
print("stay:", sum(play(False) for _ in range(n)) / n)
print("switch:", sum(play(True) for _ in range(n)) / n)

The values obtained fluctuate around 0.333 and 0.667. Writing the simulation also has a valuable side effect: it forces you to encode the rules exactly, and that is often precisely where you notice what intuition had overlooked.

Why intuition fails

The error comes from the idea that two closed doors are automatically equally likely. They are not, because the two doors are not symmetric: one was chosen by the contestant without information, the other survived a filter applied by someone who knew the answer. Probabilities depend on the process that produced the observations, not only on the final observations.

When the rules change, the answer changes

This is the most instructive point. If we modify the host's behaviour, the result changes:

  • Ignorant host: he opens one of the other two doors at random and by pure chance finds a goat. In this scenario, conditioning on the fact that a goat appeared, switching or staying does indeed give 1/2 and 1/2.
  • Malicious host: he offers the switch only when the contestant has picked the car. Then switching always loses.
  • Host who does not always offer the switch: the answer depends on his rule, which the contestant would need to know.

The same observation, «a goat door was opened», has different meanings depending on how it was produced.

The lesson for data analysts

In working with data the same thing often happens: a report shows only the incidents someone decided to report, a log keeps only the events that exceed a threshold, a survey collects only those who chose to answer. Before drawing conclusions you have to ask who or what filtered the information we see, and by what criterion.

In short

  • Under the standard rules, switching doors wins with probability 2/3.
  • Opening a goat door says nothing about the contestant's initial choice.
  • Enumerating the cases or simulating the game makes the answer evident.
  • If the host's behaviour changes, the probabilities change.
  • Probabilities depend on the process that generates the information, not only on the visible result.
MM
Marco Marzaduri

Marco Marzaduri works in cybersecurity, digital forensics and web development. A computer science graduate, he combines rigorous technical analysis with attention to the people who use technology.

Read also