# Pearson correlation critical level values formula

As statistics is not my domain, I have got hard time to find and understand all missing pieces. I have seen many tables with critical levels for pearson-r but I can't find any formula I can trust. What I need is to generate this kind of table but for any value I wish:

df\p  0,1    0,05    0,02    0,01    0,001
-------------------------------------------
1   0,98769 0,99692 0,99950 0,9998  0,99999
2   0,90000 0,95000 0,98000 0,9900  0,99900
3   0,8054  0,8783  0,93433 0,95873 0,99116
4   0,7293  0,8114  0,8822  0,91720 0,97406
5   0,6694  0,7545  0,8329  0,8745  0,95074
6   0,6215  0,7067  0,7887  0,8343  0,92493
7   0,5822  0,6664  0,7498  0,7977  0,8982
8   0,5494  0,6319  0,7155  0,7646  0,8721
9   0,5214  0,6021  0,6851  0,7348  0,8471
10  0,4973  0,5760  0,6581  0,7079  0,8233
11  0,4762  0,5529  0,6339  0,6835  0,8010
12  0,4575  0,5324  0,6120  0,6614  0,7800
13  0,4409  0,5139  0,5923  0,6411  0,7603
14  0,4259  0,4973  0,5742  0,6226  0,7420
15  0,4124  0,4821  0,5577  0,6055  0,7246
16  0,4000  0,4683  0,5425  0,5897  0,7084
17  0,3887  0,4555  0,5285  0,5751  0,6932
18  0,3783  0,4438  0,5155  0,5614  0,6787
19  0,3687  0,4329  0,5034  0,5487  0,6652
20  0,3598  0,4227  0,4921  0,5368  0,6524
25  0,3233  0,3809  0,4451  0,4869  0,5974
30  0,2960  0,3494  0,4093  0,4487  0,5541
35  0,2746  0,3246  0,3810  0,4182  0,5189
40  0,2573  0,3044  0,3578  0,3932  0,4896
45  0,2428  0,2875  0,3384  0,3721  0,4648
50  0,2306  0,2732  0,3218  0,3541  0,4433
60  0,2108  0,2500  0,2948  0,3248  0,4078
70  0,1954  0,2319  0,2737  0,3017  0,3799
80  0,1829  0,2172  0,2565  0,2830  0,3568
90  0,1726  0,2050  0,2422  0,2673  0,3375
100 0,1638  0,1946  0,2301  0,2540  0,3211


More precisely I need piece of code (but not in R) to generate value for any N I need. For example for N = 79, p = 0.01, one-tailed (with steps N-2).

It would be great if someone explain how to calculate it step by step, post formula or just write piece of code (or pseudocode) easy to understand.

function criticalR(N, alpha){
return // this part I need;
}

console.log( criticalR(50, 0.02) ); // prints 0,5155

• Close voters (as off topic): please indicate why you believe this doesn't require statistical expertise to answer (as described in the help center under Programming) -- I find myself at a loss to guess why. Jan 26, 2019 at 2:35

The exact null distribution for a Pearson correlation where the variables are assumed to be bivariate normal and the null is $$\rho=0$$ will have the form of a shifted and scaled symmetric beta distribution - specifically, linearly transformed to (-1,1).

The explicit form of the density is given in the Wikipedia article on the Pearson correlation coefficient:

$$p(r) = \frac{(1-r^2)^{(n-4)/2}}{\operatorname{B}(1/2, (n-2)/2)}$$

where $$r$$ is the random variable (the sample correlation), $$n$$ is the sample size (number of observation-pairs) and $$B$$ is the (complete) beta function.

We can readily use the beta cdf and the inverse beta cdf (common in many stats packages) to give critical values and p-values by taking care of the linear transformation ourselves. Or if we're writing code from scratch many numerical libraries offer the incomplete beta function and its inverse, which can be used to do the same thing.

As an alternative, given the null hypothesis of population correlation of 0, a particular transformation of the sample correlation will have a t-distribution; if you're stuck using tables this will be particularly convenient, since t-tables are often more extensive than tables for the correlation coefficient.

This is also given in the same Wikipedia article linked above, in the section titled Testing using Student's t-distribution:

$$t=r{\sqrt {\frac {n-2}{1-r^{2}}}}$$

with $$n-2$$ degrees of freedom.

This relationship may be used to obtain p-values directly or it can be used to back out critical values if you want to build a larger table (though I question the need for tables at all, since t-distribution calculations are nearly ubiquitous in statistical software and numerical packages for languages) -- it is straightforward to make $$r^2$$ the subject: $$r^2=1-1/[1+t^2/(n-2)]$$, and hence to obtain critical values for $$r$$ from critical values for $$t$$.

As a check, the 1% two tailed critical value for a t with 80 df (i.e. with n=82) is 2.6387 and 1-1/[1+2.6387^2/(80)] is about 0.080065; the square root of that is 0.28296, which rounds off to the value in your table above (0.2830).

For moderate to large $$n$$ (say $$n>80$$ or so, depending on your tolerance for approximation) the normal approximation is quite good at typical significant levels (say near 5%). If you're using very small significance levels (perhaps to maintain a low familywise type I error rate), then it may take considerably larger sample size to have a good approximation from the normal, but if you're using a computer there's little reason not to calculate exactly using either the beta distribution or the transformation to a t-distribution (both of which are exact when the assumptions are true).

• I still analyse your answer, I think second part with example is quite clear, the question and problem I can see is that N is unknown input number - it can be 50, 101 or 183 (thats why I want to avoid big table and generate it instead) so I would need to store again table for t. I am not sure I understood first part - do I need correlation calculated for first formula? I am not sure how exactly the first formula can be used - I mean the r there isalready calculated correlation or the factor I need or just completely something else? Jan 26, 2019 at 3:11
• I can't follow the second half of your comment, sorry. If you want tables of critical values you won't have r values at all. If you have sample r's you'll presumably want to compute p-values. Which is it? Jan 26, 2019 at 3:43
• I need critical values, thats why 'r' in the first formula was confusing for me but if I understand correctly it's for reverse situation. I could find some library to get criticals but I need to understand also how it was made - someone generated big table of numbers and I had no idea from where it comes from. Anyway if I am correct I just need beta function to generate t values of normal distribution and then use the second formula, yes? Jan 26, 2019 at 3:57
• You'll either need a function for the inverse incomplete beta, or the inverse cdf for a t distribution (followed by the formula to convert t to r); As I already stated, many numerical libraries have the first. Stats libraries often have the second. An F inverse cdf would also work. Jan 26, 2019 at 4:39