4
I’m working on a population dynamics simulation that involves generating whole numbers. Due to the hypotheses of my model, I am generating random numbers through the function rmultinom
R. However, I am having overflow problems in my simulation.
The largest integer R can generate is defined by .Machine$integer.max
. In my PC, this number is equal to 2147483648. In scientific notation, this value is equivalent to approximately 2,147 x 10 9.
But many of the simulations I run exceed this limit. The parameter size
of rmultinom
will be greater than 10 (10) or even 10 (12). And if so, I cannot generate random numbers with the distribution I desire.
What could I do to solve this problem? Any suggestions?
Yes, yes, this is the definition of the multinomial distribution. The
length(prob)
it won’t be a problem for me, because it is fixed as 3. I checked your function here and, in my tests, it stopped overflowing in cases where this occurred.– Marcus Nunes
Good! I think it will give problem if the size is > 1000000000L 2 It makes sense to do the tests independently and then add right?
– Daniel Falbel
It makes perfect sense because they are independent draws. One way to check this is to run your function
amostra
a large number of times (say 100000 instead of 100) for a smaller size value. Here runs the original version ofrmultinom
for the same replication values, size and size. If category estimates match what has been defined inprob
, everything will be all right. I circled here and everything hit as it should.– Marcus Nunes