{"id":4060,"date":"2017-03-22T13:43:02","date_gmt":"2017-03-22T18:43:02","guid":{"rendered":"http:\/\/hoolihan.net\/blog-tim\/?p=4060"},"modified":"2017-03-22T13:43:02","modified_gmt":"2017-03-22T18:43:02","slug":"simulating-monty-hall-problem-r","status":"publish","type":"post","link":"http:\/\/hoolihan.net\/blog-tim\/2017\/03\/22\/simulating-monty-hall-problem-r\/","title":{"rendered":"Simulating the Monty Hall Problem in R."},"content":{"rendered":"<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monty_Hall_problem\">Monty Hall Problem<\/a> is famous in the world of statistics and probability. For those struggling with the intuition, simulating the problem is a great way to get at the answer. Randomly choose a door for the prize, randomly choose a door for the user to pick first, play out Monty&#8217;s role as host, and then show the results of both strategies. <\/p>\n<figure id=\"attachment_4061\" aria-describedby=\"caption-attachment-4061\" style=\"width: 600px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/MontyHall.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/MontyHall.png\" alt=\"Simulating Monty Hall in R\" width=\"600\" height=\"300\" class=\"size-full wp-image-4061\" srcset=\"http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/MontyHall.png 600w, http:\/\/hoolihan.net\/blog-tim\/wp-content\/uploads\/2017\/03\/MontyHall-300x150.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4061\" class=\"wp-caption-text\">Simulating the strategies of Monty Hall<\/figcaption><\/figure>\n<p>The numeric output will vary, but look something like:<\/p>\n<p><code>&gt; print(summary(games$strategy) \/ nrow(games))<br \/>\n  stay switch<br \/>\n 0.342  0.658 <\/code><\/p>\n<p>The following code does this in a rather short R example:<\/p>\n<script src=\"https:\/\/gist.github.com\/911e0ea4d4e9d07abbffacbeb0535c2a.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>The Monty Hall Problem is famous in the world of statistics and probability. For those struggling with the intuition, simulating the problem is a great way to get at the answer. Randomly choose a door for the prize, randomly choose a door for the user to pick first, play out Monty&#8217;s role as host, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,306,267,316],"tags":[319,313,318,278,317],"class_list":["post-4060","post","type-post","status-publish","format-standard","hentry","category-data","category-data-science","category-r","category-simulation","tag-dplyr","tag-ggplot2","tag-monty-hall","tag-r","tag-simulation"],"_links":{"self":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/4060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/comments?post=4060"}],"version-history":[{"count":0,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/posts\/4060\/revisions"}],"wp:attachment":[{"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/media?parent=4060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/categories?post=4060"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hoolihan.net\/blog-tim\/wp-json\/wp\/v2\/tags?post=4060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}