Calculating Pearson correlation using the
cor.test() function in R, I found that the p-value does not necessarily correspond to the CI:
# reproducible example # generate the data set.seed(123) N <- 200 X <- rnorm(N) a <- 0.2 b <- 0.8 sigma <- 4 eps <- rnorm(N, 0, sigma) Y <- a + b * X + eps Y <- 23.70932 # change a bit cor.test(X, Y)
The resultant CI says the correlation is significant, while the p-value says otherwise:
t = 1.9717, df = 198, p-value = 0.05004 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.00002440203 0.27226422569 sample estimates: cor 0.1387649
The difference is small, but still quite large to be explained as a numerical error. This test does produce two-tailed test (for both the CI and the p-value) with the CI level of 0.95. Corresponding one-tailed test would be like this:
Y <- 37.692 cor.test(X, Y, alternative = "greater")
with a similar problem. I tried to use the parameter
exact = TRUE, but that's not related to the default calculation of Pearson correlation coefficient.
So, is this just a big imprecision (probably a bug, since the cor.test function doesn't provide any tolerance/epsilon parameter, which it should probably specify with this quite large imprecision?). Is the imprecision caused by not using an exact distribution of pearson coefficient, but just some approximations, that would yield slightly different results when calculating CI and p-value? Or is there some other principial problem?