MATLAB Answers

How to calculate correlation p-value?

26 views (last 30 days)
Ritankar Das
Ritankar Das on 26 May 2016
Edited: the cyclist on 1 Jun 2021
I have a correlation matrix and have performed some filtering on it. Now I want to calculate the p-value of the filtered correlation matrix. Can anyone help we with the code. [R,P]=corrcoef(A) returns both the correlation matrix as well as the p-value matrix, but I already have the correlation matrix, and just want to calculate the p-value matrix.
Thank you in advance. Ritankar.

Answers (2)

the cyclist
the cyclist on 26 May 2016
You cannot calculate a P-value from only a correlation matrix. You need the underlying data. The reason why is pretty easy to understand ... The correlation matrix could have come from a dataset with maybe N=10 measurements, or perhaps N=100000 measurements. These will (almost certainly) have different P-values.

Anil Kamat
Anil Kamat on 30 May 2021
Edited: Anil Kamat on 30 May 2021
Lets say
N --> no.of the observations / data points
r --> assumed corr.coef
t = r*sqrt((N-2)/(1-r^2)); % find t-statistics
p1 = 1 - tcdf(t,(N-2)) % find pvalue using Student's t cumulative distribution function for one sample test.
https://www.mathworks.com/help/stats/tcdf.html
  1 Comment
the cyclist
the cyclist on 1 Jun 2021
Can you help me understand that your formula is correct? Here is a correlation coefficient calculated from a randome dataset, and then your calculation. (I modified your formula only to make meaningful variable names.)
rng default
N = 1000;
x = randn(N,2);
[correlationMatrix,pMatrix] = corrcoef(x);
pValueFromOriginalData = pMatrix(1,2);
correlationCoefficient = correlationMatrix(1,2);
t = correlationCoefficient*sqrt((N-2)/(1-correlationCoefficient^2)); % find t-statistics
p_from_anil = 1 - tcdf(t,(N-2)); % find pvalue using Student's t cumulative distribution function for one sample test
sprintf('p-value from original data = %7.4f',pValueFromOriginalData)
ans = 'p-value from original data = 0.7695'
sprintf('p-value from Anil = %7.4f',p_from_anil)
ans = 'p-value from Anil = 0.6153'
They give different results.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by