[Rd] Problem with NAs using chisq.test() (PR#748)

kjetikj@astro.uio.no kjetikj@astro.uio.no
Sun, 26 Nov 2000 21:21:23 +0100 (MET)


Full_Name: Kjetil Kjernsmo
Version: 1.1.1.1 (patched the rpois :-))
OS: osf4.0e
Submission from: (NULL) (129.240.28.227)


Dear all,

I have just gotten through a debugging session of my code, being confused
for a few days. I sent what I thought was a straightforward matrix to
chisq.test() and once in a while got the error message:
> chisq.test(t2)
Error in chisq.test(t2) : missing value where logical needed

Now, it turned out that a fairly deep bug in my code occasionally produced
NAs in the matrix, and that was the source of the confusion. Looking at
the code, it is apparent that the test
    if (any(x < 0) || any(is.na(x)))
        stop("all entries of x must be nonnegative and finite")
was designed to catch this, but it doesn't seem to, because the first
any()-call is NA and so when using the operator ||, well, I bet you
understand this better than I... :-)

I figured, perhaps turn this around:
    if (any(is.na(x)) || any(x < 0))
        stop("all entries of x must be nonnegative and finite")
That seems to work: 
> chisq.test(t2)
Error in chisq.test(t2) : all entries of x must be nonnegative and finite

Now, I hope this was a true bug, not just one of my misunderstandings, and that
this is a real fix too.... :-)

Kjetil

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._