Math::NumberCruncher-5.00 bug

W

WCR.III

Just a note to stuff this into the 'net consciousness, since I
can't find it mentioned anywhere else.

The SignSignificance calculation in Math::NumberCruncher
has a bug.

currently the code looks like this:


my ( $trials, $hits, $probability ) = @_;
return undef unless defined $trials && defined $hits &&
defined $probability;
my $confidence;
foreach ( $hits .. $trials ) {
$confidence += Binomial( $trials, $hits, $probability );
}
return $confidence;


Unfortunately, the confidence isn't calculated properly - the
middle operand to Binomial needs to iterate from $hits to $trials.
To fix, do something like this instead:


my ( $trials, $hits, $probability ) = @_;
return undef unless defined $trials && defined $hits &&
defined $probability;
my ($confidence, $ahit, $aconf);
$confidence = 0;
foreach ($ahit = $hits;$ahit <= $trials;$ahit++)
{
$aconf = Binomial( $trials, $ahit, $probability );
# print STDERR "numcrunch binomial returns: $hits $ahit $trials $aconf\n";
$confidence += $aconf;
}
return $confidence;


Yes, it's clunky and looks like C by Perl standards. It also
doesn't have bugs introduced because implied automatic
variables are being (mis) used :)

I informed the module maintainer of this problem some time
ago, but a recent re-install of the module demonstrated that
the fix hadn't made it into the code yet.
Just another C hacker...
Will Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top