{"id":2061,"date":"2017-08-10T01:41:04","date_gmt":"2017-08-10T06:41:04","guid":{"rendered":"http:\/\/www.laurentlessard.com\/bookproofs\/?p=2061"},"modified":"2017-08-26T14:09:57","modified_gmt":"2017-08-26T19:09:57","slug":"is-this-bathroom-occupied","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/is-this-bathroom-occupied\/","title":{"rendered":"Is this bathroom occupied?"},"content":{"rendered":"<p>After a brief hiatus from Riddling, I&#8217;m back! This <a href=\"https:\/\/fivethirtyeight.com\/features\/is-this-bathroom-occupied\/\">Riddler problem<\/a> is about probability and bathroom vacancy.<\/p>\n<blockquote><p>\nThere 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 &#8220;Vacant&#8221; to &#8220;Occupied&#8221; so that no one else will try the door handle (theoretically) when you are inside. Unfortunately, people often forget to slide the sign to &#8220;Occupied&#8221; when entering, and they often forget to slide it to &#8220;Vacant&#8221; when exiting.<\/p>\n<p>Assume that 1\/3 of bathroom users don\u2019t 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 &#8220;Occupied&#8221; as they enter. However, they forget to slide it to &#8220;Vacant&#8221; when they exit. The remaining 1\/3 of the users are very conscientious: They make sure the sign reads &#8220;Occupied&#8221; when they enter, and then they slide it to &#8220;Vacant&#8221; when they exit. Finally, assume that the bathroom is occupied exactly half of the time, all day, every day.<\/p>\n<p>Two questions about this workplace situation:<\/p>\n<p>1. If you go to the bathroom and see that the sign on the door reads &#8220;Occupied,&#8221; what is the probability that the bathroom is actually occupied?<br \/>\n2. If the sign reads &#8220;Vacant,&#8221; what is the probability that the bathroom actually is vacant?<br \/>\nExtra credit: What happens as the percentage of conscientious bathroom users changes?\n<\/p><\/blockquote>\n<p>Here is how I solved the problem:<br \/>\n<a href=\"javascript:Solution('soln_bathroom','toggle_bathroom')\" id=\"toggle_bathroom\">[Show Solution]<\/a><\/p>\n<div id=\"soln_bathroom\" style=\"display: none\">\n<p>This problem can be solved using <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bayes%27_theorem\">Bayes&#8217; Rule<\/a> but you can also use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Markov_chain\">Markov chains<\/a>. I like Markov chains so that&#8217;s what we&#8217;ll do!<\/p>\n<p>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 &#8220;Vacant&#8221; or &#8220;Occupied&#8221;, that there should be four states (one for each possible pair).<\/p>\n<p>However, this is not the case. The reason is because the transition probabilities are not independent of one another. Consider the state &#8220;bathroom is occupied and the sign says it&#8217;s occupied&#8221;. We must distinguish between the cases where the person occupying the bathroom is conscientious (they will definitely slide the sign to &#8220;Vacant&#8221; when they leave) or not (they will leave the sign as &#8220;Occupied&#8221; after they leave).<\/p>\n<p>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&#8217;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:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_markov.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_markov.png\" alt=\"\" width=\"886\" height=\"292\" class=\"aligncenter size-full wp-image-2070\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_markov.png 886w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_markov-300x99.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_markov-768x253.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>If $\\{x_k\\}$ denotes the probability of being in state $k$ in the diagram, the stationary distribution satisfies the equation:<\/p>\n<p>\\[<br \/>\n\\begin{bmatrix}<br \/>\n0 &#038; 0 &#038; 1 &#038; 1 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; 1 &#038; 1 \\\\<br \/>\np &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\nr &#038; r &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\nq &#038; q &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; p &#038; 0 &#038; 0 &#038; 0 &#038; 0<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}<br \/>\nx_1 \\\\ x_2 \\\\ x_3 \\\\ x_4 \\\\ x_5 \\\\ x_6<br \/>\n\\end{bmatrix}<br \/>\n=<br \/>\n\\begin{bmatrix}<br \/>\nx_1 \\\\ x_2 \\\\ x_3 \\\\ x_4 \\\\ x_5 \\\\ x_6<br \/>\n\\end{bmatrix}<br \/>\n\\]<\/p>\n<p>Solving these equations, we obtain:<\/p>\n<p>\\begin{align}<br \/>\nx_1 &#038;= \\frac{r}{2 (q+r)}, &#038; x_2 &#038;= \\frac{q}{2 (q+r)}, &#038; x_3 &#038;= \\frac{p r}{2 (q+r)}, \\\\<br \/>\nx_4 &#038;= \\frac{r}{2}, &#038; x_5 &#038;= \\frac{q}{2}, &#038; x_6 &#038;= \\frac{pq}{2 (q+r)}<br \/>\n\\end{align}<\/p>\n<p>We can now compute the probabilities we&#8217;re after:<\/p>\n<p>\\begin{align}<br \/>\n\\mathbb{P}(\\text{Vacant}\\mid \\text{says &#8220;Vacant&#8221;})<br \/>\n&#038;= \\frac{x_1}{x_1+x_3} = \\frac{1}{1+p}\\\\<br \/>\n\\mathbb{P}(\\text{Occupied}\\mid \\text{says &#8220;Occupied&#8221;})<br \/>\n&#038;= \\frac{x_4+x_5+x_6}{x_2+x_4+x_5+x_6} = \\frac{r+q-pr}{r+2q-pr}<br \/>\n\\end{align}<\/p>\n<p>When $p=q=r=\\frac{1}{3}$ (equal fraction of conscientious, forgetful, and oblivious users), we obtain:<br \/>\n\\begin{align}<br \/>\n\\mathbb{P}(V\\mid V) &#038;= \\frac{3}{4}, &#038;<br \/>\n\\mathbb{P}(O\\mid O) &#038;= \\frac{5}{8}<br \/>\n\\end{align}<\/p>\n<h3>Bonus: different probabilities<\/h3>\n<p>We have the analytic expressions above for what happens as a function of $p,q,r$&#8230; 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:<br \/>\n\\begin{align}<br \/>\n\\mathbb{P}(V\\mid V) &#038;= \\frac{2}{3-r}, &#038;<br \/>\n\\mathbb{P}(O\\mid O) &#038;= \\frac{r^2+1}{r^2-r+2}<br \/>\n\\end{align}We can also plot these probabilities as a function of $r$:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom-1024x665.png\" alt=\"\" width=\"840\" height=\"546\" class=\"aligncenter size-large wp-image-2065\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom-1024x665.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom-300x195.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom-768x499.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom.png 1106w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ternary_plot\">ternary density plot<\/a>. 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:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_vac.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_vac.png\" alt=\"\" width=\"769\" height=\"652\" class=\"aligncenter size-full wp-image-2080\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_vac.png 769w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_vac-300x254.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_vac-768x651.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_occ.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_occ.png\" alt=\"\" width=\"769\" height=\"652\" class=\"aligncenter size-full wp-image-2079\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_occ.png 769w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_occ-300x254.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2017\/08\/bathroom_occ-768x651.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p>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.<\/p>\n<p>One additional comment: you&#8217;ll notice the point at the top of the triangle (100% oblivious users) is missing. This is because this probability doesn&#8217;t make sense. When all users are oblivious, the sign will never change. So if it starts at &#8220;Vacant&#8221;, it will stay at &#8220;Vacant&#8221; forever.\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>After a brief hiatus from Riddling, I&#8217;m back! This Riddler problem is about probability and bathroom vacancy. 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 &#8220;Vacant&#8221; to &#8220;Occupied&#8221; so that no one else &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/is-this-bathroom-occupied\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Is this bathroom occupied?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[7],"tags":[20,8,2],"class_list":["post-2061","post","type-post","status-publish","format-standard","hentry","category-riddler","tag-markov-chains","tag-probability","tag-riddler"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/comments?post=2061"}],"version-history":[{"count":11,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2061\/revisions"}],"predecessor-version":[{"id":2081,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2061\/revisions\/2081"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=2061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=2061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=2061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}