John Peach

Mind-sized STEM ideas and experiments, beyond the textbook.

Marylin and The Goats

Home

keywords: Monty Hall Problem, probability simulation, R programming, game show mathematics, statistical paradox

Throw out your gold teeth and see how they roll; The answer they reveal: life is unreal.

— Your Gold Teeth II, by Steely Dan

Marilyn

Marilyn is very smart, maybe the smartest person in the world. She has written short stories, magazine and newspaper articles, and more than 20 books. She became financially independent by investing in stocks and real estate, and in 1985 was listed in The Guinness Book of World Records as the person with the highest IQ in the world with an IQ of 228. She took her mother's name, vos Savant as her last name, and on August 23, 1987, she married Robert Jarvik, who developed the Jarvik-7 artificial heart. She is also a descendent of the physicist Ernst Mach, sometimes going by Marilyn Mach vos Savant.

marilyn-vos-savant

In 1986, Parade Magazine published a profile of her, and it was so popular that they asked her to write a weekly column, Ask Marilyn. The IQ test that made her famous was written by philosopher Ronald K. Hoeflin, called the Mega Test designed to find people with one in a million IQs (99.9999th percentile), which admits them to the Mega Society. The test was first published in the April 1985 issue of OMNI magazine, and a high score would also admit you into less intelligent groups such as the Triple Nine Society (99.9%), The International Society of Philosophical Enquiry (99.96%), The Prometheus Society (99.99%), and the Titan Society (99.999%). Pity the poor Mensans with IQs merely in the top 98th percentile.

The Goats

In 1990 a reader of the Ask Marilyn column wrote, "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?"

In 1975 Steve Selvin, a statistician at UC Berkeley, presented the same problem to the American Statistician, calling it The Monty Hall Problem from the game show Let's Make a Deal.

game-show

Monty Hall is required by the game rules to

  1. always open a door that was not picked by the contestant
  2. always open a door to reveal a goat and never the car
  3. always offer the chance to switch between the originally chosen door and the remaining closed door.

Should you stick with your original choice of Door #1, or switch to Door #2?

In her column, Marilyn said that you should always switch doors. Then the letters poured in 10,000 of them and 1,000 of those from Ph.D. statisticians and mathematicians.

letter

Goat Analysis

First, you pick a door, any door. Suppose you pick a door with a goat. Then Monty will show you the other goat, and you should switch to the third door. If you pick the door with the car, Monty shows you one of the goats and you shouldn't switch. Since you don't know what's behind the door you initially selected, let's follow Marilyn's logic of always switching.

Diagram stepping through each scenario, revealing car as outcome 2/3 of the time.

If you happen to pick a door with a goat, then by switching you end up with the car. Two-thirds of the time you'll be randomly choosing a door with a goat, so by switching you have a 2 / 3 2/3 2/3 chance of getting the car. On the other hand, if you don't switch, you'll get your first choice (the first column) and wind up with the goat two out of three times. What Scott Smith, Ph.D., University of Florida gets wrong is that the chances are fixed after your initial selection. The host always shows you a goat and that doesn't change the odds, it just changes which door you should choose next.

Maybe some people were confused by the last branch where you pick the door with the car and then there's a split depending on which goat Monty chooses. Another way to look at it is that you'll choose the top branch here with probability 2 / 3 2/3 2/3 and the bottom branch with probability 1 / 3 1/3 1/3:

goat-analysis2

Could you improve your odds of winning the car by randomly choosing to switch or not? Suppose you decide to switch with probability p p p. Then the odds of winning that shiny red car become

2 3 p + 1 3 ( 1 − p ) = 1 3 + 1 3 p . \frac{2}{3}p+\frac{1}{3}(1-p)=\frac{1}{3} + \frac{1}{3}p. 32p+31(1p)=31+31p.

Since 0 ≤ p ≤ 1 0 \leq p \leq 1 0p1, the best you can do is set p = 1 p=1 p=1. In other words, always switch.

Years later, a reader asked Marilyn if any of the irate mathematicians and statisticians had ever written back to apologize. She said,

Several of them wrote back, but none with an apology. Most maintained that the statement of the problem was ambiguous. However, plenty of other readers—people who had thought my answer was wrong but hadn’t written to say so and people whose letters weren’t published—wrote to say they had gotten it wrong at first but were delighted with the “aha” moment when they understood later.

There is one other possibility. Maybe you're a farmer who doesn't cotton to new-fangled contraptions and you'd actually prefer the goat. You probably don't even have a TV or watch Let's Make a Deal.

Let's Make a Simulation

You could start by playing an online simulation written by Adriano Garsia, a professor of mathematics at UCSD. His simulation shows that about 2 / 3 2/3 2/3 of people who switched won the car. This is fun, but you don't get much of a sense about the long term probabilities, and we can't be certain that the code accurately reflects the game.

Another way to simulate the Monty Hall puzzle is with a pair of dice. You could let rolls of 1 or 2 represent door #1, 3 or 4 for door #2 and 5 or 6 for door #3. Let one die be the door with the car and the other be your initial choice. Notice that the only way you don't win the car is when your initial choice is the door with the car. If the two doors are different, then by switching you get the car.

This is what I got after 52 rolls. There are 34 wins, meaning by switching I got the car 65% of the time.

