<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/"></div></div><div><a data-url="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/" data-counturl="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/" data-count="horizontal" data-text="How to be Bayesian and spare yourself a dreadful afternoon with your stupid football team losing the derby" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://gianlubaio.blogspot.com/2016/05/how-to-be-bayesian-and-spare-yourself.html"> Gianluca Baio's blog</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span>Yesterday was the second-last game of the Italian Serie A; I’ve been a <a target="_blank" href="http://www.sampdoria.it/">Sampdoria</a> supported since I was 12 $-$ at that time, they were starting to become one of the best clubs in Serie A (and that was back in the 80’s when Serie A was arguably the best league in the world), although they</span><span> hadn’t won anything and didn’t have prospects for that season either. </span><span>But they were a young, good side, playing nicely and so I kind of fell in love with them (and their <a target="_blank" href="http://www.sampcollection.com/wp-content/uploads/2007/11/1986_87_1_f.jpg">shirt</a>). </span><span>Then they did become a very good side, winning the league and a few more trophies $-$ so good timing on my part! But also, then they reverted to some relative mediocrity $-$ of course, once you’ve decided you support a team, you’re stuck with them no matter what.</span><br><span><br></span><span>Anyway, this season has been rather crappy and yesterday it was a crucial game: we were playing the derby against local rival Genoa entering the game with 40 points and two games left in the campaign. Two teams couldn’t reach us any more (as they were trailing by over 6 points). But at least one between Carpi and Palermo could still overtake us if we lost our two remaining games and they won all of theirs. Also, Udinese was just one point behind us so they too could overtake us, technically. With three teams being relegated, we weren’t statistically safe yet.</span><br><span><br></span><span>So, that’s kind of nervous and earlier last week I thought about this a bit. I had a bad feeling about our game, because we’ve not been great lately (the previous game we were beaten by Palermo) and, clearly, Genoa would try really hard to mess it up for us… But, irrespective of the outcome of the derby, if at least one between Carpi, Palermo and Udinese failed to win their match we would be safe (as there wouldn’t be enough points left for them to catch us). Carpi played </span><span>at home against </span><span>Lazio</span><span>, whose season hasn’t been great either, but they were already safe and with not much else to fight for, except a strong finish; Palermo were away at Fiorentina, who theoretically were still fighting for a Europa league qualification and so should have something to play for; Udinese were away at Atalanta, who much as Lazio were mathematically safe and with not much to play for.</span><br><span><br></span><span>Although one can make a much more complex model, I reasoned that instead of the actual result, what was only important was the chance that either of the three teams behind us would win and so I set up a model with </span><span>$ y_{rm{Car}} sim mbox{Bernoulli}(theta_{rm{Car}})$, </span><span>$y_{rm{Pal}} sim mbox{Bernoulli}(theta_{rm{Pal}})$</span><span> and</span><span> $y_{rm{Udi}} sim mbox{Bernoulli}(theta_{rm{Udi}})$ where the “success” would in fact be the worst possible outcome, ie a win for them.</span><br><span><br></span><span>Then I set up some priors: I reasoned that because they were playing at home, Carpi may have a slightly higher chance of winning the game $-$ I figured something about 35%. Also, I thought (hoped) that Lazio wouldn’t be a walkover and so I assumed that 90% of the mass for the chance of Carpi winning their game was around 45%. These can be turned into an informative Beta(</span><span>15.80107,28.4877</span><span>) prior $-$ it’s fairly easy to work out the parameters of a Beta distribution given the mode (0.35, in this case) and some percentile (0.45 as the 90th percentile, in this case); <a target="_blank" href="https://www.crcpress.com/Bayesian-Ideas-and-Data-Analysis-An-Introduction-for-Scientists-and-Statisticians/Christensen-Johnson-Branscum-Hanson/9781439803547">Christensen et al</a> (page 100) show some theory, while <a target="_blank" href="http://www.medicine.mcgill.ca/epidemiology/joseph/pbelisle/BetaParmsFromQuantiles.html">this</a> is some relevant R code.
<p>This is effectively the prior I was assuming:
<div><a target="_blank" href="https://2.bp.blogspot.com/-kWdSeKXSN6Y/VzBWXGzi1jI/AAAAAAAAEnw/9s4upgTdVmUXG2nOBZkx_yXodAmtzf_1gCLcB/s1600/Carpi.jpeg"><img src="https://2.bp.blogspot.com/-kWdSeKXSN6Y/VzBWXGzi1jI/AAAAAAAAEnw/9s4upgTdVmUXG2nOBZkx_yXodAmtzf_1gCLcB/s1600/Carpi.jpeg" border="0"></a></div></span>
<p>
<div><a target="_blank" href="https://2.bp.blogspot.com/-RssHZFHkKNM/VzBWxHuUOGI/AAAAAAAAEn4/yBQX_6GXhLYA_5VLaRLxuo5S0gugDlQBgCLcB/s1600/Carpi.png"><img height="320" width="320" src="https://2.bp.blogspot.com/-RssHZFHkKNM/VzBWxHuUOGI/AAAAAAAAEn4/yBQX_6GXhLYA_5VLaRLxuo5S0gugDlQBgCLcB/s320/Carpi.png" border="0"></a></div>
<div><span>and I thought it was just about reasonable (the dotted vertical lines indicate a rough estimate of the 95% prior credible interval). Then I did something similar to derive the priors for a Palermo and Udinese win $-$ because they were playing away, I figured they would have an average chance of winning of around 20% with 90% of the mass before 40%, which can be turned into a Beta(3.279775,10.1191</span><span>) prior, looking like this:</span></div>
<div><a target="_blank" href="https://4.bp.blogspot.com/-rEKvCfpjrjE/VzBbyawpWrI/AAAAAAAAEoY/lxx6RQz3KkoNO92InRsLpvW3NohHXOTdACLcB/s1600/Others.png"><img height="320" width="320" src="https://4.bp.blogspot.com/-rEKvCfpjrjE/VzBbyawpWrI/AAAAAAAAEoY/lxx6RQz3KkoNO92InRsLpvW3NohHXOTdACLcB/s320/Others.png" border="0"></a></div>
<p>
<div></div>
<div><span>Again, I was relatively happy with this and so used these priors in my model, which one could code in R as something like</span></div>
<div><span>p.car ~ rbeta(10000,15.80107,28.4877)</span><span> </span><span># P(win) on average .35 and with 95% mass &lt;= .45</span></div>
<div><span>p.pal ~ rbeta(10000,3.279775,10.1191) </span><span> </span><span># P(win) on average .2 and with 95% mass &lt;=.4</span></div>
<div><span>p.udi ~ rbeta(10000,3.279775,10.1191)</span><span> </span><span># P(win) on average .2 and with 95% mass &lt;=.4</span></div>
<div><span>p.safe &lt;- 1-(p.car*p.pal*p.udi)</span></div>
<div><span><br></span></div>
<div><span>The most important variable in the model is the probability of Sampdoria being mathematically certain of avoiding relegation, </span><span>p.safe</span><span>, which is 1 minus the probability of the worst happening $-$ this assumes independence in the three games for Palermo, Carpi and Udinese; in general that’s probably not the best assumption, but in this case they kind of had to win to have a good shot at safety themselves and so I think it’s OK to assume independence. The results were kind of reassuring:</span></div>
<div><a target="_blank" href="https://3.bp.blogspot.com/-uT3DkAGyLgM/VzBdgOjgl-I/AAAAAAAAEok/IcevTVRVNtYcwp1JXf5BTLsmoJU0Z785ACLcB/s1600/Safe.png"><img height="320" width="320" src="https://3.bp.blogspot.com/-uT3DkAGyLgM/VzBdgOjgl-I/AAAAAAAAEok/IcevTVRVNtYcwp1JXf5BTLsmoJU0Z785ACLcB/s320/Safe.png" border="0"></a></div>
<div><span>$-$ I got an estimated posterior average of 97.8% with a 95% credible interval of 93.8 to 99.7%. </span></div>
<div><span><br></span></div>
<div><span>I am not really one to stay at home on a Sunday just to watch the football game (so perhaps I’m not really a footaball fan?) and we’d planned to see some friends, but this reassured me that we shouldn’t be in too much trouble, even if we lost the derby. In the event, Kobi wasn’t great (possibly as a result of venturing an outing at the seaside on Saturday) and so we stayed at home $-$ but I decided not to bother with watching the game (again: a) a bold move for a real football fan, confident about his team; b) a cowardly move from a real football fan scared of what the outcome may be; c) not a real football fan).</span></div>
<div><span><br></span></div>
<div><span>We did lose the derby very badly, but Carpi, Palermo and Udinese all failed to win their games, which means we are safe. I’m glad I didn’t watch the game…</span></div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/"></div></div><div><a data-url="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/" data-counturl="http://www.r-bloggers.com/how-to-be-bayesian-and-spare-yourself-a-dreadful-afternoon-with-your-stupid-football-team-losing-the-derby/" data-count="vertical" data-text="How to be Bayesian and spare yourself a dreadful afternoon with your stupid football team losing the derby" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://gianlubaio.blogspot.com/2016/05/how-to-be-bayesian-and-spare-yourself.html"> Gianluca Baio's blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/6mgaC6bVxCI"></a></div>