{"id":554,"date":"2018-05-28T06:57:55","date_gmt":"2018-05-28T06:57:55","guid":{"rendered":"https:\/\/www.aiproblog.com\/index.php\/2018\/05\/28\/poker-probability-monte-carlo-and-r\/"},"modified":"2018-05-28T06:57:55","modified_gmt":"2018-05-28T06:57:55","slug":"poker-probability-monte-carlo-and-r","status":"publish","type":"post","link":"https:\/\/www.aiproblog.com\/index.php\/2018\/05\/28\/poker-probability-monte-carlo-and-r\/","title":{"rendered":"Poker, Probability, Monte Carlo, and R"},"content":{"rendered":"<p>Author: steve miller<\/p>\n<div>\n<p><a href=\"http:\/\/api.ning.com\/files\/Ur-DU7NoTnzf0FLUWVEiG5eFSIxsJj38CEHK8jaucwUh6tC0H9w*dh01yVjxVa9ayOfHyW1PZNHkUUJbukSbTNly9gUVZvVu\/poker_hand.png\" target=\"_self\"><img decoding=\"async\" src=\"http:\/\/api.ning.com\/files\/Ur-DU7NoTnzf0FLUWVEiG5eFSIxsJj38CEHK8jaucwUh6tC0H9w*dh01yVjxVa9ayOfHyW1PZNHkUUJbukSbTNly9gUVZvVu\/poker_hand.png\" width=\"475\" class=\"align-full\"><\/a><\/p>\n<\/p>\n<p>My daughter just started a business analytics Master&#8217;s program. For the probability sequence of the core statistics course, one of her assignments is to calculate the probability of single<span>\u00a0<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Poker_probability#Frequency_of_5-card_poker_hands\">5 card draw poker hands<\/a><span>\u00a0<\/span>from a 52-card deck.<\/p>\n<p>I well remember this exercise from back in the day, when I computed all such relevant probabilities using basic combination counting techniques for an intro to probability course. My daughter though, a business undergrad, is less interested in the math than she is in the stats\/computation, opining that&#8217;s where she&#8217;ll make money.<\/p>\n<p>It&#8217;s hard to argue that logic, though I thought it might be an analytics &#8220;ah-hah&#8221; moment for her to connect the probability math with statistics. The population of 5 card draw hands, consisting of 52 choose 5 or 2598960 elements, is pretty straightforward both mathematically and statistically.<\/p>\n<p>So of course ever the geek, I just had to attempt to show her how probability and statistics converge. In addition to explaining the &#8220;combinatorics&#8221; of the counts and probabilities, I undertook two computational exercises. The first was to delineate all possible combinations of 5 card draws from a 52 card deck, counting occurrences of relevant combinations such as 2 pair, a straight, or nothing in a cell loop.<\/p>\n<p>The second and statistical approach revolves on<span>\u00a0<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Monte_Carlo_method\">Monte Carlo simulation<\/a><span>\u00a0<\/span>that&#8217;s driven from &#8220;repeated random sampling to obtain numerical results. Their essential idea is using randomness to solve problems that might be deterministic in principle.&#8221; So by generating a sizable number of randomly sampled hands, similar logic to that articulated above can be used to tally counts of pertinent combinations. The<span>\u00a0<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Law_of_large_numbers\">Law of Large Numbers<\/a><span>\u00a0<\/span>suggests that as sample size gets large, the statistical counts should look a lot like those probability calculations.<\/p>\n<p>Method 1, grounded in math\/probability, produces exact answers, while Method 2, which revolves on sampling, is approximate and variable, with generally more accuracy the larger the sample size.<\/p>\n<p>Why approximate over exact? In this case the probability distribution is simple, but in more complicated instances, the math may be too complex. Better a Monte Carlo statistical estimate than intractable mathematics.<\/p>\n<p>The remainder of this notebook looks at first the probability calculations and then the corresponding sampling-based approximations. The technology is Jupyter Notebook with Microsoft Open R 3.4.4.<\/p>\n<p>For the probability calculations, I draw heavily on R&#8217;s choose and combn combinatorics functions. The basic sample function feeds the statistical estimation cell&#8217;s main loop. Simple frequencies of individual hands by suit and rank computed from the data.table package are central to the exercise. Not surprisingly, the notebook is very compute-intensive, consuming almost 2.5 hours from end to end.<\/p>\n<p>Read the entire blog\u00a0<a href=\"http:\/\/api.ning.com\/files\/Ur-DU7NoTnxefgDrwCfE9bgI7Oo7mtE3XkjTDv7FqWw6j5oHGnf5zoqjRw7akHWdElK5phmf-1dKuRfdxmeDGG1OKKWaqDNZ\/DSCcardsR.html\" target=\"_self\">here.<\/a><\/p>\n<\/p>\n<\/div>\n<p><a href=\"https:\/\/www.datasciencecentral.com\/xn\/detail\/6448529:BlogPost:723761\">Go to Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: steve miller My daughter just started a business analytics Master&#8217;s program. For the probability sequence of the core statistics course, one of her assignments [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/www.aiproblog.com\/index.php\/2018\/05\/28\/poker-probability-monte-carlo-and-r\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":555,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/554"}],"collection":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":0,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media\/555"}],"wp:attachment":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}