<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/another-riddle-with-a-stopping-rule/"></div></div><div><a data-url="http://www.r-bloggers.com/another-riddle-with-a-stopping-rule/" data-counturl="http://www.r-bloggers.com/another-riddle-with-a-stopping-rule/" data-count="horizontal" data-text="another riddle with a stopping rule" 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="https://xianblog.wordpress.com/2016/05/27/another-riddle-with-a-stopping-rule/"> R – Xi'an's Og</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>A</strong> puzzle on <a target="_blank" href="http://fivethirtyeight.com/features/can-you-best-the-mysterious-man-in-the-trench-coat/">The Riddler</a> last week that is rather similar to an earlier one. Given the probability (1/2,1/3,1/6) on {1,2,3}, what is the mean of the number N of draws to see all possible outcomes and what is the average number of 1’s in those draws? The second question is straightforward, as the proportions of 1’s, 2’s and 3’s in the sequence till all values are observed remain 3/6, 2/6 and 1/6. The first question follows from the representation of the average</p>
<p><img title="\mathbb{E}[N]=\sum_{n=3}^\infty \mathbb{P}(N&gt;n) + 3" alt="\mathbb{E}[N]=\sum_{n=3}^\infty \mathbb{P}(N&gt;n) + 3" class="latex" src="https://s0.wp.com/latex.php?latex=%5Cmathbb%7BE%7D%5BN%5D%3D%5Csum_%7Bn%3D3%7D%5E%5Cinfty+%5Cmathbb%7BP%7D%28N%3En%29+%2B+3&bg=000000&%23038;fg=B0B0B0&%23038;s=0"></p>
<p>as the probability to exceed n is the probability that at least one value is not observed by the n-th draw, namely</p>
<p>3+(1/2)<sup>n</sup>+(2/3)<sup>n</sup>+(5/6)<sup>n</sup>-(1/6)<sup>n</sup>-(1/3)<sup>n</sup>-(1/2)<sup>n</sup></p>
<p>which leads to an easy summation for the expectation, namely</p>
<p>3+(2/3)³/(1/3)+(5/6)³/(1/6)-(1/3)³/(2/3)-(1/6)³/(5/6)=73/10</p>
<p><span></span></p>
<p>Checking the results hold is also straightforward:</p>
<pre>
averages &lt;- function(n=1){
    x=matrix(sample(1:3,100,rep=TRUE,prob=1:3),100,3)
    x[,1]=as.integer(x[,2]&lt;2) x[,3]=as.integer(x[,2]>2)
    x[,2]=1-x[,1]-x[,3]
    y=apply(apply(x,2,cumsum),1,prod)
    m=1+sum(y==0)
    return(apply(x[1:m,],2,sum))}
</pre>
<p>since this gives</p>
<pre>
mumbl=matrix(0,1e5,3)
for (t in 1:1e5) mumbl[t,]=averages()
> apply(mumbl,2,mean)
[1] 1.21766 2.43265 3.64759
> sum(apply(mumbl,2,mean))
[1] 7.2979
> apply(mumbl,2,mean)*c(6,3,2)
[1] 7.30596 7.29795 7.29518
</pre>
<p>Filed under: <a target="_blank" href="https://xianblog.wordpress.com/category/books/">Books</a>, <a target="_blank" href="https://xianblog.wordpress.com/category/kids/">Kids</a>, <a target="_blank" href="https://xianblog.wordpress.com/category/statistics/r-statistics/">R</a> Tagged: <a target="_blank" href="https://xianblog.wordpress.com/tag/538/">538</a>, <a target="_blank" href="https://xianblog.wordpress.com/tag/fivethirtyeight/">FiveThirtyEight</a>, <a target="_blank" href="https://xianblog.wordpress.com/tag/stopping-rule/">stopping rule</a>, <a target="_blank" href="https://xianblog.wordpress.com/tag/the-riddler/">The Riddler</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xianblog.wordpress.com/30705/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/xianblog.wordpress.com/30705/" border="0"></a> <img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=xianblog.wordpress.com&blog=5051449&%23038;post=30705&%23038;subd=xianblog&%23038;ref=&%23038;feed=1" border="0"></p>
<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/another-riddle-with-a-stopping-rule/"></div></div><div><a data-url="http://www.r-bloggers.com/another-riddle-with-a-stopping-rule/" data-counturl="http://www.r-bloggers.com/another-riddle-with-a-stopping-rule/" data-count="vertical" data-text="another riddle with a stopping rule" 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="https://xianblog.wordpress.com/2016/05/27/another-riddle-with-a-stopping-rule/"> R – Xi'an's Og</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/YxsjgspeFcU"></a></div>