[Rd] cor.test(x,x) sometimes produce NaN (PR#1099)
maechler@stat.math.ethz.ch
maechler@stat.math.ethz.ch
Mon, 24 Sep 2001 14:00:06 +0200 (MET DST)
This *is* kind of a bug, hence diverted to R-bugs
>>>>> "Peter" == Peter Malewski <peter.malewski@gmx.de> writes:
Peter> In the code
>> for(i in 1:100){zz <- rnorm(10);print(cor.test(zz,zz))}
Peter> sometimes a sqrt(0) occures:
Peter> 24: NaNs produced in: sqrt(1 - r^2)
I found that the reason is that in (at least one of) those cases,
r == 1+eps
where eps = .Machine$double.eps
which I think is the real bug, here.
Here is a reproducible example:
> set.seed(125);z0 <- rnorm(40);zz <- round(rnorm(10),5); r <- cor(zz,zz)
> r-1
[1] 2.220446e-16
Peter> in all the other cases a result like
(for me, not in all, but quite a few cases)
Peter> t = Inf, df = 8, p-value = < 2.2e-16
which I think is entirely correct.
Peter> occurs. Does cor.test need some more "inf" - handling? I found
Peter> that calculating a cor-matrix with additional p-values.
(last sentence is a bit unclear to MM).
Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._