# p-value for hypothesis test with given correlation, sample size

I'm writing a statistical tool in Java. Here I'm calculation pearson correlation values (r). My next step is to validate if my correlation values are good enough to prove that my to variables are correlated. So I have two approaches in mind:

a) since I have the sample size = n and the correlation = r already calculated, I could use the these values to calculate the p-value and validate if p<alpha (level of significance) But for this approach I'm missing the formula for calculating the p-value

b) Since I'm planning to use a fixed alpha, I was thinking of precalculating the minimum r_min for given n. (e.g n=1 -> n=10000) and then check the calculated r against the precalculated r_min.

Does anyone know about a good solution for this Problem? I already found this but here as far as I see it, the library needs to recalculates the r with would take the performance down.

• I'll add that an issue with approach b is that it doesn't account for statistical significance. Intuitively, a dataset with two points would generate a line-of-best fit that has an r of exactly 1, but we both know such a value is not statistically significant. David Robinson's test statistic for inference on the correlation coefficient is probably the most valid approach. Jan 31, 2013 at 14:53

As described here, you can use the formula

to get a test statistic t, where n is the sample size and r is the calculated correlation. This test statistic t will follow a Student's t-distribution in the null hypothesis, so you can use it to compute a p-value.

However, note that this will not be as robust as using the traditional permutation or bootstrap p-value calculations for the significance of the correlation coefficient- that is, it assumes that both covariates have a normal distribution. If the data deviate from that assumption, this calculation might be unreliable.

• you are right, with t and n I would be able to calculate the p-value, however I'm still missing an efficient implementation to calculate the actual p-value
– Hellski
Jan 30, 2013 at 17:51
• @Hellski: You could simply use TDistribution.cumulativeProbability here. Jan 30, 2013 at 18:31
• You could use the formula just under the one that David uses (on the page he points to) with your method 2 to calculate critical values using tools that already have the information on the t-distribution, then just hard code the resultsing correlations for each sample size for comparison. Jan 31, 2013 at 20:23
• thank you all for your comments. I will think about the best way to fit my problem. But anyway the problem is solved. Feb 18, 2013 at 10:36