Howdy fellow monks,
I am trying to implement the hypergeometric probability in Perl. The general form of the equation is given, for instance, in the second page of this article, under the heading "Interpretation of Clusters".
Since the values can get quite large, I thought I would implement using Math::Big and Math::BigFloat, but I seem to have a misunderstanding or a bug somewhere that I cannot track down. The code is below. The symptom is that the value of $delta through each loop iteration is 0, and the final probability value is always one. When I do some calculations manually I get distinctly nonzero $delta for the last few loop iterations. Can anyone see what's I've done wrong?
use strict;
use Math::BigFloat;
use Math::Big;
my $G = 40; #$ARGV[0];
my $C = 25; #$ARGV[1];
my $n = 15; #$ARGV[2];
my $k = 14; #$ARGV[3];
sub choose {
my $temp = Math::BigFloat>new('1');
$temp = Math::Big::factorial($_[0]) /
Math::Big::factorial ($_[0]  $_[1]) /
Math::Big::factorial($_[1]);
return $temp;
}
my $p = Math::BigFloat>new('1');
my $denom = Math::BigFloat>new(choose($G, $n));
for (my $i = 0; $i < $k; $i++) {
my $val1 = $G  $C;
my $val2 = $n  $i;
my $delta = Math::BigFloat>new();
$delta = choose($C, $i) * choose($val1, $val2) / $denom;
print "$delta\n";
$p = $delta;
}
print "Probability estimate: $p\n";
Tats
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, 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, 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: 
 &   & 
 <   < 
 >   > 
 [   [ 
 ]   ] 
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.

