views:

510

answers:

3

Hi everyone,

I'm trying to calculate correlations in Perl. I found out how to calculate correlations between arrays in CPAN, but I can't seem to find out how to get the t-statistics and p-values of those correlations (R gives these automatically). Is that even possible in Perl? I hope someone can help because I need to determine the significance of the correlations. Many thanks in advance!

-Abdel

+3  A: 

This might help. The p value is basically whether the correlation coefficient is significantly different from 0 or not, so this is a t test: t=r/sqrt[(1-r²)/(N-2)] with n-1 degrees of freedom. Again Math::GSL will get the p value of t for you.

singingfish
Clarification: The p-value for the correlation coefficient is the probability of obtaining a correlation coefficient that is as far away from zero as the one you obtained purely due to random sampling error conditional on the hypothesis that the true correlation coefficient is zero. We say that the correlation is statistically different from zero when that probability is small enough.
Sinan Ünür
Thanks, that formula for the t-statistic is what I needed! I'll try to program that in and see if it works!
Abdel
Isn't the degrees of freedom N-2 though?
Abdel
+2  A: 

Statistics::Distributions can help you with that.

Sinan Ünür
+1  A: 

Is Statistics::LineFit what you are searching for?

Anon