There is a bathroom in your office building that has only one toilet. There is a small sign stuck to the outside of the door that you can slide from “Vacant” to “Occupied” so that no one else will try the door handle (theoretically) when you are inside. Unfortunately, people often forget to slide the sign to “Occupied” when entering, and they often forget to slide it to “Vacant” when exiting.

Assume that 1/3 of bathroom users don’t notice the sign upon entering or exiting. Therefore, whatever the sign reads before their visit, it still reads the same thing during and after their visit. Another 1/3 of the users notice the sign upon entering and make sure that it says “Occupied” as they enter. However, they forget to slide it to “Vacant” when they exit. The remaining 1/3 of the users are very conscientious: They make sure the sign reads “Occupied” when they enter, and then they slide it to “Vacant” when they exit. Finally, assume that the bathroom is occupied exactly half of the time, all day, every day.

Two questions about this workplace situation:

1. If you go to the bathroom and see that the sign on the door reads “Occupied,” what is the probability that the bathroom is actually occupied?

2. If the sign reads “Vacant,” what is the probability that the bathroom actually is vacant?

Extra credit: What happens as the percentage of conscientious bathroom users changes?

This problem can be solved using Bayes’ Rule but you can also use Markov chains. I like Markov chains so that’s what we’ll do!

The first step is to define what are states and transition probabilities are. This is the tricky part; we might be tempted to think that because the bathroom can be either occupied or not, and the sign in front can either read “Vacant” or “Occupied”, that there should be four states (one for each possible pair).

However, this is not the case. The reason is because the transition probabilities are not independent of one another. Consider the state “bathroom is occupied and the sign says it’s occupied”. We must distinguish between the cases where the person occupying the bathroom is conscientious (they will definitely slide the sign to “Vacant” when they leave) or not (they will leave the sign as “Occupied” after they leave).

We must therefore add additional states to our Markov chain that correspond to the different ways in which the bathroom can be occupied. To keep things general, let’s assume the fraction of oblivious, forgetful, and conscientious users are $p$, $q$, and $r$, respectively. Therefore $0\le p,q,r \le 1$ and $p+q+r=1$. A diagram of the Markov chain:

If $\{x_k\}$ denotes the probability of being in state $k$ in the diagram, the stationary distribution satisfies the equation:

\[

\begin{bmatrix}

0 & 0 & 1 & 1 & 0 & 0 \\

0 & 0 & 0 & 0 & 1 & 1 \\

p & 0 & 0 & 0 & 0 & 0 \\

r & r & 0 & 0 & 0 & 0 \\

q & q & 0 & 0 & 0 & 0 \\

0 & p & 0 & 0 & 0 & 0

\end{bmatrix}

\begin{bmatrix}

x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\ x_6

\end{bmatrix}

=

\begin{bmatrix}

x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \\ x_6

\end{bmatrix}

\]

Solving these equations, we obtain:

\begin{align}

x_1 &= \frac{r}{2 (q+r)}, & x_2 &= \frac{q}{2 (q+r)}, & x_3 &= \frac{p r}{2 (q+r)}, \\

x_4 &= \frac{r}{2}, & x_5 &= \frac{q}{2}, & x_6 &= \frac{pq}{2 (q+r)}

\end{align}

We can now compute the probabilities we’re after:

\begin{align}

\mathbb{P}(\text{Vacant}\mid \text{says “Vacant”})

&= \frac{x_1}{x_1+x_3} = \frac{1}{1+p}\\

\mathbb{P}(\text{Occupied}\mid \text{says “Occupied”})

&= \frac{x_4+x_5+x_6}{x_2+x_4+x_5+x_6} = \frac{r+q-pr}{r+2q-pr}

\end{align}

When $p=q=r=\frac{1}{3}$ (equal fraction of conscientious, forgetful, and oblivious users), we obtain:

\begin{align}

\mathbb{P}(V\mid V) &= \frac{3}{4}, &

\mathbb{P}(O\mid O) &= \frac{5}{8}

\end{align}

### Bonus: different probabilities

We have the analytic expressions above for what happens as a function of $p,q,r$… so now it remains to visualize it somehow. One possibility is to set two of them equal and just make a plot. For example, if we only vary the percentage of conscientious users ($r$) and set the other two to be equal, i.e. $p=q=\frac{1-r}{2}$. We then obtain:

\begin{align}

\mathbb{P}(V\mid V) &= \frac{2}{3-r}, &

\mathbb{P}(O\mid O) &= \frac{r^2+1}{r^2-r+2}

\end{align}We can also plot these probabilities as a function of $r$:

If we want to see what happens as we vary the percentages of $p,q,r$ all at once, we can visualize the result using a ternary density plot. Here, we plot values in a triangle; the fraction of each type of bathroom user is determined by the length of the altitude to the opposite side of the triangle and the color indicates the probability. Here are the plots:

You can read off the appropriate percentages by looking at the tick marks. For example, the lower-left corner corresponds to everybody being conscientious, the bottom (horizontal) side of the triangle corresponds to nobody being oblivious, and as you move from left to right you increase the fraction of forgetful users while simultaneously decreasing the fraction of conscientious users. The center of the triangle corresponds to $p=q=r=\tfrac{1}{3}$, and so on.

One additional comment: you’ll notice the point at the top of the triangle (100% oblivious users) is missing. This is because this probability doesn’t make sense. When all users are oblivious, the sign will never change. So if it starts at “Vacant”, it will stay at “Vacant” forever.

I’m honored you returned to tackle my bathroom problem. The Markov chain approach never occurred to me, but I’m relieved that you got the same answers I did using a Bayesian approach!