Skip to main content
19 events
when toggle format what by license comment
Dec 13, 2022 at 17:06 comment added Henry I did something almost identical to your convolve.binomial function. Just to note that it gives the probabilities for the numbers poisoned while StasK's chart is for the numbers surviving.
Feb 22, 2018 at 15:36 comment added whuber FWIW, my preceding comment may be confusing in its reference to sapply: that construct has since been replaced by a one-line for loop. The algorithm, and its explanation, remain the same.
S Feb 22, 2018 at 14:27 history edited whuber CC BY-SA 3.0
Great answer. Suggested edits give identical results and virtually identical performance, without the unusual use of sapply for side effects (and confusing return value of the enclosed function, which doesn't do anything). Just as suggestion. Thanks for the great solutions!
S Feb 22, 2018 at 14:27 history suggested Ry Guy CC BY-SA 3.0
Great answer. Suggested edits give identical results and virtually identical performance, without the unusual use of sapply for side effects (and confusing return value of the enclosed function, which doesn't do anything). Just as suggestion. Thanks for the great solutions!
Feb 22, 2018 at 14:00 review Suggested edits
S Feb 22, 2018 at 14:27
Oct 2, 2016 at 5:01 comment added Antoni Parellada Clothesline with $z_1$ being the $\Pr(\text{zero poisonings})$. And the $t$ in the $qt$ part of the pdf of each new Bernouilli $p_i$ modifying one term offset of the polynomial... So clear now...
Oct 1, 2016 at 20:40 comment added whuber @Antoni, each step adds a Bernoulli$(q)$ variable to the discrete variable whose probability generating function (pgf) is given in the variable z. If you like, think of z as representing the polynomial $z(t)=z_1+z_2t+z_3t^2+\cdots+z_nt^{n-1}$. The pgf of the Bernoulli variable is $f_q(t)=(1-q)+qt$. Each step of sapply computes an update $z(t)\to z(t)f_q(t)$. The initial value is $z(t)=1$. Thus, given the vector $\mathbf{p}=(p[1],p[2],\ldots,p[n-1])$, the loop computes the product $$\prod_{i=1}^{n-1}f_{p[i]}(t),$$ which is a polynomial of degree $n-1$ (therefore with $n$ coefficients).
Oct 1, 2016 at 18:00 comment added Antoni Parellada I am trying to understand your code to see exactly the mechanics of the calculation of the convolution.
Dec 2, 2013 at 19:43 comment added DWin Thanks from an old guy who never took college level probability courses. I've tried learning this stuff from textbooks, but having the capacity to play around with it in R makes it more immediate. I will try to link up this experience with my copies of Feller's wonderful volumes.
Dec 2, 2013 at 19:39 comment added whuber @DWin The order of the probabilities has a small effect on finite-precision floating-point calculations (for well-known reasons), but it has no effect on the exact results. This is made obvious by considering that the characteristic function of the resulting distribution is the product of the cfs of the Bernoulli distributions: because the order of multiplication in the product does not matter and the cf determines the distribution, the result is the same regardless of the order. The floating point errors are typically about as small as can be hoped, less than $10^{-16}$.
Dec 2, 2013 at 19:21 comment added DWin This lends itself well to exploring consequences of different aspects of the set of probabilities; experimentation shows that the order of the probabilities has no effect. I'm not sure if that is immediately obvious, but now I suspect a proof by induction should be possible.
Oct 27, 2012 at 22:28 comment added rudivonstaden I would accept both answers if I could as both answer the question comprehensively! Your answer was more immediately useful, while @StasK's solution was more instructive. On that basis I will select his answer as the most relevant to the question. But I appreciate the time and insight that you have both contributed.
Oct 27, 2012 at 20:22 comment added whuber You shouldn't accept an answer on that basis! @StasK's algorithm is easily implemented in R. I added code to show how.
Oct 27, 2012 at 20:21 history edited whuber CC BY-SA 3.0
added 1059 characters in body
Oct 26, 2012 at 19:33 comment added rudivonstaden I am accepting this answer because I will be doing this analysis from within the QGIS mapping application, which integrates easily with R.
Oct 26, 2012 at 18:13 comment added rudivonstaden Thanks for your elegant solution, @whuber! You were correct in your understanding of "risk of extinction category"; since it could potentially be confusing and doesn't add anything to the question, I have removed those references.
Oct 26, 2012 at 18:01 vote accept rudivonstaden
Oct 27, 2012 at 22:25
Oct 26, 2012 at 17:59 history edited whuber CC BY-SA 3.0
added 221 characters in body
Oct 26, 2012 at 17:53 history answered whuber CC BY-SA 3.0