Bug in dhyper (and phyper) (fwd) -- and patch

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 3 Apr 1998 09:22:53 +0200

>>>>> "GB" == Goran Brostrom <gb@stat.umu.se> writes:

    GB> Last night I sent the bug report below to r-help. I have since then
    GB> looked at dhyper.c and found:

    GB>         if (NR < 0 || NB < 0 || n <= 0 || n > N) DOMAIN_ERROR;

    GB> I changed 'n <= 0' to 'n < 0' and then dhyper worked as I
    GB> wanted. Am I introducing some potentially dangerous behaviour by
    GB> this change?

No, I think your change was correct.
Thanks a lot for your fix!

I'm going to put your change into the 0.62 unstable version of R.

What's the typo in the documentation you mentioned (below, at the end)?
[you may answer to me privately..]

Martin Maechler <maechler@stat.math.ethz.ch>			<><
Seminar fuer Statistik, ETH-Zentrum SOL G1;	Sonneggstr.33
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086

    GB> ----------------------------------------------------------------------

    GB> I think I have found a bug in the function dhyper (R-0.61.2):

    R> dhyper(0,3,3,0)
    GB> Warning: NAs produced in function "dhyper" [1] NA

    GB> Documentation:

    GB> "Usage

    GB> dhyper(x, N1, N2, n)

    GB> .......

    GB> The hypergeometric distribution is used for sampling without
    GB> replacement.  It has density

    GB>   p(x) = Choose(N1, x) Choose(N2, n-x) / Choose(N1+N2, n)

    GB> for x = 0,...,n"

    R> choose(3,0) * choose(3,0) / choose(6,0)
    GB> [1] 1

    GB> This result is correct, and obviously dhyper is implemented in some
    GB> way not consistent with the documentation.

    GB> Also note the spelling error of 'choose' in the documentation.
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch