R Project: Monty Hall Problem Simulation

The Monty Hall Problem problem is loosely based on the American television show Let's Make a Deal, originally hosted by Monty Hall, and became famous as a question that appeared in Marilyn vos Savant's "Ask Marilyn" column in Parade magazine in 1990:

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?

Marilyn's response was that the contestant should switch to the other door, suggesting that contestants who switch have a $2/3$ chance of winning the car, while contestants who stick to their initial choice have only a $1/3$ chance. Many readers of vos Savant's column refused to believe switching increased one's chance of winning the car. Indeed, 10,000 of them -- including nearly 1,000 with PhDs -- wrote to the magazine, with most of them claiming Marilyn was wrong.

As evidence Marilyn vos Savant was correct, let us simulate this scenario using R...

  1. First, write an R function original.door() that simulates the situation where the contestant sticks with his or her original randomly-chosen door. The value returned should be a boolean value that is TRUE when the contestant wins the randomly placed car and FALSE when he or she loses.

  2. Then, write an R function switch.door() that simulates the situation where the contestant switches to the door that was both not chosen originally and not opened by Monty Hall (who -- when he has as choice of doors to open -- picks one at random). Again, the value returned should be TRUE when the contestant wins the car, and FALSE otherwise.

  3. Finally, write an R function cars.won(n,strategy) that takes a number of trials $n$, and a strategy (in the form of one of the function names: original.door or switch.door), and returns a simulated number of cars won in those $n$ trials, using the strategy supplied.

  4. Use your cars.won(n,strategy) function to test both strategies under 3000 trials. Which one works better? Do you believe Marilyn now?