R-beta: Bug in dhyper (and phyper) (fwd)
Goran Brostrom
gb@stat.umu.se
Fri, 3 Apr 1998 09:20:07 +0200 (MET DST)
Last night I sent the bug report below to r-help. I have since then looked
at dhyper.c and found:
if (NR < 0 || NB < 0 || n <= 0 || n > N)
DOMAIN_ERROR;
I changed 'n <= 0' to 'n < 0' and then dhyper worked as I wanted. Am I
introducing some potentially dangerous behaviour by this change?
Goran
----------------------------------------------------------------------
I think I have found a bug in the function dhyper (R-0.61.2):
R> dhyper(0,3,3,0)
Warning: NAs produced in function "dhyper"
[1] NA
Documentation:
"Usage
dhyper(x, N1, N2, n)
.......
The hypergeometric distribution is used for sampling without replacement.
It has density
p(x) = Choose(N1, x) Choose(N2, n-x) / Choose(N1+N2, n)
for x = 0,...,n"
R> choose(3,0) * choose(3,0) / choose(6,0)
[1] 1
This result is correct, and obviously dhyper is implemented in some way
not consistent with the documentation.
Also note the spelling error of 'choose' in the documentation.
---
Goran Brostrom phone : +46 90 7865223
Department of Statistics 7865213 (secr)
Umea University fax : 7866614
S-90187 Umea, Sweden e-mail: gb@stat.umu.se
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._