Is This Bathroom Occupied?
August 17, 2017 11:02 AM   Subscribe

The other week there was a puzzle on FiveThirtyEight about the probability of the sign on a bathroom being correct given the behavior of different people in an office (solution). Can you help me figure out why my approach doesn't work?

Basically, the puzzle states that you have three different types of people who change the state of a bathroom and its sign in a different way. I set up my solution as having an initial state (vacant, with sign showing vacant), and then working through a large number of randomly selected people who each change the state of the bathroom in turn. Sampling the state of the sign and the bathroom whenever a person enters or exits the bathroom, I get the following results after 100000 runs:
True positive probability: 0.41693
True negative probability: 0.249075
False positive probability: 0.250925
False negative probability: 0.08307
As it turns out, this is totally wrong:
There is a 62.5 percent chance that the bathroom is occupied if the sign says “Occupied.” There is a 75 percent chance that the bathroom is vacant if the sign says “Vacant.”
What is my solution missing, that would cause it to be so incorrect? Am I double counting some states, or failing to count others?
posted by OverlappingElvis to Sports, Hobbies, & Recreation (6 answers total) 1 user marked this as a favorite
 
Best answer: Disclaimer: I can't read JavaScript without thinking, but I can do math.

The problem is that you didn't make the final step of computing conditional probabilities from your results.

Your "true positive" probability is the probability that the sign says occupied and the bathroom is actually occupied.
Your "false positive" probability is the probability that the sign says occupied and the bathroom is actually vacant.
So the probability that the bathroom is occupied, conditional on the sign saying occupied, is your (TP)/(TP + FP), which works out to 0.62428 or so, within a reasonable margin of error for a simulation.

Similarly your TN/(TN + FN) is very close to 0.75.
posted by madcaptenor at 11:11 AM on August 17, 2017 [4 favorites]


Yeah, you're sampling wrong. You should sample at random times, then separate those by the sign marker, the compute the probabilities conditioned on that.

You may have other errors too, but that's what jumped out at me.
posted by SaltySalticid at 11:13 AM on August 17, 2017


Response by poster: The problem is that you didn't make the final step of computing conditional probabilities from your results.

Ok, this is totally it! Just to make sure I actually understand, we have to add the true and false positive (negative) probabilities together because we care what proportion of ALL cases where the sign says occupied actually reflects the bathroom being occupied?
posted by OverlappingElvis at 11:22 AM on August 17, 2017


Best answer: What you want this: 'GIVEN that the sign says occupied, what is the probability that it is in fact occupied?'

Maybe that's what you meant, with "what proportion of ALL cases... " but your wording is less clear, and at first I thought you were referring to the same thing as the "true positive" case at the top. It's a good habit to stick to the formulaic language for this stuff, the semi-standardized nature makes it clearer.

Anyway the conditional probability can be computed by the formula above in this case, which is essentially the same as the first formula given on Wikipedia's page on conditional probability.
posted by SaltySalticid at 11:46 AM on August 17, 2017


Response by poster: Thanks, I didn't know that conditional probability was what I was looking for! I'm just a programmer without a strong math background.
posted by OverlappingElvis at 11:52 AM on August 17, 2017 [1 favorite]


Response by poster: Just to close the loop, I've updated the gist of my solution and with that missing piece I now get the results I was looking for (and more importantly I understand why)!
Results after 500000 runs:
Probability of the bathroom being occupied when the sign reads occupied: 0.6251
Probability of the bathroom being vacant when the sign reads vacant: 0.7506

posted by OverlappingElvis at 1:29 PM on August 17, 2017 [1 favorite]


« Older What fitness tracking armb..wat.. THING is right...   |   Advice for Amorgos? Newer »
This thread is closed to new comments.