I guess you'll need to simplify the fraction in the first term before doing the calculations, as it is often the case in probability calculations. This makes the calculations much faster and more accurate.
I don't remember enough about multinomial distributions, but let me take a simple example: computing the number of permutations of 5 items in a population of 1000. The formula is: n!/(n-k)! or, in the example, 1000!/995! . You don't want to calculate 1000! (a number with 2570 digits) and then calculate 995! (only 2552 digits...) and then proceed with the division between the two huge numbers, whereas you really need only: 996 * 997 * 998 * 999 * 1000. In Perl, this could be expressed simply as follows:
`my $result = 1;
$result *= $n-- while $k--;
`
Some form of similar simplication should be possible in your case.
Otherwise, there are on the CPAN many probability and statistics modules, including some for calculating scores of different distributions.
Update 17:35 UTC: added the permutation example. |
Comment onMultinomial Distribution Test in PerlDownloadCode