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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "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 http://www.stat.math.ethz.ch/~maechler/ 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._