<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/will-stanton-hit-61-home-runs-this-season/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://andrewgelman.com/2017/09/21/will-stanton-hit-61-home-runs-season/"> R – Statistical Modeling, Causal Inference, and Social Science</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>[<b>edit</b>: Juho Kokkala <a rel="nofollow" href="http://andrewgelman.com/2017/09/21/will-stanton-hit-61-home-runs-season/#comment-567416" target="_blank">corrected my homework</a>. Thanks! I updated the post. Also see some further elaboration in <a rel="nofollow" href="http://andrewgelman.com/2017/09/21/will-stanton-hit-61-home-runs-season/#comment-567752" target="_blank">my reply to Andrew’s comment</a>. As <a rel="nofollow" href="http://andrewgelman.com/2005/10/06/god_is_in_every/" target="_blank">Andrew likes to say …</a>]</p>
<p>So far, <a rel="nofollow" href="http://m.mlb.com/player/519317/giancarlo-stanton" target="_blank">Giancarlo Stanton</a> has hit 56 home runs in 555 at bats over 149 games. Miami has 10 games left to play. What’s the chance he’ll hit 61 or more home runs? Let’s make a simple back-of-the-envelope Bayesian model and see what the posterior event probability estimate is.</p>
<p><b>Sampling notation</b></p>
<p>A simple model that assumes a home run rate per at bat with a uniform (conjugate) prior:</p>
<p><img alt="theta sim mbox{Beta}(1, 1)" title="theta sim mbox{Beta}(1, 1)" src="http://s0.wp.com/latex.php?latex=%5Ctheta+%5Csim+%5Cmbox%7BBeta%7D%281%2C+1%29&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p>The data we’ve seen so far is 56 home runs in 555 at bats, so that gives us our likelihood.</p>
<p><img alt="56 sim mbox{Binomial}(555, theta)" title="56 sim mbox{Binomial}(555, theta)" src="http://s0.wp.com/latex.php?latex=56+%5Csim+%5Cmbox%7BBinomial%7D%28555%2C+%5Ctheta%29&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p>Now we need to simulate the rest of the season and compute event probabilities. We start by assuming the at-bats in the rest of the season is Poisson.</p>
<p><img alt="mathit{ab} sim mbox{Poisson}(10 times 555 / 149)" title="mathit{ab} sim mbox{Poisson}(10 times 555 / 149)" src="http://s0.wp.com/latex.php?latex=%5Cmathit%7Bab%7D+%5Csim+%5Cmbox%7BPoisson%7D%2810+%5Ctimes+555+%2F+149%29&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p>We then take the number of home runs to be binomial given the number of at bats and the home run rate.</p>
<p><img alt="h sim mbox{Binomial}(mathit{ab}, theta)" title="h sim mbox{Binomial}(mathit{ab}, theta)" src="http://s0.wp.com/latex.php?latex=h+%5Csim+%5Cmbox%7BBinomial%7D%28%5Cmathit%7Bab%7D%2C+%5Ctheta%29&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p>Finally, we define an indicator variable that takes the value 1 if the total number of home runs is 61 or greater and the value of 0 otherwise.</p>
<p><img alt="mbox{gte61} = mbox{I}[h geq (61 - 56)]" title="mbox{gte61} = mbox{I}[h geq (61 - 56)]" src="http://s0.wp.com/latex.php?latex=%5Cmbox%7Bgte61%7D+%3D+%5Cmbox%7BI%7D%5Bh+%5Cgeq+%2861+-+56%29%5D&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p><b>Event probability</b></p>
<p>The probability Stanton hits 61 or more home runs (conditioned on our model and his performance so far) is then the posterior expectation of that indicator variable,</p>
<p><img alt="displaystyle mbox{Pr}[h geq (61 - 56)] \[6pt] hspace*{3em}  displaystyle { } =  int_{theta}  sum_{ab} ,  mathrm{I}[h geq 61 - 56] \ hspace*{8em}  times  mbox{Binomial}(h mid ab, theta) \[6pt] hspace*{8em}  times  mbox{Poisson}(ab mid 10  times  555 / 149) \[6pt] hspace*{8em}  times  mbox{Beta}(theta mid 1 + 56, 1 + 555 - 56)  mathrm{d}theta." title="displaystyle mbox{Pr}[h geq (61 - 56)] \[6pt] hspace*{3em}  displaystyle { } =  int_{theta}  sum_{ab} ,  mathrm{I}[h geq 61 - 56] \ hspace*{8em}  times  mbox{Binomial}(h mid ab, theta) \[6pt] hspace*{8em}  times  mbox{Poisson}(ab mid 10  times  555 / 149) \[6pt] hspace*{8em}  times  mbox{Beta}(theta mid 1 + 56, 1 + 555 - 56)  mathrm{d}theta." src="http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cmbox%7BPr%7D%5Bh+%5Cgeq+%2861+-+56%29%5D+%5C%5C%5B6pt%5D+%5Chspace%2A%7B3em%7D++%5Cdisplaystyle+%7B+%7D+%3D+%5C+%5Cint_%7B%5Ctheta%7D+%5C+%5Csum_%7Bab%7D+%5C%2C+%5C+%5Cmathrm%7BI%7D%5Bh+%5Cgeq+61+-+56%5D+%5C%5C+%5Chspace%2A%7B8em%7D+%5C+%5Ctimes+%5C+%5Cmbox%7BBinomial%7D%28h+%5Cmid+ab%2C+%5Ctheta%29+%5C%5C%5B6pt%5D+%5Chspace%2A%7B8em%7D+%5C+%5Ctimes+%5C+%5Cmbox%7BPoisson%7D%28ab+%5Cmid+10+%5C+%5Ctimes+%5C+555+%2F+149%29+%5C%5C%5B6pt%5D+%5Chspace%2A%7B8em%7D+%5C+%5Ctimes+%5C+%5Cmbox%7BBeta%7D%28%5Ctheta+%5Cmid+1+%2B+56%2C+1+%2B+555+-+56%29+%5C+%5Cmathrm%7Bd%7D%5Ctheta.&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"></p>
<p><b>Computation in R</b></p>
<p>The posterior for <img alt="theta" title="theta" src="http://s0.wp.com/latex.php?latex=%5Ctheta&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"> is analytic because the prior is conjugate, letting us simulate the posterior chance of success given the observed successes (56) and number of trials (555). The number of at bats is independent and also easy to simulate with a Poisson random number generator. We then simulate the number of hits on the outside as a random binomial, and finally, we compare it to the total and then report the fraction of simulations in which the simulated number of home runs put Stanton at 61 or more:</p>
<pre>
> sum(rbinom(1e5,
             rpois(1e5, 10 * 555 / 149),
             rbeta(1e5, 1 + 56, 1 + 555 - 56))
       >= (61 - 56)) / 1e5
