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.

migrated from stackoverflow.comJan 31 '13 at 14:33

This question came from our site for professional and enthusiast programmers.

• 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. – AdamO Jan 31 '13 at 14:53 