While looking at the cor.test function in R, used to compute (among others) the Pearson correlation, I saw that the t-statistics, used later to calculate the p-value is
STATISTIC <- c(t = sqrt(df) * r/sqrt(1 - r^2))
where r is the correlation measure, and df is the number of degrees of freedom.
But the t-test for a Pearson correlation seems rather to be: (cf. http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient#Testing_using_Student.27s_t-distribution)
sqrt( ( n - 2 ) / ( 1 - r^2 ) )
As always, given that the cor.test is widely used I suspect first a misunderstanding from my side. Does anyone know whether the definition used in cor.test is correct?
Thanks
If you look at the code a little further you will see that they are in fact equivalent.
Firstly, you forgot the
r
in your equation for wikipedia. You equation should be:Now, let's do some simplifying of the
STATISTIC <- c(t = sqrt(df) * r/sqrt(1 - r^2))
df
is in factn-2
rewritten
Simplified
And you have your equivalence.