Car Chosen Win Car Chosen Win Car Chosen Win Car Chosen Win
3 2 TRUE 3 3 FALSE 3 1 TRUE 1 1 FALSE
3 1 TRUE 2 3 TRUE 3 3 FALSE 2 3 TRUE
3 2 TRUE 3 2 TRUE 3 2 TRUE 3 2 TRUE
1 1 FALSE 1 1 FALSE 1 3 TRUE 1 2 TRUE
2 2 FALSE 1 3 TRUE 2 1 TRUE 2 2 FALSE
3 3 FALSE 2 3 TRUE 1 2 TRUE 1 1 FALSE
3 1 TRUE 3 2 TRUE 1 1 FALSE 1 2 TRUE
3 1 TRUE 1 3 TRUE 3 2 TRUE 3 3 FALSE
3 2 TRUE 1 1 FALSE 2 3 TRUE 2 2 FALSE
3 3 FALSE 1 2 TRUE 3 2 TRUE 3 2 TRUE
1 3 TRUE 2 3 TRUE 1 3 TRUE 2 3 TRUE
2 2 FALSE 3 2 TRUE 3 3 FALSE 1 1 FALSE
3 1 TRUE 1 2 TRUE 1 2 TRUE 1 1 FALSE

The R Language

For a much bigger simulation, you either need a lot of patience or to write some code. While this could be done in almost any language, this is a good opportunity to experiment with the R language. John Chambers, Rick Becker, and Allan Wilks developed a statistical language they called S while working at Bell Labs. R is derived from S and used by statisticians because of its many specialized statistical functions.

First, download and install R, and I recommend the IDE RStudio. RStudio provides tutorials for beginners to help get started with the environment, with the R language, and with associated packages. When you start RStudio, it should look something like this:

RStudio

The upper left pane (click on the green circle with the white + below File if it's not open), is where you can write new R scripts. The pane below is the console for interacting directly with the language. On the right side are panes for Environment, History, Connections, and Tutorials and below for Files, Plots, Packages, Help, and Viewer. You might find the RStudio Cheat Sheet handy, too.

The sample(x, size, replace) function in R is equivalent to rolling dice. The number of sides is set by x, the number of dice by size and setting replace = TRUE means that the dice are independent so a number appearing on the first die can also appear on the other die. For our experiment, we want 3 sides, and 2 dice, so the call should be sample(3, 2, replace = TRUE).

The program for simulating the Monty Hall problem is pretty simple. Initialize a wins counter, roll a pair of dice with the sample function n times, and if the numbers that come up are not equal, add 1 1 1 to wins. Finally, divide the number of wins by the number of iterations to get the probability of winning.

montyhall <- function(n)
{
  # Win counter
  wins <- 0
 
  # Loop over n samples, rolling a pair of dice
  for(i in 1:n){
    # Roll the dice
    s <- sample(3,2,replace = TRUE)
 
    # If the doors are different, win the car
    if(s[1] != s[2]) wins = wins + 1
  }
 
  # Calculate the probability of winning
  p <- wins/n
 
  # Print the result
  print(p)
 
}

R uses <- as the assignment operator, so initializing wins to zero is done by wins <- 0. Rolling the dice puts a 1 × 2 1 \times 2 1×2 vector into s which you can see at the command line by

> s <- sample(3,2,replace = TRUE); print(s)
[1] 1 2

and if the elements of s aren't equal then wins is incremented by 1 1 1. The probability of winning the car is approximated by the ratio of the number of wins to the number of games played,

p <- wins/n

After you've written the function, click the "Source" button in the upper right corner of the code pane. This will import the function into the command window and let you run experiments. This is what I got from one sample,

> montyhall(10000)
[1] 0.6626

which is just about the 2 / 3 2/3 2/3 expected.

The Last Door

What started as a simple game show puzzle sparked one of the most fascinating controversies in popular mathematics. Marylin vos Savant's correct assertion that switching doors gives you a better chance of winning demonstrated how even highly educated professionals can fall prey to probability paradoxes. Through our dice experiments and R simulation, we've shown that switching doors indeed gives you a 2/3 chance of driving home in that shiny new car (though farmers might prefer the goat).

The Monty Hall problem teaches us several valuable lessons. First, our intuition about probability can be surprisingly unreliable. Second, empirical testing through simulation can help verify mathematical theories in ways that are both convincing and accessible. And finally, sometimes the smartest person in the room isn't the one with the most degrees – they're the one willing to question conventional wisdom and defend their reasoning with clear logic and evidence.

So the next time you're faced with a choice between sticking with your first instinct or switching strategies, remember Marylin and the goats. Sometimes the best decision is to change your mind – about two-thirds of the time, to be precise.

As Steely Dan suggested in our opening quote, when you "throw out your gold teeth and see how they roll," the answer might reveal that life – and probability – isn't always what it seems at first glance.

Today's pop quiz is the Mega Test. You have 15 minutes.


Update January 17, 2021: Monty Hall simulation in JavaScript


Image credits

Hero: The Men Who Stare at Goats

Let's Make A Deal Game Show: Jan De Wilde

RStudio IDE: Posit, PBC

Code and Software

montyhall.r - Monty Hall problem simulation

monty-hall.js - Monty Hall simulation in JavaScript

  • R and RStudio - R is a language and environment for statistical computing and graphics. RStudio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.
  • JavaScript - JavaScript (JS) is a lightweight interpreted (or just-in-time compiled) programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.

See all software used on Wild Peaches →

References and Further Reading

📬 Subscribe and stay in the loop. · Email · GitHub · Forum · Facebook

© 2020 – 2025 Jan De Wilde & John Peach