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:
If you are comfortable editing the corrcoef.m file, you can add Tstat as an additional output. This variable is computed inside the file but not returned.
Another alternative is to see how Tstat is computed and do that yourself outside the corrcoef.m file.
Best Answer