t-test of the Pearson correlation in R

4.1k views Asked by At

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

1

There are 1 answers

0
cdeterman On BEST ANSWER

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:

t = r*sqrt((n-2)/(1-r^2))

Now, let's do some simplifying of the STATISTIC <- c(t = sqrt(df) * r/sqrt(1 - r^2))

df is in fact n-2

t = sqrt(n-2)*r/sqrt(1-r^2)

rewritten

t = r * sqrt(n-2)/sqrt(1-r^2)

Simplified

t = r*sqrt((n-2)/(1-r^2))

And you have your equivalence.