[1] 0.34
</pre>
<p>That is, I’d give Stanton about a 34% chance conditioned on all of our assumptions and what he’s done so far. </p>
<p><b>Disclaimer</b></p>
<p>The above is intended for recreational use only and is not intended for serious bookmaking.</p>
<p><b>Exercise</b></p>
<p>You guessed it—code this up in Stan. You can do it for any batter, any number of games left, etc. It really works for any old statistics. It’d be even better hierarchically with more players (that’ll pull the estimate for <img alt="theta" title="theta" src="http://s0.wp.com/latex.php?latex=%5Ctheta&bg=ffffff&%23038;fg=000000&%23038;s=0" class="latex"> down toward the league average). Finally, the event probability can be done with an indicator variable in the generated quantities block.</p>
<p>The basic expression looks like you need discrete random variables, but we only need them here for the posterior calculation in generated quantities. So we can use Stan’s random number generator functions to do the posterior simulations right in Stan.</p>
<p>The post <a rel="nofollow" href="http://andrewgelman.com/2017/09/21/will-stanton-hit-61-home-runs-season/" target="_blank">Will Stanton hit 61 home runs this season?</a> appeared first on <a rel="nofollow" href="http://andrewgelman.com/" target="_blank">Statistical Modeling, Causal Inference, and Social Science</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://andrewgelman.com/2017/09/21/will-stanton-hit-61-home-runs-season/"> R – Statistical Modeling, Causal Inference, and Social Science</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/S0M8OZctOUI" height="1"></a></div>