## R Shiny app: Monty Hall gone wild

Ah, probability! Generalizing the famous Monty Hall problem. Here I generalize this fun probability game a bit and I’ve put the results into an **R** Shiny web application. In the classic Monty Hall problem, which originates from the old game show, Let’s Make a Deal (hosted by Monty Hall), there are three doors. Behind one of these doors is a car. Behind the other two stand goats. Monty Hall tells you to choose a door. You hope to win the car obviously, by randomly choosing the correct door. After you make your choice, the door remains closed. Monty Hall then opens one of the other two doors, always to reveal a goat. After all, if you have not chosen the correct door, and the car is behind one of the other two, what point is there in Monty showing you the car? That would end the game. After he shows you a goat, he gives you a simple choice. Do you want to stick to your guns and open the door you originally chose or do you want to switch to the other unopened door? Does it make a difference in your chances of winning? It certainly does.

This web application displays plots of probabilities of winning the car in more general versions of the Monty Hall game. There can be three or more doors. The Monty Hall function I wrote in **R** will allow any combination of numbers of doors selected (but unopened) by the player, and subsequently a mutually exclusive set of doors opened to reveal goats by Monty Hall, so long as the doors chosen by the player and by Monty leave at least one door unchosen by the player and unopened by Monty. However, for simplicity, time management, and a general interest in avoiding overkill at least for now, I have currently restricted the app to plotting probability heat maps of n x n grids where n is just less than half of N, the total number of doors. This way you get a square heat map of probabilities that at least pertain to somewhat more interesting games, rather than the full triangular matrix of all possible games, e.g., there are 25 doors, you select one, then Monty opens 23 doors to reveal goats and asks if you want to switch to the last remaining door. (You better switch! ALWAYS switch! But especially now!)

One important point of clarification is that when the player and Monty both have multiple options, and not necessarily the same number of options either, the notion of switching is no longer trivial. Here I have chosen to simplify the idea of switching by what I am calling maximum switching. If the player chooses to switch, this means switching to as many of the initially unselected doors that remain closed after Monty hall reveals goats as possible. For example, say there are ten doors. The player chooses three, Monty opens three others. This leaves four doors to which the player can switch. Similar to the original Monty Hall problem, the player either sticks with the original three or completely switches to an alternative remaining three. Since there are four to choose from, the player simply chooses three of these four at random. Say there are ten doors, the player selects four, and Monty opens three. This leaves three. Switching in this scenario means the player will automatically select all three remaining doors, and then retain one at random from the original selection. Maximum switching means abandoning the original selection of doors as much as possible.

No more, no less. The game could be generalized further. Switching could be less trivial, there could be more than one car, or other prizes to win, etc. But ain’t nobody got time for that.