The Monty Hall Problem
Switch or stay? With a famous guessing game you learn to record an experiment as data, rebuild it in R and play it so often that the data give an answer hardly anyone expects.
Phase 1: Play the game
Phase 2: Games as vectors
Phase 3: 100 games as a tibble
tibblePhase 4: Simulate the game
About this project
On a game show there are three doors. Behind one waits a car, behind each of the other two a goat. You choose a door, and the host, who knows where the car is, then opens one of the other two, always one with a goat. Then he asks whether you stay with your door or switch to the other closed one.
Most people are sure that it makes no difference, since two doors are left. Whether that is true you will not find out by thinking in this project, but with data: you play yourselves, record every round, analyse a data set of 100 games and let R repeat the game until the answer no longer depends on chance. Every phase ends with an experiment you carry out as a team.
Along the way you learn what every data analysis needs: how to write down an
experiment so that it can be analysed, what such data look like in R as
vectors and as a tibble, and how a few lines of code run an experiment as
often as you like and turn it into a data set.
What you need
A browser is enough for everything, since the game and R run on the pages of
the platform. If you prefer working on your own computer, take Positron
and download the data set. For further reading, chapters
5 to 7 of Hands-On Programming with R fit well, on objects, the notation
with square brackets and modifying values, and for tibbles and dplyr the
first chapters of R for Data Science.
Details
- Level
- Beginner
- Modules
- Empirical Research
- Code
1663- Updated
- 3 November 2026
- Status
- published