MATLAB: How to get p-val from correlation coefficient and number of sample

correlationp-val

Hi, all!
We know that in MATLAB, [r,p]=corrcoef(A) could return the correlation coefficient and p-val.
But who knows how p-val is calculated, what is the formulas?
Thanks for your help!

Best Answer

The p-value is based on a t statistic
t = r* sqrt((n-2)/(1-r^2))
which has n-2 degrees of freedom.
You can find a discussion of the sampling distribution of r both when the null hypothesis is that r=0 and when you are testing for nonzero values of r here: