<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tuan Doan on Medium]]></title>
        <description><![CDATA[Stories by Tuan Doan on Medium]]></description>
        <link>https://medium.com/@tuannguyen-doan?source=rss-87144e3252f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1yXOgM5q1vhrkhUzahJg2A.png</url>
            <title>Stories by Tuan Doan on Medium</title>
            <link>https://medium.com/@tuannguyen-doan?source=rss-87144e3252f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 03:38:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuannguyen-doan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Love, Strategically: the Game Theory of modern dating]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://aiadvances.org/love-strategically-the-game-theory-of-modern-dating-fc320aed32eb?source=rss-87144e3252f6------2"><img src="https://cdn-images-1.medium.com/max/1642/1*Qstg2VB_COE9Id0MMDJUHQ.png" width="1642"></a></p><p class="medium-feed-snippet">The math behind why everyone ghosts, noone commits, and we all put up with the bare minimums</p><p class="medium-feed-link"><a href="https://aiadvances.org/love-strategically-the-game-theory-of-modern-dating-fc320aed32eb?source=rss-87144e3252f6------2">Continue reading on AI Advances »</a></p></div>]]></description>
            <link>https://aiadvances.org/love-strategically-the-game-theory-of-modern-dating-fc320aed32eb?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc320aed32eb</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[dating]]></category>
            <category><![CDATA[economics]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Tue, 10 Feb 2026 11:14:32 GMT</pubDate>
            <atom:updated>2026-02-12T07:41:18.971Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Parking Problems? Don’t blame the drivers, blame the Statistics]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science-collective/parking-problems-its-not-the-driver-it-s-the-stats-52cb64192451?source=rss-87144e3252f6------2"><img src="https://cdn-images-1.medium.com/max/1680/1*HeLPLK42YRRgt86u84zp_A.png" width="1680"></a></p><p class="medium-feed-snippet">Parallel parking is always so cursed and it&#x2019;s not because of those terrible drivers</p><p class="medium-feed-link"><a href="https://medium.com/data-science-collective/parking-problems-its-not-the-driver-it-s-the-stats-52cb64192451?source=rss-87144e3252f6------2">Continue reading on Data Science Collective »</a></p></div>]]></description>
            <link>https://medium.com/data-science-collective/parking-problems-its-not-the-driver-it-s-the-stats-52cb64192451?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/52cb64192451</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Wed, 16 Apr 2025 04:01:31 GMT</pubDate>
            <atom:updated>2026-02-13T02:47:01.654Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Expectedly Unexpected: The Mathematical Art of Measuring Surprise]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/expectedly-unexpected-the-mathematical-art-of-measuring-surprise-28c04f0e8a1a?source=rss-87144e3252f6------2"><img src="https://cdn-images-1.medium.com/max/1920/1*_TJ9iA3NtsPjUOXyGjdpcA.jpeg" width="1920"></a></p><p class="medium-feed-snippet">The statistical reasons behind why Taylor Swift and Lionel Messi are so GOATED</p><p class="medium-feed-link"><a href="https://medium.com/data-science/expectedly-unexpected-the-mathematical-art-of-measuring-surprise-28c04f0e8a1a?source=rss-87144e3252f6------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/expectedly-unexpected-the-mathematical-art-of-measuring-surprise-28c04f0e8a1a?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c04f0e8a1a</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[thoughts-and-theory]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[music]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Tue, 01 Oct 2024 23:01:50 GMT</pubDate>
            <atom:updated>2024-10-01T23:32:20.998Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The statistical theory behind why your Instagram posts have so few likes]]></title>
            <link>https://medium.com/data-science/the-statistical-theory-behind-why-your-instagram-posts-have-so-few-likes-31f46d03448b?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f46d03448b</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[instagram]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[math]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 20:54:56 GMT</pubDate>
            <atom:updated>2023-12-28T20:55:17.632Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Statistical Theory Behind Why Your Instagram Posts Have So Few Likes</h3><h4><em>A handy trick to count uncountable things — from Instagram clout, to penguin population and Man City fans in North London</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0tzHsvM0UIzFK99xBBlEQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/stocksnap-894430/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2570925">StockSnap</a> from <a href="https://pixabay.com//?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2570925">Pixabay</a></figcaption></figure><p>We have all been there …</p><p>With hopeful eyes, we framed the Christmas spirit through our iPhone 15 lens, capturing the dinner table with an artist’s persistence and a poet’s soul, each photo a festive vignette brimming with friends, the shimmering glaze of the turkey, and the twinkle of ornaments. We meticulously pair every snapshot with an upbeat caption, carefully woven from the threads of our thoughts, hoping each post would jingle all the way through Instagram’s bustling holiday traffic.</p><p>And yet, for all the hard work to unveil our holiday spirit to the digital world, we receive a mere 15 likes on our Instagram posts (20 if you count the x-posts on Facebook)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvzO_dcLKuBjDqGwAr3ttQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/geralt-9301/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=6038943">Gerd Altmann</a> from <a href="https://pixabay.com//?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=6038943">Pixabay</a></figcaption></figure><p>Maybe it is unrealistic to expect a social media uproar if you have a mere 300 Instagram followers, but surely these heartfelt Christmas posts must compel more than 5% of our friends to react, right? The problem is, your total follower count is not the same as your “true audience size” — the number of connections that <em>are active </em>and see your posts. You may have many followers, but the majority may not be active, or they may have too dense a follow graph that your posts realistically never reach them.</p><p>Then the question is, how can you measure your true social media reach, your Internet clout?</p><h4>The Lincoln-Peterson index — or how to count uncountable things</h4><p>Let’s say you make an Instagram post on a private account of 300 followers and receive 40 likes. You know your audience is somewhere between 40 and 300. If you have supreme confidence in your ability to craft Instagram posts, you may suppose your reaction rate be 100%, your audience a mere 40 users and it was Instagram who squeeze your reach.</p><p>But maybe your photos don’t look too good, or maybe you are not as witty as you think. Maybe you did reach your full 300 followers but you can only get 5% of them to gingerly give you a virtual moral support. There’s no way to know with one post. But if you have <em>two</em> posts, you can get a good idea, even if you don’t know how compelling each individual posts are.</p><p>Let’s say your second post has 60 likes and there are 15 mutual likes (people who like both posts). We can naively calculate our true audience size using the good old Set Intersection theory, knowing that it is very conservative estimation, because we potentially neglect a population that doesn’t like either of the Instagram posts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9VHmdVhNGZK4MsbbCu_2JQ.png" /><figcaption>Image by author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*lnIqzzFho9CLTfchMQHBcg.png" /></figure><p>Fortunately, there is a neat method called the Lincoln Index that allows us to estimate the total audience. Let <strong><em>n1, n2 </em></strong>be the number of likes on the first and second post respectively, and <strong><em>m</em></strong> the number of people who like both:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*ZwTT-kXTB3SDZVeel1n2Pg.png" /></figure><p>Our estimated reach according to the Lincoln index is 40 x 60/15 = 160. Notice that it is a lot larger than the naive estimate of 85, which exonerates Instagram from squeezing our social clout.</p><h4>How does it work mathematically? — or the part where you should feel free to skip</h4><p>Let us re-frame the problem: we want to choose <strong><em>n2</em></strong> people to like the second post out of <strong><em>N </em></strong>people, where exactly <strong><em>m</em></strong> out of <strong><em>n2</em></strong> are among<strong><em> n1</em></strong> people who like the first post. It should be fairly straightforward that the probability to arrive at such choice is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*oYjHmOxUXuHTXJDH5ncvrw.png" /></figure><p>We can use the maximum likelihood method to find an estimate <strong><em>N</em></strong>. For the mathematically inclined, here is an outline of the proof:</p><ul><li>The trick is instead of trying to find <strong><em>N</em></strong> that maximizes the likelihood function:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*_PSA2ThXhFWoC5vook1Ueg.png" /></figure><ul><li>we find the largest 𝑁 that satisfies the inequality:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*eW4J2QQmlXVI_zjdhQvVVg.png" /></figure><ul><li>it should be obvious, after a bit of arithmetic juggling, that this is equivalent to:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*XUigSi-F1DfRPqVA0TGfpQ.png" /></figure><ul><li>And so the estimate <strong><em>N_hat</em></strong> that maximizes the likelihood function has values:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*1PFcexluVnI_ju9WLZ4isg.png" /></figure><h4>A simulation</h4><p>I know not everyone is a fan of mathematical proofs so I will try to convince you with a small simulation.</p><p>Let’s say we know our social media reach to be 100 and we have 2 Instagram posts with the probability of like <strong><em>p1</em></strong> and <strong><em>p2</em></strong>, respectively. We can simulate different scenarios of <strong><em>p1</em></strong> and <strong><em>p2</em></strong>, observe the number of likes on each posts, then reapply the naive Method and the Lincoln methods to see how far each of them are from arriving at the value of 100 (ground truth).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7da82de3d05a94e61bc21d369fdb937a/href">https://medium.com/media/7da82de3d05a94e61bc21d369fdb937a/href</a></iframe><p>We can see that at different values of <strong><em>p1</em></strong>,<strong><em> p2</em></strong>, the Lincoln estimates remain <strong><em>unbiased</em></strong> (the mean of the 10,000 simulations approximate the true population of 100), while the 95% confidence interval reduces as <strong><em>p1</em></strong>, <strong><em>p2</em></strong> approximate 1. This makes sense i.e. if we are confident that the like rate of our posts is close to 100%, we should be fairly confident about our audience size estimate. The naive estimate, unfortunately, underestimates our social reach by a lot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3gjEeOYhyocErjZmvPt8g.png" /><figcaption>Image by author</figcaption></figure><h4><strong>As usual, all good statistics come with some caveats:</strong></h4><ul><li>(1) We assume that between each post, the true audience size does not change. This may be true for a casual Instagram user, but probably unrealistic if you are an influencer with an ever increasing fan base.</li><li>(2) We also assume there are overlapping mutual likes between the two posts. Some of our readers may have found a small cheat in my code:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb8f8f93cf5e6efe90907b92ee941267/href">https://medium.com/media/fb8f8f93cf5e6efe90907b92ee941267/href</a></iframe><p>While the mathematics remain valid, the estimate becomes fairly rough and biased at smaller sample size. Luckily, we have a neat modification, called the Chapman estimate, to address this issue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*4Kc8CF7X9zluNPmhebdFiA.png" /></figure><p>So what is this counting method useful for? This statistical technique— estimating any population size where is impractical to count every individual is very popular in ecology, under a commonly known name <strong>mark-recapture method.</strong> It is also common to see this method in action in Tech companies, where we want to estimate the amount of bugs in a video game before release, or the amount of policy-violated contents in a social media platform.</p><p>I was once challenged in an interview to estimate the number of Man City fans in London. It would have been a fun weekend activity to do some sampling in Trafalgar Square, interviewing people and crunching numbers according to the Lincoln estimate. Although I suspect that the City fans are so few you may actually be able to just count them all!</p><p>If you enjoy this article, you may also enjoy my other article about interesting statistical facts and rules of thumbs</p><ul><li><a href="https://medium.com/towards-data-science/disney-movies-were-right-we-are-all-special-and-statistically-so-3bb56e79ab71">Disney Movies were right — We are all special, and Statistically so</a></li><li><a href="https://towardsdatascience.com/a-statistical-rule-to-optimize-your-life-the-lindys-effect-96d2c75b080d">A statistical rule to optimize your life: the Lindy’s Effect</a></li><li><a href="https://towardsdatascience.com/the-rule-of-three-calculating-the-probability-of-events-that-have-not-yet-occurred-106144dc2c39">Rules of Three: Calculating the probability of events that have not yet occurred</a></li></ul><p>For other deep dive analyses:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian Statistics convince me to hit the gym?</a></li><li><a href="https://towardsdatascience.com/making-big-bucks-with-a-data-driven-sports-betting-strategy-6c21a6869171">Making big bucks with a data-driven sport betting strategy</a></li><li><a href="https://towardsdatascience.com/love-in-the-time-of-pandemic-a-probabilistic-approach-to-dating-ba888880cd12">Love in the time of Pandemic: A Probabilistic approach to Dating</a></li></ul><p>The entire code for this project (simulation and graph) can be found in my <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/Python/lincoln_estimate.py">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31f46d03448b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-statistical-theory-behind-why-your-instagram-posts-have-so-few-likes-31f46d03448b">The statistical theory behind why your Instagram posts have so few likes</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Love in the time of Pandemic: A Probabilistic approach to dating]]></title>
            <link>https://medium.com/data-science/love-in-the-time-of-pandemic-a-probabilistic-approach-to-dating-ba888880cd12?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba888880cd12</guid>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[love]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Sat, 12 Feb 2022 05:38:41 GMT</pubDate>
            <atom:updated>2022-02-12T16:20:09.193Z</atom:updated>
            <content:encoded><![CDATA[<h3>Love in the Time of Pandemic: A Probabilistic Approach to Dating</h3><h4><em>Dating is hard — but maybe Probability Theory can make it slightly easier this cuffing season</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7d0rgh6N7kAqrVxwKnRvxQ.jpeg" /><figcaption>Image from Pixabay (dimitrisvetsikas1969)</figcaption></figure><p>Back in 2019, I wrote an article about Optimal Stopping theory and its application to dating.</p><p><a href="https://towardsdatascience.com/probability-theory-and-the-optimal-dating-strategy-for-2018-2b75b26fb0b">Finding the optimal dating strategy for 2019 with probability theory</a></p><p>The lesson was simple for the hopeful romantic: to maximize your chance of finding the best match, you should <em>get to know but not commit yourself to any of the first</em> 37% of the people (you think) you will meet, and then immediately settle for the <strong>first person who’s better than the ones you saw before. </strong>Doing this will guarantee a 37% chance for you to find the <em>Mathematically Destined One.</em></p><p>It has been 3 years since then and it was enough time for me to learn that reality is nothing like these mathematical formulae.</p><blockquote>However, reality is harsh.</blockquote><p>I graduated from college and moved to a new city for work. And let me tell you, even at the age when everything seems complain-worthy, from the long waits at Blue Bottle to the non-existence of public transportation in the SF Bay Area and the exorbitant price I pay for my tiny 1-bedroom, <em>the lack of time and opportunity to date</em> is still at the top of my gripes.</p><p>And then the pandemic hit and abruptly changed the definition of romance, from intimate experiences with dinner, a few drinks in a crowded bar or a goodnight kisses to awkward Zoom call, mask-wearing and the threat of catching a deadly disease. It’s virtually impossible to date a person, let alone 10 or 37.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4gqcmMhYRlfN5eg_W7JdA.jpeg" /><figcaption>Image from Pixabay (StockSnap)</figcaption></figure><p>And don’t even get me started on how hyper-competitive the dating market is in San Francisco or New York City. Even if (you think) you have found that significant other, chances are that the person is not available or does not reciprocate your feelings.</p><blockquote>So the Math seems way out of touch with reality, what now?</blockquote><p>We follow what good scientists would do: we acknowledge the shortcomings of our model, relax a few assumptions and come up with the new algorithm to better reflect this reality.</p><h3>1. Finding the Many Ones — a top k approach</h3><p>One way to make dating a tiny little bit easier for us is to ask ourselves: is the best match really that different from the “second best” or “third best”? After all, we are probably so infatuated by love that committing to a serious relationship with any of the top 3 or top 5 candidates will likely make very little difference to our lifetime utility.</p><p>So, let’s say, instead of finding the best match among 100 people, we set out to find the top <strong>k</strong> love candidates. We use the same approach: at first, we explore our compatibility with the first <strong><em>r</em></strong> candidates and make a mental note on the maximum score observed among them. Let’s call this threshold <strong><em>t</em></strong>. We then select each candidate from the interval <em>{r + 1, …, n}</em> with score higher than <strong><em>t</em></strong> until we select <strong><em>k</em></strong> persons or we run out of candidates.</p><h4><strong>A simulation:</strong></h4><p>Let us also start with running a simulation to build up some intuition around the optimal value of <strong><em>r. </em></strong>The setup is fairly simple with the following Python code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/422ae0d6c3733a89b77ff4c1c66f3b90/href">https://medium.com/media/422ae0d6c3733a89b77ff4c1c66f3b90/href</a></iframe><p>Let us visualize the result when <strong>n = 100</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B4ifyctZ-oFT5GMkYSQj2w.png" /><figcaption>Graph created by author</figcaption></figure><p>We can see that <strong><em>k = 1 </em></strong>turns this into the classic problem where we only pick the best person. The ideal <em>exploration phase</em> will thus last for around 36–37 people. Interestingly, we have to conclude our exploration phase a lot sooner to only around 23 or 24 people when we want to choose the top 3 candidates, and to 9 people when we want to cast our net wide for the top 10 candidates.</p><p>You may ask, the probability of success actually decreases as we increase the number of top partners we want to pick (around 15% when k= 3 and 4% when k = 10), so is it actually worse than our original strategy, where we are guaranteed a success rate of 37%?</p><ul><li>That is true, but the catch is, the original magic number <strong>37 </strong>only guarantees that you will find the best one, but it says nothing about their availability. It’s true that as <em>k</em> increases, the probability of successfully choosing top <em>k</em> partners decreases, but the chance that <em>at least one of them </em>accept is significantly higher. After all, in love, it is only one that counts.</li></ul><h4><em>How does the Math actually work?</em></h4><p>We can also run some math to find <strong><em>r</em></strong>.</p><p>Let <strong>S(n, k, r) </strong>be the event that we succeed, that is, we find the top <strong><em>k</em></strong> candidates with <strong><em>n</em></strong> by using our algorithm on the first <strong><em>r</em></strong> observations. We want to maximize the probability of success i.e. <strong>P(S(n, k, r))</strong>.</p><p>To do this, we have to use a small trick: we break down <strong>P(S(n, k, r))</strong> into the sum of small components <strong>P(S(n, k, r, i))</strong>, where <strong>S(n, k, r, i)</strong> is the event that we succeed with <strong><em>i</em> </strong>being the last selected candidate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q3sTZ5yR-LpZA5fLZXE4hA.png" /></figure><p>To break <strong>P(S(n, k, r, i)) </strong>even further, notice that for <strong><em>i </em></strong>to be the last selected candidates:</p><ul><li>It has to be one of the top <strong><em>k</em></strong> candidates, with probability <strong><em>k/n</em></strong></li><li>We were able to pick <strong><em>k-1 </em></strong>candidates among <strong><em>i-r-1 </em></strong>candidates:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-pgP-GDVHnH-0V4wbsDbg.png" /></figure><ul><li>One of the first <strong><em>r</em></strong> people is the best among the first <strong><em>i-1</em></strong> people, with probability <strong><em>r/(i-1)</em></strong></li></ul><p>Our equation becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQ6ZHOYQlOvjTDDIOxX9nQ.png" /></figure><p>Analytically finding <strong><em>r </em></strong>to maximize this equation is extremely complicated and beyond the scope of this post. But, if you trust me, then as <strong><em>n → ∞</em></strong>, the optimal <strong><em>r</em></strong> approaches:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*WL9jShIO4-Ohy6xW8HwwBw.png" /></figure><p>And if you need some convincing, this is what the r_best looks like between our simulated and theoretical results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*8SPUcZniAGkV7YhL6nBt5Q.png" /><figcaption>Graph created by author</figcaption></figure><h3>2. Handling rejection — when you are not The One for the other</h3><p>Let’s say that we are still committed to finding the best person, and that person only, but we realize that there is a (pretty high) chance that the person is not available, e.g., they may not be attracted to you, they are already in a relationship, or … you happen to be in their exploration phase.</p><p>So let us tweak the problem a little bit and allows the candidate the right to refuse our offer of love. We assume that if given our proposal, any candidate will reciprocate our feelings with the same probability <strong><em>p</em></strong>, independent of their rank and the disposition of other people we interact with. This is obviously naive, but the assumption will do for now.</p><p>The math is extremely messy so I will save you from it. Basically, in this case, the strategy is also to explore <strong><em>r </em></strong>candidates first, where <strong><em>r = p^(1/(1-p))</em></strong>. For example, if we think the acceptance rate to be 0.5, then we should explore r = 0.5^(1/0.5) = 25% of our candidates and <em>stop with the first available applicant who is better than those preceding them.</em></p><p>You can see that in the simulation below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5i8rwGOCjjgM0_PNYu_lOw.png" /><figcaption>Graph created by author</figcaption></figure><p>Depending on your success projection, you may be able to explore more or fewer candidates. At 25% successful rate, you can only explore around 15 candidates. If you live in the Bay Area where I think (I have no data to back my claim) the availability rate is much less than 10%, then you can only afford exploring 7 candidates. That is, quite a grim outlook.</p><h3>Beyond Love and Dating:</h3><p>At this point, you probably can tell that even with these revised assumptions, it’s impossible for us to capture the complexity of human interaction that goes into love and dating.</p><p>However, this does not mean that what everything you have read so far is just fun and games. What you have been introduced so far is the very backbone of <strong>Optimal Stopping Theory, </strong>where we need to choose a time to take a given action based on sequentially observed random variables in order to maximize an expected payoff. In fact, you can basically swap “finding a partner” with “hiring a data scientist,” “finding a person to sell my house to” or “option trading” and the math would be the same. In particular, the <strong><em>top k</em></strong> problem you have seen is a well-known ML-system problem called <strong><em>Online Data sampling</em></strong>, where you need to perform online data selection and sampling from a stream of data without revision.</p><p>But then again, none of them is as fun as dating, isn’t it?</p><p>If you enjoy this article, you may also enjoy my other article in a series about interesting statistical facts and rules of thumbs</p><ul><li><a href="https://towardsdatascience.com/disney-movies-were-right-we-are-all-special-and-statistically-so-3bb56e79ab71">Disney Movies Were Right — We Are All Special, and Statistically So</a></li><li><a href="https://towardsdatascience.com/a-statistical-rule-to-optimize-your-life-the-lindys-effect-96d2c75b080d">A statistical rule to optimize your life: the Lindy’s Effect</a></li></ul><p>For other deep dive analyses:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian Statistics convince me to hit the gym?</a></li><li><a href="https://towardsdatascience.com/making-big-bucks-with-a-data-driven-sports-betting-strategy-6c21a6869171">Making big bucks with a data-driven sport betting strategy</a></li></ul><p>You can find all the codes to my article at my Github <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/Python/optimal_dating.py">link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba888880cd12" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/love-in-the-time-of-pandemic-a-probabilistic-approach-to-dating-ba888880cd12">Love in the time of Pandemic: A Probabilistic approach to dating</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Disney Movies were right — we are all special, and statistically so]]></title>
            <link>https://medium.com/data-science/disney-movies-were-right-we-are-all-special-and-statistically-so-3bb56e79ab71?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bb56e79ab71</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[humanity]]></category>
            <category><![CDATA[disney]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Tue, 18 Jan 2022 21:25:18 GMT</pubDate>
            <atom:updated>2022-02-12T16:23:26.065Z</atom:updated>
            <content:encoded><![CDATA[<h3>Disney Movies Were Right — We Are All Special, and Statistically So</h3><h4><em>A little bit of Statistical Theory will convince you that the idea of “the average Joe” is really just a big myth</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eaokZ_qf8MCHMW7bqBfMvg.jpeg" /><figcaption>Photo by StockSnap from <a href="https://pixabay.com/photos/disney-land-castle-night-dark-2584304/">PixaBay</a></figcaption></figure><p>I love Disney movies !!!</p><p>Besides all magical kingdoms and thrilling adventures, mystery and romance, the one thing Disney Movies are so good at is convincing me that, after all, I am special.</p><p>Nowadays, we live by comparisons to others. We want to live an exciting life, to be more than just an “average Joe” or “Jane,” and if you work in tech, to be that 10x engineer friend who make millions from a start-up exit and afford a vacation home in Tahoe. So among all the movies constantly reminding us of how insignificant we are in the monotonous capitalistic rat race, there is a deep sense of comfort on a Sunday evening when we rewatch movies like Toy Stories or Camp Rock. Isn’t it great to see Woody or Mitchell (Demi Lovato), through a series of uplifting songs, recognizing that they are special who they are, and they deserve as much love and attention just for being themselves? Then Monday hits and you tell yourself as you are brought back to the reality of the rat race: “That was fun, but it was movie after all.”</p><p>But, what if I tell you that, statistically, these movies are right, that it’s almost impossible for us to be “normal,” and “average”, and that each of us is really special who we are?</p><h3><strong>The misleading nature of the Normal Distribution</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlbyXgfzYZWrigQpEK34nA.png" /><figcaption>A standard normal distribution. Each of the pairs of red, black and yellow line shows the 1, 2 and 3 standard deviation difference from the mean. Image by author.</figcaption></figure><p>Most of us are familiar with the Normal distribution and the famous 68–95–99.7 rule, that is, 68%, 95%, and 99.7% of the population will lie within 1, 2 and 3 standard deviation from the mean. <em>In other words, almost all observed data is extremely close to the mean value.</em></p><p>A popular example is height. The heights of adult men in America (&gt;20 years old) are empirically normally distributed, with a mean of 5&#39;7’” and a standard deviation of 3 inches. So it shouldn’t surprised you to see most people around you is between 5&#39;2&quot; and 6&#39;2&#39;’(2 std from the mean).</p><p>This would make you think: by the same logic, it should also applies to other attributes like weight, talents, education level, etc. right? It seems quite likely for any of us, including myself, to be average in everything, with really nothing special to show.</p><p><strong><em>Well, there’s one thing you forgot to factor in: dimensionality.</em></strong></p><h3>The “blessing” of dimensionality</h3><p>Let’s revisit the problem but in mathematical terms: suppose each person’s has <em>n </em>factor, each of which is represented by an independent, standard normal random variable. That is, each person’ attribute vector has the form (<em>x</em>1, <em>x</em>2, <em>x</em>2, …, <em>xn</em>) where each <em>xi </em>i.i.d Normal with mean 0 and variance 1. The expected value of each factor is 0, so you might expect that most points are piled up near the origin (0, 0, 0, …, 0), right?</p><p>One way to see how <em>far</em> we are from the average (0, 0, 0, …, 0) is to look at the Euclidean norm. I used the squared Euclidean norm for computational simplicity but the idea is the same. Particularly, we want to find the distribution of this distance, P(d²) and see where the distribution mass is maximized or where most of the points are located.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*QLhrOOhrxIRdBhwZeunUxg.png" /></figure><p>Since d² comes from a sum of square of <em>n-</em>i.i.d<em> </em>standard normal distribution, d² follows a Chi-squared distribution with <em>n</em> degrees of freedom. To study the behavior of the <em>n</em>-degree of freedom Chi-squared distribution, we can approximate it by a Normal distribution with mean <em>n </em>and variance <em>2n</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*IoFrlUQm0S4cxjK2WuaMIQ.png" /></figure><p>Since it is hard to think about how d² behaves especially when n increases, we can also change our variable and look at <strong><em>d²/n</em></strong>. Intuitively, we can think of multiple spheres with different radius value surrounding the origin. We particularly care about the spheres with radius <em>n,</em> and we want to see how the points are distributed, relative to this <em>n</em>-radius fictional spheres. It is easy to see find the distribution for <strong><em>d²/n </em></strong>as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*VUIPasZr8JsP-_VD0n3Jdw.png" /></figure><p>Since <strong><em>d²/n </em></strong>follows a Normal distribution, we can also apply the 68–95–99.7 rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*QhJj9E1Z1q5Zhfbli1jrKA.png" /></figure><p>This means that 95% of the points lies just between [1–2 * σ, 1+2*σ] from the imaginary sphere of radius <em>n</em> we mentioned earlier. As <em>n</em> increases, this spaces gets smaller and smaller i.e. the points lie much closer to the sphere. When <em>n</em> → ∞, all the points lie on the imaginary sphere.</p><p>This is surprising, because initially, we thought most of the points will be close to the origin. In fact, most of them are <em>n-distanced </em>away from the origin, in a <em>n-dimensional </em>soap bubble with radius <em>n</em>.</p><blockquote>Initially, we thought most of the points will be close to the origin. In fact, most of them are <em>n-distanced </em>away from the origin, in a <em>n-dimensional </em>soap bubble with radius <em>n</em>.</blockquote><h3>A simulation</h3><p>I know not everyone is a fan of mathematical proofs so I will try to convince you with a small simulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_2roWv9F7mRPen0h2jIxjg.png" /><figcaption>Image by author</figcaption></figure><p>For different values of <em>n</em>, we sample a large amount of “people” — where each person comes from a <em>n-</em>dimensional Normal distribution. We then calculate the <em>distance</em> (squared Euclidian norm) from each person to the “average Joe” or the origin. The graph here shows the distribution of distance when <em>n = 100.</em></p><p>The two red lines shows 2 standard deviation away from the mean and where where 95% of the points exist. In the graph below, we see that as n → ∞, the ratio between the boundaries and <em>n </em>approaches 1, suggesting most points lie in a very small area n-distance away from the origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4gPpnCBuXxJ7QfYfBK-oA.png" /><figcaption>Image by author</figcaption></figure><p>Another way to look at this is shown on the right graph: by the time we reach 2000 dimensions, nearly all of the vectors sampled from the distribution have a magnitude near 1, and virtually no points are close to the origin.</p><h3>Some caveats:</h3><p>So I hope I have convinced you that: somebody exists who is more or less the average height, or weight. But <em>if there are 100 or more roughly independently varying criteria to measure people by, then probably nobody exists who is average in every way; there are too many ways to be different.</em></p><p>However, this analysis relies on the assumption of independence. We need to come up with a lot of independent factors to convince ourselves that we are special. That is not necessarily the case for most of the common attributes, e.g. height and weight can be correlated through genetics, your ability to do various sports correlate through your physique, etc.</p><p>But, at least for now, whenever you saw another cheesy Disney movie that tell you to believe in special self, at least you know there is some statistical backing to that claim.</p><p>If you enjoy this article, you may also enjoy my other article in a series about interesting statistical facts and rules of thumbs</p><ul><li><a href="https://towardsdatascience.com/a-statistical-rule-to-optimize-your-life-the-lindys-effect-96d2c75b080d">A statistical rule to optimize your life: the Lindy’s Effect</a></li><li><a href="https://towardsdatascience.com/the-rule-of-three-calculating-the-probability-of-events-that-have-not-yet-occurred-106144dc2c39">Rules of Three: Calculating the probability of events that have not yet occurred</a></li></ul><p>For other deep dive analyses:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian Statistics convince me to hit the gym?</a></li><li><a href="https://towardsdatascience.com/making-big-bucks-with-a-data-driven-sports-betting-strategy-6c21a6869171">Making big bucks with a data-driven sport betting strategy</a></li><li><a href="https://towardsdatascience.com/love-in-the-time-of-pandemic-a-probabilistic-approach-to-dating-ba888880cd12">Love in the time of Pandemic: A Probabilistic approach to Dating</a></li></ul><p>The entire code for this project (simulation and graph) can be found in my <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/Python/n_dimensionalNormal.py">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bb56e79ab71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/disney-movies-were-right-we-are-all-special-and-statistically-so-3bb56e79ab71">Disney Movies were right — we are all special, and statistically so</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A statistical rule to optimize your life: the Lindy’s Effect]]></title>
            <link>https://medium.com/data-science/a-statistical-rule-to-optimize-your-life-the-lindys-effect-96d2c75b080d?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/96d2c75b080d</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Thu, 21 Jan 2021 20:10:27 GMT</pubDate>
            <atom:updated>2022-01-20T13:49:26.514Z</atom:updated>
            <content:encoded><![CDATA[<h4>In a world of too much information, how do you tell the signals from the noises?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yY3Fdrn68ooXww9NE1JuQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@thoughtcatalog?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Thought Catalog</a> on <a href="https://unsplash.com/s/photos/laptop-book?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Sometimes, I wake up and feel anxious to open my phone. Scrolling through all the social media news feed, glancing at the New York Times app, hoping around some Youtube new uploads, takes <strong><em>a lot of time</em></strong>.</p><p>The flood of information that swamps me daily produces more pain than gain. Every iota of information has been so well-optimized at ‘looking urgent/important’ that we have to constantly making choices in terms of what to process, knowing that little (if none) of them will remain relevant in the next 24 hours?</p><p>What if there existed a rule to identify what type of news or information that will still be relevant for a long time to come?</p><p>What if there was a guide you could use to filter the knowledge worth knowing from the rest of the noise?</p><p>There is — it’s called the <strong>Lindy Effect</strong>.</p><h4><strong>Lindy’s effect — or the value of Time as a judge of quality</strong></h4><p>The Lindy’s effect is an observation that:</p><blockquote><strong><em>The longer an artifact has been around, the longer it’s likely to stay around.</em></strong></blockquote><p>Nassim Nicholas Taleb, in his book, <a href="https://www.amazon.com/dp/B0083DJWGO/ref=dp-kindle-redirect?_encoding=UTF8&amp;btkr=1"><em>Antifragile</em></a><em>, </em>explains the concept quite cleanly: <em>“If a book has been in print for forty years, I can expect it to be in print for another forty years. But,[…], if it survives another decade, then it will be expected to be in print another fifty years.”</em></p><p>The idea is, the future life expectancy of some non-perishable things like a book/technology/intellectual production <em>is proportional to</em> their current age; every additional period of survival implies a longer remaining life expectancy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gS7EKviLVbPujUWZTTWyA.png" /></figure><h4>A mathematical motivation:</h4><p>The Lindy’s effect starts with an idea that the lifetimes of some intellectual artifacts follow a <strong>Pareto distribution: </strong>a skewed distribution with heavy, “slowly decaying” tails (i.e. much of the data is in the tails).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*HZl3de1VYma_-run5s21sQ.png" /><figcaption>An example of a Pareto graph. To the left are the few that dominate, to the right is a long tail that contains much of the data. Image from Wikipedia — under Public Domain.</figcaption></figure><p>You may have heard of the Pareto distribution as the famous 80/20 rule: there are a few items that are very common and contribute a lot to the “head” of the distribution e.g. 20% of the top-earners account for 80% of the national wealth; the top football teams represent a small fraction in the English leagues, yet they account for the bulk of TV royalties.</p><p>Modeling the lifetime of artifacts by the Pareto distribution means most items will last only for a short period of time, but there is a long tail of items that could last substantially longer. Lots of economic research has verified this property among intellectual artifacts.</p><p>We can write the probability distribution function of lifetime — PDF(t) of such an artifact under the Pareto form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*6LO1prvhltPJgboIbJyjaw.png" /></figure><p>where <strong><em>t_m </em></strong>(the scale parameter)<strong><em> </em></strong>is the minimum possible value of <strong>t</strong>, and <strong><em>α</em></strong> is the shape parameter, also known as the tail index. Notice that <strong><em>t_m</em></strong> is necessarily positive i.e. the lifetime of an artifact has to be &gt; 0.</p><p>Now, we want to find the expected lifetime <strong><em>E(t)</em></strong>, conditional on it having lasted a period of time <strong><em>t_0</em></strong>. In other words, we want to find <strong><em>E(t|t&gt;t_0).</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*KmBYK8eY46wTHitvqNHW3w.png" /></figure><p>and so the expected additional life after <strong>t_0</strong>, or <strong><em>E (t-t_0|t&gt;t_0) </em></strong>is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*CE8bdnix9_ZjFLgAezzq6A.png" /></figure><p>While the math can look intimidating, the result is surprisingly clean. The conditional expected additional lifetime is simply the time that has passed (<strong><em>t_0</em></strong>) multiplied by a proportionality constant <strong><em>1/(α-1)</em></strong>.</p><ul><li>The closer <strong><em>α</em></strong> is to 1, the larger the proportionality constant, and the larger expected additional lifetime we can hope for our artifact. If <strong><em>α</em></strong> = 2, the proportionality constant is 1. That is, <strong><em>the expected additional life equals the life seen so far.</em></strong></li><li>For example, when <strong><em>α</em></strong> = 2, once t_0 is reached, we expected the future lifetime is also t_0; if that point is reached making the total lifetime so far 2t_0, then the new expected future lifetime is 2t_0; and so on.</li></ul><h4>A simulation</h4><p>I know not everyone is a fan of mathematical proofs so I will try to convince you with a small simulation.</p><p>Let’s assume that 2021 is a 20th anniversary of your favorite book and you want see how many additional years the book have before completely falling into oblivion.</p><p>What we will do is to simulate many, many scenario of lifetime from <strong><em>P(t-t_0|t&gt;20, α) </em></strong>for different values of<strong><em> α, </em></strong>and see how the distributions behave<strong><em>.</em></strong></p><p><em>Now, actually performing this simulation requires a technique called Inverse Random Sampling. Its details are beyond the scope of this post, but if you are interested, I wrote </em><a href="https://github.com/tuangauss/DataScienceProjects/blob/master/R/lindy/Inverse_Random_Sampling.pdf"><em>a small note</em></a><em> explaining the technique .</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075321782def9e9172402ba3226e3e2c/href">https://medium.com/media/075321782def9e9172402ba3226e3e2c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*K1iHi7XUopuTHHef0tMx8A.png" /></figure><p>You can see that as <strong><em>α</em></strong> increases in value, the conditional distribution becomes “heavier” around the head, thus resulting in a smaller conditional expectation of additional years remaining. A book that has been in print for 20 years is expected to last another 40 years if <strong>α=1.5</strong>, 20 if if <strong>α=2</strong>, and 10 if <strong>α=3</strong>.</p><p>One interesting result is to compare how the conditional expectation of remaining years differ between a Lindy’s good and a human life.</p><p>With some quick research, I found that <a href="https://www.indium.com/blog/can-your-mortality-be-modelled-with-the-weibull-distribution.php#:~:text=It%20is%20interesting%20(and%20perhaps,little%20low%20at%2072%20years">US males lifetime distribution </a>follows a Weibull distribution with a mean expectancy of 70. Given this information, we can then do some simulation to see what the conditional probability of remaining lifetime after one has celebrated their 20th birthday:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Po8BMCZBiw_Qyrgzo21QnA.png" /><figcaption>Left: conditional probability distribution function of Lindy’s good (Pareto with <em>α = 2)</em><strong><em> </em></strong><em>and Human (Weibull with mean = 70) after the first 20 years have passed — the dashed lines represent the values of the mean of the respective distributions. Right: the expected remaining years as a function of the years that have passed.</em></figcaption></figure><p>What we learn is technologies have different survival patterns than people.</p><ul><li>Given the first 20 years, the expected remaining year for a Lindy’s good is 20, while we do expect an average US male to live for another 50 years (which adds up to the expectancy of 70).</li><li>However, the older a person is, the fewer expected years he has left. That is because human lifetimes follow thin-tailed distributions — much thinner than the Pareto distribution’s tail. The Pareto distribution’s heavy tail is the reason why the longer a technology has survived, the longer we can expect it continue surviving. In Taleb’s words, technology <strong><em>“ages in reverse.”</em></strong></li></ul><h4><strong><em>Applying Lindy’s effect to optimize your life:</em></strong></h4><p>In essence, Lindy’s effect teaches us a simple principle: if you cannot decide, then <strong>let time be the natural filter for contents</strong>:</p><ul><li>I have uninstalled all the news app from my phone, while subscribing to weekly recap newsletters. If an event is important and newsworthy, then it should remain so beyond the first 24 hours.</li><li>Books: not knowing which books to choose between all presented in Bill Gates’ reading notes or NPR’s Book Concierge? Read the Classics. The Bible, Machiavelli’s The Prince, Marcus Aurelius’s Meditations, the insights of these books have tested against changing time and they most likely outlive most of this year’s NYT’s bestsellers.</li><li>ML algorithms: Linear regression via least squared estimation, invented by Gauss in the 1800s, is still by far the most popular Machine Learning techniques among data scientists, according to a 2016 <a href="https://www.kdnuggets.com/2016/09/poll-algorithms-used-data-scientists.html">Kdnuggets survey</a>. If I have to place a bet between least squared linear regression and deep neural nets and choose which algorithm to still be used in the year 2200+, my bet is definitely with the former.</li></ul><h4>Some caveats:</h4><p>As we have seen, Lindy’s effect is very neat probability statement. But they are exactly that, probability statement, and you shouldn’t take it too seriously:</p><ul><li>We don’t know for sure which item exhibits Lindy’s effect. The condition for it is rather strict. Not everything follows Pareto distribution: human lifetime certainly does not, neither does atomic decay. On top of that, even if an artifact’s lifetime is distributed in a Pareto manner, we have seen that there’s a big difference in additional lifetime expectation if we just move the shape parameter a little bit.</li><li>Note that I computed <strong><em>E(t|t&gt;t_0)</em></strong>, i.e. it only conditions on knowing that <strong><em>t&gt;t_0</em></strong>. If you have additional information, such as evidence that a technology is in decline, then you need to condition on that information.</li></ul><p>The Lindy Effect is thus a trivial heuristics, the usefulness of which decreases as you acquire additional relevant information.</p><p>But you know, to filter books and news to read, maybe trivial heuristics is good enough.</p><p>If you enjoy this article, you may also enjoy my other article in a new series about interesting statistical facts and rules of thumbs</p><ul><li><a href="https://towardsdatascience.com/disney-movies-were-right-we-are-all-special-and-statistically-so-3bb56e79ab71">Disney Movies Were Right — We Are All Special, and Statistically So</a></li><li><a href="https://towardsdatascience.com/the-rule-of-three-calculating-the-probability-of-events-that-have-not-yet-occurred-106144dc2c39">Rules of Three: Calculating the probability of events that have not yet occurred</a></li></ul><p>For other deep dive analyses:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian Statistics convince me to hit the gym?</a></li><li><a href="https://towardsdatascience.com/making-big-bucks-with-a-data-driven-sports-betting-strategy-6c21a6869171">Making big bucks with a data-driven sport betting strategy</a></li><li><a href="https://towardsdatascience.com/a-bayesian-quest-to-find-god-b30934972473">A Bayesian quest to find God</a></li></ul><p>The entire code for this project can be found in my <a href="https://github.com/tuangauss/DataScienceProjects/tree/master/R/lindy">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96d2c75b080d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-statistical-rule-to-optimize-your-life-the-lindys-effect-96d2c75b080d">A statistical rule to optimize your life: the Lindy’s Effect</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building your own book recommendation engine in Python]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/building-my-own-2021-book-recommendation-engine-903ea10d5021?source=rss-87144e3252f6------2"><img src="https://cdn-images-1.medium.com/max/2600/1*wh6Vk8VUsbJUuZNodmOblw.jpeg" width="3712"></a></p><p class="medium-feed-snippet">A comprehensive, no-nonsense guide to Collaborative Filtering and all the cool acronyms MF, SGD, ALS.</p><p class="medium-feed-link"><a href="https://medium.com/data-science/building-my-own-2021-book-recommendation-engine-903ea10d5021?source=rss-87144e3252f6------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/building-my-own-2021-book-recommendation-engine-903ea10d5021?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/903ea10d5021</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[books]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Wed, 30 Dec 2020 14:16:10 GMT</pubDate>
            <atom:updated>2020-12-31T00:05:47.157Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[The Rule of Three: calculating the probability of events that have not yet occurred]]></title>
            <link>https://medium.com/data-science/the-rule-of-three-calculating-the-probability-of-events-that-have-not-yet-occurred-106144dc2c39?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/106144dc2c39</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[voting]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 02:19:45 GMT</pubDate>
            <atom:updated>2020-12-04T18:09:06.582Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsdatascience.com/tagged/hands-on-tutorials">Hands-on Tutorials</a></h4><h4>How confident are we that blue states California, New York, etc. do not turn red in the next election?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gRw3ZEXSqAMj8viFYX8Bg.jpeg" /><figcaption>Former President Barack Obama’s second inaugural address (2013). Photo by <a href="https://unsplash.com/@dyanawingso?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Dyana Wing So</a> on <a href="https://unsplash.com/s/photos/democrat?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><em>Author’s note</em>: I’m experimenting with a shorter form of articles, which aims to introduce interesting statistical facts and rules of thumbs. Let me know how you like them. For more in-depth analysis:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian Statistics convince me to hit the gym?</a></li><li><a href="https://towardsdatascience.com/making-big-bucks-with-a-data-driven-sports-betting-strategy-6c21a6869171">Making big bucks with a data-driven sport betting strategy</a></li><li><a href="https://towardsdatascience.com/a-bayesian-quest-to-find-god-b30934972473">A Bayesian quest to find God</a></li></ul><p>Another election cycle, another time we are bewildered by the overall results. There was no blowout for any side. The election was a nail biter. Both Democrats and Republicans made unexpected inroads in several races.</p><p>Facing the rising uncertainty each election cycles, a friend of mine acclaimed:</p><blockquote>The one thing we know for sure is that California has never, and will never turn Red.</blockquote><p>Well, for one, it is historically incorrect — California had been consistently voting Red before the ’92 election¹. My friend would have to qualify his observation to “elections that he observed [since 1992]”, or if he changed the place to District of Columbia. However, he will still be less confident about his projection if he knew that even in this election, a third of the 10 million votes in California was casted for President Trump². Just because we [seemingly] observe a place to be a Democratic stronghold does not mean that it cannot turn Red in the future and vice versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HcYgcqvujDAYL1mcEs-sKA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@claybanks?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Clay Banks</a> on <a href="https://unsplash.com/s/photos/vote?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The type of projections my friend made is a very common mental induction that we all exercise on a daily basis. Just as airplanes should not crash, wisdom teeth removal should not cause nerve damage and a reigning Premier League champion should not be upset by a team wallowing in the fifth tier of English football. In reality, however, these things do happen. Just because I have not ran into any accidents on a motorbike for the last 10 years does not mean the risk of accident is 0.</p><p>The question is: <strong><em>can we quantify the probability of something that has yet to occur?</em></strong> Ideally, we would want to assign a probability to the rare event, but the numerators for these events are 0, and our hands are tied. A convenient way to quantify the amount of risk in these cases is called the <strong>Rule of Three</strong>:</p><blockquote><em>If a certain event did not occur in a sample with n subjects, the interval </em><strong><em>from 0 to 3/n</em></strong><em> is a 95% confidence interval for the rate of occurrences in the population.</em></blockquote><p>One thing to note here is that the smaller the sample observed, the wider the confidence interval, meaning the upper limit of a confidence interval from a small sample is greater than that from a large sample. But it would be wrong to say that the true probability of an adverse event occurring is larger in a small series.</p><h3><strong>How does it work?</strong></h3><p>The proof of this rule is quite simple, denoting the number of events by <em>X</em> and the probability that we observe an adverse event by <em>p</em> (<em>p</em> is close to 0), we want to find the values of the parameter <em>p</em> of a binomial distribution of <em>n</em> observation that give Pr(<em>X</em> = 0) ≤ 0.05.</p><p>And so we need to solve for <em>p</em> such that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Q90VNucSeu9nyZ0H3dGV4g.png" /></figure><p>Then we can approximate the entity ln(1-<em>p</em>) by using the Maclaurin series, which is the evaluation of the Taylor expansion of function <em>f(x)</em> at <em>a =</em> 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*qyk1EICJrZbYWJkTXeONKQ.png" /></figure><p>Applying this to ln(1-<em>p</em>), we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*RI6o3lZQbcL-bC-rYhbhFQ.png" /></figure><p>Thus, we have <em>-np</em> ≤ -2.996 or <em>p</em> ≤ 3/<em>n</em>.</p><p><strong>A quick simulation:</strong></p><p>While the math is clear and simple, to demonstrate that it actually works, we can try to run a simple simulation:</p><ul><li>Imagine us testing for defects in a production line. Let’s say we know the probability of defect is <em>p</em> = 0.001</li><li>We test every products that come off the line, one by one, until we come across a defect (test number <em>n+1</em>).</li><li>We then make a confidence interval <strong>bounded by 0 and 3/n</strong> and make note of it. We make check whether the confidence interval contains the true probability of defect p = 0.001.</li><li>We repeat this process for a lot of time e.g 100,000 iterations</li></ul><p>This is a snippet of the R code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bd7f6d467a948d5d1919ac1dbbcb3d2/href">https://medium.com/media/9bd7f6d467a948d5d1919ac1dbbcb3d2/href</a></iframe><p>As you can see, in the long run, about 95% of the interval <strong>[0, 3/<em>n</em>]</strong> such intervals should contain the true underlying probability of defect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*aTtv_Qx-Iz4mMm1cRI1oWw.png" /><figcaption>Histogram plot of the simulation. The red lines shows the true probability of failure (p=0.001). We see that area to the right of the red line adds up to 95%, which means that 95% of the time, the confidence we arrive at this procedure contains the true underlying defect probability.</figcaption></figure><p><strong>Back to the original question:</strong></p><p>So let us come back to the original questions: let’s forget all the elections before 1992. Since we have not observed California voting Red for the last 8 elections, using the rule of three, we can deduce that the 95% confidence interval of California going red is between 0 and 3/8 = 37.5%. For District of Columbia, it would be [0, 3/15= 20%].</p><p>To be clear, this is a fun example, and to make it work, I have to make some sweeping assumptions here, none of which is probably true.</p><ul><li>(1) We assume that each election result is independent of one another. This is <em>largely untrue</em>, as we know an election result can at least influences district mapping or motivates the turnout of the next one, etc.</li><li>(2) There is an underlying, fixed probability of a state voting Red, this is <em>probably untrue</em>, as we know that the state demography, economic outlook and people’s sentiments, which largely influence party affiliation and how the result come about, change all the time.</li><li>(3) For California, we ignore all elections before 1992. If we included data before, where the rare event did occur [but it was not that rare since California was considered a Red state before 1990s], the rule of three should not have been used [D.C does not have this problem however]</li></ul><p><strong>An actual use case:</strong></p><p>So what is the Rule of Three actually used for? The very popular use case is in pre-licensure clinical trials where the adverse event rate is very rare e.g. vaccine development program. Usually, a sample size in the range of 10,000 subjects can be considered adequate for establishing the protective efficacy of a new vaccine, but not sufficient for detecting the rarer events or complications.</p><p>If no event of any particular sort has been observed during a pre-licensure clinical program involving 10,000 individuals, it can be estimated that this event rate has an upper limit of 3 per 10,000. The actual complication rates, those occurring at a lower frequency than the vaccine-targeted disease, can only be detected by some reliable post-marketing surveillance systems.</p><p>So the next time your dentist says he never fails a procedure, you know what to do: ask him how many patients he has served, used the rule of three to find the confidence interval for his failure rate, and see how comfortable you are with the upper bound.</p><p>You can find the code for the article at <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/R/RuleOfThree.R">my Github page</a>.</p><h3>References:</h3><p>[1] <a href="https://www.nytimes.com/2020/11/06/us/california-blue-state-democrat.html">Why Is California a Blue State?</a></p><p>[2] <a href="https://www.latimes.com/projects/2020-california-election-proposition-analysis/">How this year’s ballot measures show California’s growing political divide</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=106144dc2c39" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-rule-of-three-calculating-the-probability-of-events-that-have-not-yet-occurred-106144dc2c39">The Rule of Three: calculating the probability of events that have not yet occurred</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Men of Steel: Finding the best penalty-takers with empirical Bayes estimation]]></title>
            <link>https://medium.com/data-science/men-of-steel-finding-the-best-penalty-takers-with-empirical-bayes-estimation-aa0e126fb08b?source=rss-87144e3252f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa0e126fb08b</guid>
            <category><![CDATA[football]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Tuan Doan]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 03:20:10 GMT</pubDate>
            <atom:updated>2020-11-04T06:45:28.273Z</atom:updated>
            <content:encoded><![CDATA[<h4>When everything comes down to a spot kick, who can you trust?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5DwjEij42mIRWzrECvFpQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jannesglas?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jannes Glas</a> on <a href="https://unsplash.com/s/photos/soccer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Arguably the most nervy moment of all during a football match, the penalty shot is psychological warfare: Two men, one ball and a clear chance to score a goal. A penalty is supposed to be finished at the professional level: period. Anything else is a failure.</p><p>Such a task should only be required of players made with the iciest of veins.</p><p>There are great penalty-takers, those we can always count on to deliver the ball to the back of the net with a staggering metronomic efficiency. And there are those whose dismal effort, trademarked tip-toe run up or near-orbital strikes are only source for our deep regrets or relentless ridicule.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5PT70VO7E9Y%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5PT70VO7E9Y&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5PT70VO7E9Y%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d816d66627ac5b8637124fdeea900ab4/href">https://medium.com/media/d816d66627ac5b8637124fdeea900ab4/href</a></iframe><p><em>You would think taking penalties is easy. Well, maybe spend 5 minutes on this video.</em></p><h3>So who is the true Man of Steel?</h3><p>You would imagine that this would be a simple secondary Math problems. We collect the records of all spot kicks, calculate the corresponding ratios of conversion for all these players, and TADA!</p><p>But let us look at real examples and see how this simple logic falls through !!!</p><p>On one hand, we have Cristiano Ronaldo, five Ballons d’Or under his belt, whose nickname ‘Penaldo’ stands for his unwavering self-composure in front of the goal with an impressive records of 85 goals out of 98 penalty kicks (86.7%). On the other hand, we have a young talent, Nicolas Pepe at Arsenal, whose recent goal against Aston Villa made his tally totaling 10 successes out of 11 (90.9%). Is Pepe better/more reliable at penalties than Ronaldo?</p><blockquote>Of course, saying anything like that would be ridiculous !!!</blockquote><p>While the young player has slightly higher proportions of scoring, it’s not a lot of evidence: a typical player would score almost 80% of the time, and Pepe’s 90.9% success rate could be due to luck. Ronaldo, on the other hand, has a lot of evidence to show that he is above an average player.</p><blockquote><em>How do we systematically compare and make meaningful judgement about ratios like 85/98 vs 10/11?</em></blockquote><h4><strong>Bayesian Statistics to the rescue:</strong></h4><p>And it’s not in just football that we find this dilemma. We are bound to get tripped up working with successes/totals ratios due to the uncertainty in low counts. The simple solution is to set some thresholds and filter out those players who do not meet the minimum requirement. But it is far from ideal: we are throwing away what could be useful information.</p><p>Let me take a step back and re-frame the questions: we want to somewhat gauge the <em>innate penalty-taking ability</em> of a player. His historical record is a mere estimate of this ability. The task is to more accurately estimate his ability <em>given his historical record</em>.</p><p>I hope you can see how this naturally leads us to a classic Bayesian setting: we can start off with some <strong><em>prior expectation</em></strong> of the player’s ability, and by <strong><em>updating it</em></strong> with <em>new evidence </em>— that is, with his actual scoring record, we get arrive at a more practical estimation of his true ability.</p><p>For a good review of the Bayesian framework, you can have a look at my other articles:</p><ul><li><a href="https://towardsdatascience.com/how-bayesian-statistics-convinced-me-to-hit-the-gym-fa737b0a7ac">How Bayesian statistics convinced me to hit the gym</a></li><li><a href="https://towardsdatascience.com/a-bayesian-quest-to-find-god-b30934972473">A Bayesian quest to find God</a></li></ul><h3>Prior expectation and Empirical Bayes:</h3><p>I’m stepping on a landmine right here. Although the Bayesian setting makes intuitive sense, it is almost impossible to get people agree on a reasonable prior to use for each setting.</p><p>How might one go about specifying their prior belief? Especially if you don’t have an informed guess? One way might be to assign a <strong>“flat prior”</strong> — a prior where you specify that every value of your parameter is equally likely. Another way is to use <strong>Empirical Bayes</strong>, where your data is used to estimate the prior. Here’s the kicker: instead of having a fixed notion of the prior ahead of time, I will save myself from all the trouble by taking a look at the data <em>after collection</em> and estimate the prior distributions accordingly.</p><p>There are advantages from this approach. It is simple, and it takes away (well, sort of) the subjectivity that can creeps in should I have to choose my own priors. Personally, I found that this approach helps me achieve <em>a degree of stabilization</em> of results. A flat prior or something out of line with the data could lead to strange results, e.g negative posterior probabilities. And believe me, this is not uncommon. I’m more likely to get sane answers with empirical Bayes.</p><p>Listen to what famous statistician Bradley Efron has to say about this method:</p><blockquote>Ever since my first exposure in the 1970’s, via Robbins and Stein, empirical Bayes has been the most riveting topic for me. It still seems like magic sometimes<a href="https://www.statisticsviews.com/details/feature/7984731/Empirical-Bayes-has-been-the-most-riveting-topic-for-me_-It-still-seems-like-mag.html">. [1]</a></blockquote><p>David Robinson — chief Data Scientist at DataCamp, also offers some good insights here:</p><blockquote>It basically comes down to how many observations we have: if we have a lot, we can get a good estimate that doesn’t depend much on any one individual. Empirical Bayes is an <strong>approximation</strong> to more exact Bayesian methods- and with the amount of data we have, it’s a very good approximation.[2]</blockquote><p>I know, it feels like cheating, and rightly so. Using actual data to estimate the prior on top of subsequent use for the inference is criticized by many who consider the prior information exogenous to observations, as it can underestimate modeling errors. Any data is going to be complacent with a model which used the same data to specify some of its features.</p><h3>Finding the priors — The Beta Distribution:</h3><p>Let us take a look at the data.</p><p>I have scraped 13 year-worth of penalty kicks data from 6 different leagues across Europe. This is how it looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*7SzRSYl8oHkcP3gVmSfMKw.png" /><figcaption>Records of penalty kicks — ranked by the total number of kicks taken. Our job is to ‘adjust’ the success ratio in order to compare these players.</figcaption></figure><p>As explained earlier, to come up with a good approximation for the priors for the success ratio, we will take a look at its actual distributions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*pyND4izjCG0g_BZnIwKJpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*5tC9gnXLNlvIMZ1NeXuyGA.png" /><figcaption>Left: the histogram of our actual penalty conversion rate . Right: The multiple shapes the Beta distribution can describe with its parameters. Source: Wikipedia</figcaption></figure><p>Here, our task is to find a distribution that characterizes our empirical penalties conversion rate: that is, (1) it takes in a domain from 0 to 1 (no negative probability), (2) it needs to be flexible, in the sense that it could represent what we see in our histogram, and (3) if it makes our Bayesian calculation easier when we combine with the likelihood from the binomial distribution — which describes the number of successes within <strong><em>n</em></strong> trials (i.e: number of goals out of many penalties kicks), all the better.</p><blockquote>Lo and behold, <strong><em>the Beta distribution</em></strong>.</blockquote><p>The Beta distribution takes on the domain [0,1], so we know it cannot do worse than the flat prior. It is highly flexible within the domain, being characterized by two positive shape parameters, denoted by <strong><em>α</em></strong> and<strong> <em>β </em></strong>(see figure above).</p><p>The best part about the Beta distribution is that it is a <strong><em>conjugate prior</em></strong> to the binomial distribution, and this works wonder to our calculation. We can start off with Beta distribution <strong><em>B(α , β) </em></strong>as our prior, updates with information from the Binomial distribution with <strong><em>s</em></strong> successes (scores) and <strong><em>f</em></strong> failures (misses), and arrive at the posterior distribution<em> which is also a Beta distribution of a precise form </em><strong><em>B(α + s, β + f)</em></strong>. The mean of such distribution is <strong><em>(α + s)/(α + β +s+ f)</em></strong></p><blockquote><em>Simply Magical !!!</em></blockquote><p>I include some math at the end of this post just in case you are not convinced !</p><h3>Let’s go on and find our best penalty taker:</h3><h4>Estimate the priors for our actual data:</h4><p>Now that we have a clear framework for our analysis, it’s time to apply it to our real dataset.</p><p>First, let’s fit a Beta distribution to our conversion rate dataset. This could be done quite simply with R.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/397837896e56ce8b894a4b6e3a7655ef/href">https://medium.com/media/397837896e56ce8b894a4b6e3a7655ef/href</a></iframe><p>Using this method, I get an estimation of <strong><em>α = 9.29</em></strong> and<strong> <em>β = 2.93. </em></strong>Let see how well this estimation fits our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*L-2rZ_9PMXp-5RrL8N-TbA.png" /></figure><p>Obviously, it is not perfect, but something we can work with for now.</p><h4><strong>Updating each player statistics using our empirical priors:</strong></h4><p>We can now go on and find the posterior distributions for each player’s conversion rate using the formula I mentioned. That is, <em>a Beta distribution of the form </em><strong><em>B(α + s, β + f), </em></strong>where <strong><em>s </em></strong>and<strong> f </strong>are the numbers of successes and failures, respectively. The posterior mean will be <strong><em>(α + s)/ (α + β +s+ f).</em></strong></p><p>For example, the <em>posterior distribution mean</em> for Ronaldo and Pepe’s penalty conversion rate will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*BCZkIfrZNnEUAMfnHcuX8Q.png" /></figure><p>We can plot their posteriors distributions (with some other players’ ) as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*4NaRKV4Dvr1ZQqcflq9YBQ.png" /><figcaption>The posterior distribution of penalty conversion rate for a few players</figcaption></figure><p>We can see that Ronaldo’s strong records results in very high posterior mean and a narrow credible interval, while Pepe’s posterior mean conversion has a much larger credible intervals, as he has less data to stand for. Meanwhile, Griezmann and Sanchez are just not that good when it comes to penalty.</p><h4>The top 10 penalty takers:</h4><p>After applying the empirical Bayes estimate and beta-binomial posterior calculation, let me introduce the top 10 penalty takers over the last 13 years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*EsUnrjTz-y5rwd5qyYqTiw.png" /></figure><p>So it turns out that the best penalty takers, at least by this method, are Salihovic, and G.Rossi, followed very closely by Boudebouz, Mark Noble and Lewandowski. The famous penalty takers: Lampard, Gerrard, Harry Kane are not as good as they are claimed to be. Interestingly, we can see that for these players, their conversion rates shrink after we apply this procedure. We can plot the original and the adjusted ratios on a plot to assess the adjustment. This section is inspired by an amazing great article by David Robinson [2].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*UNRd_yev9G2ci2Xr3jIyPA.png" /><figcaption>Plot of actual vs adjusted conversion ratios</figcaption></figure><p>The horizontal dashed line shows the mean of the prior distribution — what we should guess a player’s success rate is if we don’t have any information about the player. Then, we have the diagonal line <strong><em>y = x</em></strong>, showing the data points in which the actual goal scoring average equals the posterior adjustment.</p><p>There are two interesting observations. First, we can see that the points above the prior mean tend to shrink down, while the points below get inflated up towards the mean. Second, the points that was least affected by the shrinkage are points associated with a lot of observations. And when you think about, it makes perfect sense: if we have a lot of evidence through observation, we can rely on the actual estimation; otherwise, there is a lot of value in believing that our data tends towards the population mean.</p><h3>Conclusion:</h3><p>So there you go, I have just introduced the concept of empirical Bayesian estimation:<em> we can leverage the overall distribution of our data as a prior to arrive at a more realistic estimate of each average</em>. Then, we use the powerful concept of conjugate priors to bypass the complications of calculating the posterior distributions in our procedure. The beta-binomial combination are so popular that you can apply it to a host of scenarios: basketball, A/B testing with clickthrough, school canteen rating, etc.</p><p>For the purpose of this article, I have conveniently ignored many complications. For one, we can tell that a beta distribution for our prior is barely a great fit. In fact, we can fit a bimodal distribution with 2 Beta distributions, assigning every player in two different groups according to the likelihood that they belong to each distribution.</p><p>You can checkout my <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/R/EPL/penalty/penalty.R">code</a> that address this issue.</p><p>Another complication is that the penalty conversion rate changes over time and differ across different leagues. As far as we consider all these different factors, we take many steps away from our simple Beta-Binomial distribution and enter the realm of <strong><em>Bayesian hierarchical model</em></strong>. And that’s where the fun begins !!!</p><h3>Appendix:</h3><p>The code for this article and more can be found <a href="https://github.com/tuangauss/DataScienceProjects/blob/master/R/EPL/penalty/penalty.R">here</a>.</p><p>This is a short proof for the Beta-Binomial conjugate pairing.</p><p>The setting is simple: we observe a number of success counts <strong><em>s</em></strong> that we believe follows a Binomial distribution with sample size n and success rate <strong><em>r. </em></strong>Our job is to find the posterior distribution of <strong><em>r</em></strong> given <strong><em>s</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*XTWzBjUM7_8ApqGYfJFVHA.png" /></figure><p>Time for us to call upon the famous Bayesian formula — only for continuous variable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*2sMi8DKEuEHdAREBtAiZ3g.png" /></figure><p>The likelihood function<strong><em> p(s|r)</em></strong> and the prior <strong><em>p(r)</em></strong> follow well-defined Binomial and Beta distributions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*ou4EXBW7ZA2C501v-JoLoA.png" /></figure><p>Then, our job is just plugging in and finding the posterior distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*njfWa2TFlG5UgJAEP4KPaQ.png" /></figure><p>The result is a Beta distribution of the form <strong><em>B(α + s, β + f)</em></strong></p><p>[1] Statistic View. (2015, June 1). “<em>Empirical Bayes has been the most riveting topic for me. It still seems like magic sometimes: An interview with Bradley Efron.</em>”</p><p>[2] Robinson, D. (2015, October 1). “<em>Understanding empirical Bayes estimation (using baseball statistics)</em>.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa0e126fb08b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/men-of-steel-finding-the-best-penalty-takers-with-empirical-bayes-estimation-aa0e126fb08b">Men of Steel: Finding the best penalty-takers with empirical Bayes estimation</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>