Monty Hall Problem Simulation

There is a popular online puzzle called the Monty Hall Problem. This puzzle dates to a letter by Steve Selvin published in the journal American Statistician in 1975. Similar statistical problems had been published by Martin Gardner in Scientific American, but this particular one is relatively simple to state and leads to a somewhat paradoxical result. It was republished in Parade magazine in 1990 in a regular column by Marilyn vos Savant where it received wider attention.

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

The paradox stems from the idea that the player has a final choice of two doors, with no direct knowledge of the car location, so it should not matter if he switches or not. But with the typical assumptions of the game show situation, the odds are actually doubled (from 1/3 to 2/3) if the player switches doors. However, those probabilities depend on those underlying assumptions, and it can be surprising which assumptions affect the odds. This code explores several of those options by doing statistical simulations.

montyhall.f90 (11.1 KB)

Here is a typical output:

$ gfortran montyhall.f90 && a.out
sim1: N= 1000000 win: 667274 0.667 loss: 332726 0.333
sim2: N= 1000000 win: 666840 0.667 loss: 333160 0.333
sim3: N= 1000000 win: 666319 0.666 loss: 333681 0.334
sim4: N= 1000000 win: 332696 0.333 loss: 333614 0.334
sim5: N= 1000000 win: 666334 0.666 loss: 333666 0.334
sim6: N= 1000000 win: 666575 0.667 loss: 333425 0.333
sim7: N= 1000000 win: 0 0.00 loss: 334181 0.334

I should mention that internally the doors are numbered 0, 1, and 2 in this code. This simplifies some of the math, but does not change the puzzle in any significant way.

The sim1 subroutine uses what I think are the typical implicit assumptions. Namely that the car door is chosen randomly, the player choice is random, Monty Hall is required to expose a goat regardless of the player choice, and that there is no movement of the car and goats behind the doors after either of the choices have been made. This simulation shows the expected behavior that the chance of winning the car is doubled if the player switches doors.

The sim2 and sim3 subroutines show the results if the specific goat door that is exposed is not random. It is sometimes argued that this affects the odds. This simulation shows that is not the case. The sim2 subroutine shows the results if the player knows the goat door algorithm and attempts to use it to advantage. The sim3 subroutine shows what happens if the goat door uses the same algorithm (the largest goat door is always exposed), but the player does not know the algorithm and chooses the final door in the usual way. The results of this simulation surprised me a little. Especially in the sim2 case, I would have thought that the player could have used that information to gain a little more advantage.

The sim4 case also surprised me a little. In this simulation Monty Hall picks an unchosen door at random rather than always exposing a goat door. My intuition told me that it should not matter, with knowledge or random chance, as long as a goat was exposed, I thought the initial choice always had 1/3 chance of winning and switching would then always have a 2/3 chance of winning. After seeing the results (1/3 and 1/3), I then realized what happens. Those increased odds of switching are because the car can initially be behind the unselected doors twice as often as the selected door. That part of my intuition was correct. But what I missed is that when Monty Hall exposes the car and ends the game, that eliminates exactly the advantage of switching. So for this case, the player’s initial choice is correct 1/3 of the time, the game ends early 1/3 of the time, and the remaining door is correct 1/3 of the time. So for the final choice, it doesn’t matter if the player switches or not in this case.

The sim5 and sim6 cases did not surprise me, I just included these cases to convince myself that my intuition was correct in these two situations (after all, I was wrong about the sim4 case). One case is when the car door is random but the player always initially chooses door 1, and the other is that the car is always door 1 but the player, who does not know that, always chooses randomly. It does not matter which door is predetermined in these simulations.

The sim7 case shows what happens if Monty Hall is not required to give the player a second choice. In this simulation he only gives the player a second opportunity to switch when he has chosen the car door initially. In this case, the player should never switch (and he would win 1/3 of the time), but if he makes the usual implicit assumptions and always switches, then he will lose every time. This did not surprise me, but it does show how important those implicit assumptions are to the game strategy. The optimal strategy against a possibly malicious Monty Hall would be to flip a coin for the final choice; that would result in early game termination up to 2/3 of the time, a win 1/6 of the time, and a loss 1/6 of the time.

