Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Howdy fellow monks,

I am trying to implement the hyper-geometric 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 non-zero $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

In reply to Hypergeometric Probability Calculation by Itatsumaki

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, 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:
    & &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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2020-12-04 01:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (58 votes). Check out past polls.

      Notices?