How to solve the Monty Hall problem?

I've looked into this myself and I don't think the problem is with Mathematica. The problem is how to represent the choice of the host. Here's an attempt I tried:

So the basic idea here is: I pick a number between from 1 to 3 and so does the car. The host picks randomly between the numbers 1 and 2 and adds that number (mod 3) to mine to pick a different door than I did. Then you condition on the host's number not being the car.

So what does this give?

unif[n_] := DiscreteUniformDistribution[{1, n}];
Probability[
 Conditioned[
  myChoice == car,
  Mod[myChoice + hostChoice, 3, 1] != car
  ],
 {
  myChoice \[Distributed] unif[3],
  car \[Distributed] unif[3],
  hostChoice \[Distributed] unif[2]
  }
]

1/2

Ugh... that doesn't look right, does it? Surely something went wrong here. Let's just simulate this thing, because numbers don't lie:

simulation = AssociationThread[{"MyChoice", "Car", "HostChoice"}, #] & /@ 
  RandomVariate[
   ProductDistribution[unif[3], unif[3], unif[2]],
   10000
];
Dataset[simulation, MaxItems -> 10]

enter image description here

I'm turning the numbers into Assocations for making the code more readable. So let's do some counting:

CountsBy[
 Select[simulation, Mod[#MyChoice + #HostChoice, 3, 1] =!= #Car &],
 #MyChoice === #Car &
]
N[%/Total[%]]

<|True -> 3392, False -> 3310|>

<|True -> 0.506118, False -> 0.493882|>

Ok, so maybe Probability wasn't wrong after all. What we're seeing here is the real reason why the Monty Hall problem is difficult: the outcome depends crucially on how you model the behaviour of the host. In this description it is -in principle- possible for the host to pick the door with the car. We just condition that possibility away.

But this is different from the actual behaviour of the host: If you pick the door with the car, the host selects randomly between the two remaining doors. If you don't pick the car, the host doesn't pick randomly at all! This is where our calculation breaks down: we always assume the host picks between two doors, but that's not how it works and that's why the Monty Hall problem is trickier than it appears, even when you think you understand it.

To put is succinctly: the line hostChoice \[Distributed] unif[2] is plainly wrong. The host's choice is a combination between a deterministic choice and unif[2] that depends on myChoice.

As for the question how to reproduce the correct answer with Probability and Conditioned: I don't think that it's possible to represent this type of conditionality (i.e., the distribution of one random variable depending on another random variable) can be implemented with the tools currently given. The only thing that comes close is ParameterMixtureDistribution, but I don't think that will help here.


Edit

I'm happy to let you know that I actually did manage to squeeze Monty Hall into ParameterMixtureDistribution with some torture. First of all, we will need to be able to define probability distributions such as "a random choice from the numbers in a list by weight". I defined such a distribution as follows:

Clear[discreteNumberDistribution]
discreteNumberDistribution[lst_List -> weights_List, {min_, max_}] := 
  With[{nWeights = weights/Total[weights]},
   ProbabilityDistribution[
    Sum[nWeights[[i]]*KroneckerDelta[\[FormalX], lst[[i]]], {i, Length[lst]}],
    {\[FormalX], min, max, 1}
   ]
];

So now we can do things like:

RandomVariate @ discreteNumberDistribution[{2, 3} -> {2, 10}, {1, 3}]

3 (* most likely *)

Now we can define the mixture distribution of my choice, the car and the host choice as follows:

mixture = ParameterMixtureDistribution[
  ProductDistribution[
   discreteNumberDistribution[{\[FormalM]} -> {1}, {1, 3}], (* my choice *)
   discreteNumberDistribution[{\[FormalC]} -> {1}, {1, 3}], (* car *)
   discreteNumberDistribution[ (* host choice *)
    Range[3] -> (Boole[! (\[FormalM] == # || \[FormalC] == #)] & /@ Range[3]),
    {1, 3}
   ]
  ],
  {
   \[FormalM] \[Distributed] DiscreteUniformDistribution[{1, 3}],
   \[FormalC] \[Distributed] DiscreteUniformDistribution[{1, 3}]
   }
];

So let's ask Mathematica again:

Probability[myChoice == car, {myChoice, car, host} \[Distributed] mixture]

1/3

and

Probability[
  otherChoice == car \[Conditioned] otherChoice != myChoice && otherChoice != host, 
  {
    {myChoice, car, host} \[Distributed] mixture, 
    otherChoice \[Distributed] DiscreteUniformDistribution[{1, 3}]
  }
]

2/3

Victory!


I know that this is not what you want, but for completeness I'll add a Monte-Carlo version:

findthecar[numberofdoors_Integer /; numberofdoors >= 3] :=
  Module[{car, goats, myfirstchoice, notmyfirstchoice, organizerschoice, mysecondchoice},
    (* the car is behind a random door *)
    car = RandomInteger[{1, numberofdoors}];
    (* there are goats behind the other doors *)
    goats = Complement[Range[numberofdoors], {car}];
    (* at first I choose a random door *)
    myfirstchoice = RandomInteger[{1, numberofdoors}];
    (* these are the doors I did not choose yet *)
    notmyfirstchoice = Complement[Range[numberofdoors], {myfirstchoice}];
    (* the organizer opens a door that is not my choice and that has a goat *)
    organizerschoice = RandomChoice@Intersection[notmyfirstchoice, goats];
    (* my second choice is not my first and not the organizer's *)
    mysecondchoice = RandomChoice@Complement[Range[numberofdoors],
                                             {myfirstchoice, organizerschoice}];
    (* is the car behind my second chosen door? *)
    mysecondchoice == car]

Try it out a million times for three doors, and see that I find the car in about 2/3 of cases:

Table[findthecar[3], {10^6}] // Counts
(*    <|True -> 666122, False -> 333878|>    *)

More generally, in a game of $n$ doors where the organizer opens $k$ goat-revealing doors and I am given the option to switch, my probability for finding the car before and after switching are

$$ P_{\text{no switch}}(n,k) = \frac{1}{n},\\ P_{\text{switch}}(n,k) = \frac{n-1}{n(n-k-1)}, $$

respectively. As $P_{\text{switch}}(n,k)>P_{\text{no switch}}(n,k)$ in all cases, we should always switch after the organizer's goat-reveal.