There is also some psychology that comes into play. Many people would feel worse about initially choosing the correct door and then switching at the end than they would about choosing initially the wrong door and then not switching given the opportunity. (This is related to the Trolley Problem, a well known moral dilemma, where many people feel less guilt taking no action rather than taking an active role in the outcome.) Feelings of loyalty, or commitment, to the initial choice also come into play, even though, in this case, the chance of winning doubles by switching (with the usual implicit assumptions). Some people also think of Monty Hall as a malicious adversary in the game, giving the player choices designed to entice him to choose a goat (as in the sim7 model above).

There may be some other implicit assumptions and other game strategies that are not explored in this code. If you recognize a new case, then please add that to the code and show the results here. It is interesting to see both cases, where a strategy is expected to change the odds but doesn’t, and cases where a strategy is not expected to change the odds but does.

1 Like

The Monty Hall problem is a nice demonstration of Bayes’ rule optimality for combining past knowledge with new evidence. I always use it as an exercise for students in my introductory Data Science courses. The key idea is that, initially, the guest’s choice has a 1/3 chance of having a car. The other two doors cumulatively have a 2/3 chance of having a car. After an informed host intentionally eliminates one of the two remaining doors, all of that 2/3 probability concentrates on the remaining door, not selected by the guest, and so the guest would be twice as likely to win by switching.
Of course, if the host is uninformed (which could ruin the game by the host unintentionally opening the door that has the car) then there is no benefit in switching the choice after the host eliminates a door, as illustrated in the plots below.
The bottom line is that no matter how you start (win or lose initially), as long as an informed host eliminates one of the remaining doors, a guest who follows Bayes’ rule in decision-making will always win twice as often in the long run.

Exp1_infLoop

Exp4_infLoop

Exp3_infLoop

Exp2_infLoop

2 Likes

This is the sim4 case in the program. This is one of the cases where my intuition failed. Even after I saw the results, my first inclination was to look for errors in the code. It was only after that that I worked through the details and finally understood the reason.

Here are the equations for readers interested. The only difference between the informed host (sim1) and the uninformed host (sim4) is that the informed host’s choice is deterministic (in the three-door Monty Hall game) and carries information that the analysis must use. The uninformed host’s choice is purely ignorant and random and carries no new information. This creates a factor-of-2 difference in the probability that the host picks one of the two remaining doors, say door 3 (H3 hypothesis). The relevant simulations in your program seem to be sim1 and sim4, with others effectively equivalent to sim1. Beautiful illustration of Bayes rule indeed.

The puzzle becomes far less intuitively paradoxical if you modify it having 10M doors and keep only one “winning” door.

1 Like

Yes, this is one of the interesting psychological aspects. When the number of doors is increased, even to smaller numbers like 4 or 5, then intuition eventually agrees with the math. But for some reason, that doesn’t happen for many people in the three-door problem. After the Parade magazine publication, there were many many people who disagreed with the analysis, including mathematicians, engineers, and scientists, all of whom should have known better because of their everyday experiences with similar problems. The Trolley Problem is the same in this respect. Given the choice of inaction to kill N people or action to kill 1 person, for many people N must be surprisingly large before they can justify action. But if the tracks are reversed, then inaction to save N people is almost always chosen.

Another variation of the Monty Hall problem is to allow the player to initially choose two of the doors, then Monty Hall exposes the goat behind one of those choices (there must be at least one), and then gives the player the chance to switch. Most people intuitively choose to keep the original door, which is correct in this case. But when you think about it, you realize that this is exactly the same game as before with exactly the same probabilities, just with the keep/switch outcome reversed. One’s intuition agrees with the math in one way, but disagrees with the math in the other. This is the psychological loyalty/commitment or action/inaction aspect kicking in.

1 Like

The last paper I remember seeing on this problem was on arXiv in 2016, about half a century after its introduction. There may have been more on arXiv since 2016.