[R] Re: Generating routine for Poisson random numbers

Thomas Lumley tlumley at u.washington.edu
Wed Aug 27 01:36:13 CEST 2003


>
> One could impose a lambda range check so that you can only invoke the
> function using a lamba range where the Poisson RNG is expected to be
> reasonably accurate.  The range you are giving is probably the most commonly
> used range where a Poisson random number generator might be used?  Brian
> Ripley also mentioned that the counting process based implementation would
> not work well for large lambdas.  Do you encounter such large lambdas in
> practice?   Can't you always, in theory, avoid such large lambdas by
> changing the size of the time interval you want to consider?

Personally, I'd probably change the question by approximating by a Normal
for large lambda and a Bernoulli for very small lambda.

The algorithm gets slow well before it gets inaccurate, though.

> > But why would anyone *want* to code their own Poisson random number
> generator, except perhaps as an interesting student exercise?
>
> Yes this is meant as an interesting exercise for someone who wants to
> understand how to implement probability distributions in an object oriented
> way (I am writing an article introducing people to probability modelling).
> I am looking for a compact algorithm that I can easily explain to people how
> it works and which will be a good enough rpois() approximation in many
> cases.  I don't want to be blown out of the water for suggesting such an
> algorithm to represent a Poisson RNG so if you think it is inappropriate to
> learn about what how a Poisson RNG works using the above described
> generating process,  then I would be interested in your views.

No, that's why I gave that as the exception.  There are lots of things
worth doing as a learning exercise that aren't worth doing otherwise.


I do think that in an article you should also point out to people that
there is a lot of numerical code available out there, written by people
who know a lot more than we do about what they are doing. It's often
easier than writing your own code and the results are better. One
advantage of an object-oriented approach is that you can just rip out your
implementation and slot in a new one if it is better.


	-thomas




More information about the R-help mailing list