Should you stick or should you switch when facing Monty Hall? You should switch, now explained with Alteryx.
Introduction
“The Monty Hall problem is a brain teaser, in the form of a probability puzzle, based nominally on the American television game show Let's Make a Deal and named after its original host, Monty Hall.” (Wikipedia)
The layout of the game is that there are 3 boxes—in one of them, there is a prize (and in this example, let’s say it is some awesome Alteryx swag), and in the other 2, there are goats. You will choose a box, let’s say box 1, and then Monty, who knows where the Alteryx swag is, will go and open another box, and you will see a goat (for this illustration, let’s say box 2). Monty will always open a box to show a goat. He will then offer for you to switch boxes, from Box 1 to Box 3; whatever is in the box you choose is your prize.
So, should you switch?
Yes. Mathematically, using Bayes’ theorem, you have a probability of 2/3 to win if you switch, compared to 1/3 if you stick with your original box.
Bayes Theorem:

For a full proof, please see this article.
Don’t worry, mathematics is not the only way to show this; we can also demonstrate this via intuition.
Imagine the Boxes. There is a 1/3 chance that you have chosen the prize and a 2/3 chance that you haven’t.

Hence, you are 2/3 as likely not to have picked it, and switching it will give 2/3 of a chance to pick it.
This can also be shown in a table format, illustrating all the possibilities:
Box chosen
|
Box prize
|
Box Monty opens
|
Win if stick
|
Win if switch
|
1
|
2
|
3
|
N
|
Y
|
1
|
3
|
2
|
N
|
Y
|
1
|
1
|
(random choice)
|
Y
|
N
|
This shows that sticking only wins 1/3 of the time, whereas if you switch, you are 2/3 of the time you will win.
If you are still not convinced, there is another way to prove this using simulation. This can be done via Alteryx.
The Alteryx way
There are 2 main ways to replicate this via simulation in Alteryx.
Method 1: Using the R tools
To use the Monty Carlo simulation, you will need the R tools downloaded. This is done using the Simulation Sampling tool in the Prescriptive tool palette.
Step 1: Setting up the simulations
Set up two Monty Carlo simulations, one for randomly assigning the box choice and the other for where the prize is.


This should be the same for both, just changing the name of the outgoing data in the second screen, and you need to select a different seed number for both. And the number of simulations needs to be the same.
Step 2: Bringing the two simulations together
Bring the two simulations together using a Join tool and joining on position.
Step 3: Converting from continuous to discrete
Convert the simulation numbers from continuous (for where the prize is and the box selected) to district numbers (i.e. 1,2,3) using the Multifield Formula tool.
Step 4: Determining which box Monty opens
If the box chosen has the Alteryx swag, it will be a random choice which box Monty opens; if the box you have chosen doesn’t have the Alteryx Swag, then Monty will open the box that has a goat in it.
So, for example, you choose box 1 and that has the swag, it will be a 50/50 chance for which box Monty opens. If you choose box 1, and the prize is in box 2, then Monty will open box 2.
This is modeled using the following IF statement in a Formula tool:
If [Box chosen]=1 and [Box prize is in ]=1
then 2+ RandInt(1)
// Prize and chosen box is in box 1. It will be random which box Monty opens between 2 and 3
elseif [Box chosen]=1 then Switch([Box prize is in ],Null(),2,3,3,2)
// Box chosen is 1 but the prize is not in box 1 hence Monty opens the box that doesn’t have the prize in, if the prize is in box 2 then open box 3 and visa versa. Similar logic is followed for the other 2 box choices
elseif [Box chosen]=2 and [Box prize is in ]=2
then 2* RandInt(1) +1
elseif [Box chosen]=2 then Switch([Box prize is in ],Null(),1,3,3,1)
elseif [Box chosen]=3 and [Box prize is in ]=3
then 1 + RandInt(1)
else Switch([Box prize is in ],Null(),1,2,2,1)
endif
Step 5: Determine if you would win if you stick or switch
This is done using 2 If statements. For the winning outcome, if you stick to the box you choose (the same one the prize was in) you win; otherwise, you lose. And vice versa for the switch strategy.
Note: Steps 3-5 can be done in a single Formula tool, but I split them up to help emulate the sequence of events as if they were happening in real life.
Step 6: Creating a total and visualizing the reports
Create a dummy field to count the records and then calculate running totals and subsequently percentages. Visualize it using the Reporting tools to see that as the number of records increases, you get close to the true probabilities of 2/3 if you switch and 1/3 if you stick.

Method 2: Without the R tools
Step 1: Setting up the simulation
Start by using the Generate Rows tool to create the number of simulations you want, and then use the Formula tool to randomly select the box chosen and the box the prize is in.
The remainder picks up from step 4 of Method 1.
Conclusion
As said in the beginning, when offered the switch, take the switch, and your chance of winning is doubled.
Hopefully this has helped illustrate to you that Monte Carlo simulation can be used to answer/provide long-term predictions. Use cases include business, finance, online gaming, engineering and medicine, further elaboration of these use cases in this article; in this you can see some further explanations of these examples.
Monty hall with R tools.yxmd
Monty hall without R.yxmd