Wednesday, February 25, 2015

The Monty Hall Problem

Imagine you are on a television game show and the host shows you three doors.  Behind one door is a brand new car, but behind the other two doors are two goats.  You pick Door #1, but just before it is opened, the host says he will open a different door other than the door that you picked that has a goat behind it, and opens Door #3 which reveals one of the two goats.  The host then offers you the chance to stay with Door #1 or to switch to Door #2.  What should you do?


This problem is called the “Monty Hall Problem” in honor of Monty Hall, the host of Let’s Make a Deal, a television game show which had similar games such as this one.  The “Monty Hall Problem” gained popularity in 1990 when vos Savant, a columnist for Parade Magazine, wrote about the problem and asserted that you should switch doors for a 2 in 3 chance of winning, since your original choice for Door #1 was a 1 in 3 chance, leaving you a 2 in 3 chance for the remaining doors, in which one choice (Door #3) was eliminated.  Her solution and explanation was heavily criticized by many of her readers, including PhD professors, who asserted that it makes no difference whether you switch doors or not, because either way there is a 1 in 2 chance of winning since there is one winning door out of the two leftover door options.

Both solutions seem to make sense, but obviously only one can be correct.  So I wrote a small computer program in Python that simulated the scenario one million times and kept track of how many times you would win by switching doors.  The computer program is as follows:

01
#The Monty Hall Solution
02
#Python 2.7.3
03

04
#Be able to pick a random number for the door with the car.
05
from random import randint
06

07
#Total number of trials to calculate.  The higher the number, the more
08
# accurate the probability solution.
09
trials = 1000000
10

11
#Keep track of the number of wins when you switch doors, originally
12
# starting at zero.
13
trials_won_by_switching = 0
14

15
#Go through each trial one by one.
16
for trial in range(1, trials + 1):
17

18
    #Randomly pick a number between 1 and 3 for the door with the car.
19
    door_with_car = randint(1,3)
20

21
    #If the car is behind Door #1, then the goats are behind Door #2 and #3
22
    if (door_with_car == 1):
23
        door_with_goat_1 = 2
24
        door_with_goat_2 = 3
25

26
    #If the car is behind Door #2, then the goats are behind Door #1 and #3
27
    elif (door_with_car == 2):
28
        door_with_goat_1 = 1
29
        door_with_goat_2 = 3
30

31
    #If the car is behind Door #3, then the goats are behind Door #1 and #2
32
    elif (door_with_car == 3):
33
        door_with_goat_1 = 1
34
        door_with_goat_2 = 2
35

36
    #You choose Door #1
37
    door_you_choose_first = 1
38

39
    #Monty Hall picks a different door other than Door #1 that has a goat
40
    #If Door #3 has no car behind it, Monty Hall opens Door #3 to reveal
41
    #  the goat, which makes Door #2 the door to switch to.
42
    if (door_with_car != 3):
43
        door_revealed_with_goat = 3
44
        door_to_switch_to = 2
45

46
    #If Door #3 has the car behind it, Monty Hall opens Door #2 to reveal
47
    #  the goat, which makes Door #3 the door to switch to.
48
    else:
49
        door_revealed_with_goat = 2
50
        door_to_switch_to = 3
51

52
    #If the door to switch to is the door with the car, then add one the
53
    #  number of trials won by switching doors.
54
    if (door_to_switch_to == door_with_car):
55
        trials_won_by_switching += 1
56

57
#When all trials have been run, print the number of trials won by switching
58
#  and give the percent.
59
print "Total number of wins by switching: " + str(trials_won_by_switching) + (
60
    " out of " + str(trials) + " (" + str(
61
    int(round(trials_won_by_switching * 100.0 / trials)))) + "%)"

If there is a 2 in 3 chance of winning by switching doors, then the above computer program should produce a probability of about 67%.  If there is a 1 in 2 chance of winning by switching doors, then the above computer program should produce a probability of about 50%.  So what are the chances?  The computer program produces the following:

>> 
Total number of wins by switching: 666501 out of 1000000 (67%)

The total number of wins varies slightly when the computer program is run again, but the percentage is the same each time: 67%.  There is a 2 in 3 chance of winning by switching doors.  Vos Savant was correct.  If your original choice for Door #1 was a 1 in 3 chance, this leaves a 2 in 3 chance for the remaining doors, in which one choice (Door #3) was eliminated.  So switching doors gives you a 2 in 3 chance of winning.

Scenario
Door #1
Door #2
Door #3
Result If You Switch Doors
Car is behind Door #1
car
goat
goat
You pick Door #1.
Monty shows the goat behind Door #3.
You switch to Door #2 which has a goat.
You Lose!
Car is behind Door #2
goat
car
goat
You pick Door #1.
Monty shows the goat behind Door #3.
You switch to Door #2 which has a car.
You Win!
Car is behind Door #3
goat
goat
car
You pick Door #1.
Monty shows a goat behind Door #2.
You switch to Door #3 which has a car.
You Win!

There are many different problems related to probability in which the “common sense” answer is actually incorrect.  The Monty Hall problem is one of the most famous ones.  At first glance it seems that there should be no difference between picking between the leftover two doors, but in reality there is a 2 in 3 chance of winning if you switch.  For some reason, human intuition fails at many statistical problems like this one.  

2 comments:

  1. I just read Vern Poythress' "Chance and the Sovereignty of God." He is a professor at Westminster Seminary in Philly and has a doctorate in math. The book deals a lot with probability, and has an appendix on the Monty Hall problem, with the same conclusion you have.

    ReplyDelete
    Replies
    1. bonus: "Chance and the Sovereignty of God" is free to download as an eBook from http://www.frame-poythress.org/ebooks/

      Delete