[R] cor < -1

Oliver Soong osoong at gmail.com
Sun May 18 21:16:13 CEST 2008


I'm having what looks like a quantization problem with cor on R 2.7.0.
 I get warnings from cor.test because r < -1.  R session output is at
the bottom.  A simple fix would be to add the appropriate checks to
the end of the internal cor code.

Oliver


> x <- c(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
> y <- c(1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1)
> cor.test(x, y)

        Pearson's product-moment correlation

data:  x and y
t = NaN, df = 13, p-value = NA
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 NaN NaN
sample estimates:
cor
 -1

Warning messages:
1: In sqrt(1 - r^2) : NaNs produced
2: In atanh(r) : NaNs produced
> cor(x, y) < -1
[1] TRUE
> cor(x, y) + 1
[1] -2.220446e-16
> .Internal(cor(x, y, 1, FALSE)) < -1
[1] TRUE
> .Internal(cor(x, y, 3, FALSE)) < -1
[1] FALSE



More information about the R-help mailing list