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.

In reply to Re: Multinomial Distribution Test in Perl by Laurent_R
in thread Multinomial Distribution Test in Perl by ZWcarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.