On 06-Aug-99 Dalton David wrote:
> I apologise if I have sent this message to the wrong list, but here
> goes...
>
> I am looking for a method to generate random numbers according to a
> poisson distribution for a simulation exercise I am working on. I
> intend
> to use a microsoft excel spreadsheet model.
>
> Can you help me with a suitable algorithm or formula, or with a
> reference to one?
Hi David,
It depends on the value of 'mu' (the Poisson mean), but the following
is a very simple method which is efficient if 'mu' is not too large
(say < 20), for any value of 'n'.
Efficient methods for larger 'mu' are more complicated.
To sample 'n' Poisson random numbers with mean 'mu':
Initially:
X is a column of n numbers all = -1
t is a column of n numbers all = +1
g is a column of n numbers all = exp(-mu)
Loop:
While any cells of col "t" > corresponding cells of col "g"
{ Add 1 to corresponding cells of col "X"
Multiply the n cells[*] of col "t" by independent random
numbers uniformly distributed on [0,1]
}
([*] or just the corresponding cells, depending on which is
fastest/easiest)
After exiting Loop:
The numbers in X are the n Poisson random numbers
===========================================================
This looks simple enough to be usable with a spreadsheet,
but it will work best with array-oriented software which
performs "vectorised" computations (i.e. one command applies
an operation to all elements of an array), such as MatLab
or its Free Software near-equivalent 'octave'.
On a rather modest P-133 machine, I get a sample of n=10000
with mu=2 in about 2 secs, with mu=10 in about 3.5 secs,
with mu=100 in about 12 secs; times (though random) are roughly
proportional to n, e.g for n=500000 they are about 60secs,
150 secs and 800 secs for mu = 2, 10, 20.
It is really fast for very small 'mu' -- e.g. 10 seconds
for n=1,000,000 with mu=0.0001.
I don't think I'd want to do this on a spreadsheet for n=1000000.
Of course it works just fine with n=1 as well!
Hope this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <[log in to unmask]>
Date: 06-Aug-99 Time: 13:58:19
------------------------------ XFMail ------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|