# Monty Hall - The True picture with Simulation

Many of you might have come across the Monty Hall problem . Here is the wikipedia definition of the problem

*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. 2, which has a goat. He then says to you, "Do you want to pick door No. 3?" Is it to your advantage to switch your choice? - **Wikipedia*

Although it's relatively easy to have an intuitive idea of the solution at times its hard to break it down into its more probabilistic form. This problem primarily arises in our inability to grasp the underlying constraints the problem has to adhere to. Here is my humble effort to explain the Monty Hall problem using Bayes theorem followed by a simulation of the same.

Let the variable denote the door behind which the prize (the car) might be present. Since each of the door is equally likely to contain the prize hence

where denotes the probability of the prize(car) behind the door number .

Similarly, let the random variable denote the host's choice of the door and hence denotes the probability of the host choosing the door number

We are given that the contestant chooses the door 1. Since the contestant chooses the door 1 the host is restricted to open either of the door 2 or 3 with equal probability. Hence the probability of host choosing different doors are as below

Now if the actual prize is behind door 2, in that case the host will always open 3 since the host will open a door that doesn’t reveal the prize. This gives us the conditional probabilities

Similarly, if the prize is behind door 3, the conditional probabilities we would have are as below

Also, if the actual prize is behind door 1, the host can choose either 2 or 3 with equal probability unless the host has any bias towards any door. The conditional probabilities would be given by

Now given that the host has opened door 2, we would have to evaluate the contestant's winning probability in sticking to door 1 (initial door) and in switching to door 3. The probability that the actual door that holds the prize is door 1 given that the host has opened door 2 is given by

So, we see that if the contestant sticks to door 1 he/she has a chance of winning.

Now let’s calculate the probability of the actual door being 3 given the host has chosen door 2

So, given the host has opened door 2, the probability of the door 1 hiding the prize is while that for door 3 is . Hence the contestant has a better chance of winning the car by deciding to switch to the other closed door.

Below is the simulation of the Monty Hall problem with the Contestant holding on to the original door followed by Monty Hall Simulation where the contestant do chose to switch to the other door.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# import numpy as np host_flag = 'not so clever' # hold on to the original door num_trails = 30000 win_count = 0 for i in xrange(num_trails): car_door = np.random.randint(low=1,high=4) contestant_choice_door = 1 if (car_door == contestant_choice_door): host_choice = np.random.choice([2,3],1,p=[0.5,0.5])[0] if (car_door == 2): host_choice = 3 if (car_door == 3): host_choice = 2 if host_flag == 'not so clever': new_choice = contestant_choice_door if host_flag == 'clever': new_choice = set([1,2,3]) - set([contestant_choice_door,host_choice]) new_choice = list(new_choice)[0] if (new_choice == car_door): win_count +=1 print 'winning rate:',win_count/float(num_trails) winning rate: 0.3297 |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# import numpy as np host_flag = 'clever' # switch to the other door num_trails = 30000 win_count = 0 for i in xrange(num_trails): car_door = np.random.randint(low=1,high=4) contestant_choice_door = 1 if (car_door == contestant_choice_door): host_choice = np.random.choice([2,3],1,p=[0.5,0.5])[0] if (car_door == 2): host_choice = 3 if (car_door == 3): host_choice = 2 if host_flag == 'not so clever': new_choice = contestant_choice_door if host_flag == 'clever': new_choice = set([1,2,3]) - set([contestant_choice_door,host_choice]) new_choice = list(new_choice)[0] if (new_choice == car_door): win_count +=1 print 'winning rate:',win_count/float(num_trails) winning rate: 0.665466666667 |

We can see from the above simulations also the chances of winning is almost double if one chooses to switch to the other door instead of holding on to the original door.