Jeremy Miles
2014-10-16 23:32:08 UTC
I'm trying to understand how cor.test() is calculating the p-value of
a correlation. It gives a p-value based on t, but every text I've ever
seen gives the calculation based on z.
data: speed and dist
t = 2.3893, df = 8, p-value = 0.04391
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.02641348 0.90658582
sample estimates:
cor
0.6453079
My p-value is different. The help file for cor.test doesn't (seem to)
have any reference to this, and I can see in the source code that it
is doing something different. I'm just not sure what.
Thanks,
Jeremy
a correlation. It gives a p-value based on t, but every text I've ever
seen gives the calculation based on z.
data(cars)
with(cars[1:10, ], cor.test(speed, dist))
Pearson's product-moment correlationwith(cars[1:10, ], cor.test(speed, dist))
data: speed and dist
t = 2.3893, df = 8, p-value = 0.04391
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.02641348 0.90658582
sample estimates:
cor
0.6453079
r <- cor(cars[1:10, ])[1, 2]
r.z <- fisherz(r)
se <- se <- 1/sqrt(10 - 3)
z <- r.z / se
(1 - pnorm(z))*2
[1] 0.04237039r.z <- fisherz(r)
se <- se <- 1/sqrt(10 - 3)
z <- r.z / se
(1 - pnorm(z))*2
My p-value is different. The help file for cor.test doesn't (seem to)
have any reference to this, and I can see in the source code that it
is doing something different. I'm just not sure what.
Thanks,
Jeremy