Re: [R] Sum of Bernoullis with varying probabilities

From: Thomas Lumley <>
Date: Mon 09 Oct 2006 - 14:44:46 GMT

On Fri, 6 Oct 2006, Deepayan Sarkar wrote:

> On 10/6/06, Ted Harding <> wrote:
>> Hi Folks,
>> Given a series of n independent Bernoulli trials with
>> outcomes Yi (i=1...n) and Prob[Yi = 1] = Pi, I want
>> P = Prob[sum(Yi) = r] (r = 0,1,...,n)

>> OK, some abbreviation of the above can be achieved with
>> the 'apply' function (and I've spelt out the details for
>> clarity). But I feel the basis of the approach (i.e. 'combn')
>> is crude (also tending to cause problems if n is large);
>> and I'm wondering if there is a nicer way.
> I don't see how. Someone has to evaluate the n-choose-r distinct terms
> to be added, and your code seems to be doing that as directly as
> possible.

Not necessarily. It could be quicker to numerically invert the characteristic function, which is easy to compute.


Thomas Lumley			Assoc. Professor, Biostatistics	University of Washington, Seattle

______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue Oct 10 01:05:56 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 09 Oct 2006 - 15:30:10 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.