TheDataGirl

A little blog about big data and other things

The Monty Hall Problem

I had encountered this problem several years ago but was recently reminded of it in a course I am attending. The Monty Hall problem poses as a great probability riddle and is one of the all-time favourites.

The riddle goes as follows. Assume that we are on a game show and we are presented with three doors. Behind one door is the car prize and behind the other two are goats. It is obviously desirable that the contestant chooses the door which has a car behind it.

The contestant is given the opportunity to choose one of these doors. Let us say that they have chosen door 1. The host then removes one of the removing doors from the choices, ensuring that the car has not been removed from the selection.

The Monty Hall question goes as follows, would it make sense to switch the choice the contestant has previously made or to keep the one they had chosen?

Statistics proves that it would be wise to switch door choices. Switching doors gives the contestant 2/3 of a chance of choosing the door with the car behind it whereas keeping the same choice gives the contestant just 1/3 choice of picking the correct door.

The following code was written in R and allows us to test out these probabilities by running 10,000 simulations.

  

monty_hall <- function() {

      choices <- 1:3

                prize_door <- sample(choices,1)

               guess_door <- sample(choices,1)

                #assume choice does not change

                remove_door <-choices[!choices %in% c(1,guess_door)][1]

                return (guess_door == prize_door)

}

rounds <- 10000

results <- replicate (rounds, monty_hall())

probability_same <- (length(which(results))/rounds)*100

probability_flip <- ((rounds – length(which(results)))/rounds)*100

  

The probabilities of a win if the contestant keeps previous choice amounted to 34.04 % whereas if they were to switch door choices, the probability would amount to 65.96%.

You can attempt to run the function several times and results amounting to a similar figure would result from these tests.

Leave a Reply

Your email address will not be published. Required fields are marked *