Solved – Significance test for Pearson Correlation Coefficient

correlationMATLABrstatistical significance

How can I compute the significance test (P value) for the correlation coefficient (r) using R or Matlab? i.e Can anybody help me with the suitable code to compute the p value for the correlation coefficient in R or Matlab?

The output of the calculators available online to compute p value for r is totally different! That's why I am looking for a trusted code to compute it using R or Matlab

Best Answer

Say r <- cor(x, y) n<-length(x)

Two-tailed tests:

  1. Testing using Student's t-distribution:

t<-r*sqrt((n-2)/(1-r^2)) p<-2*pt(-abs(t),n-2)

  1. Using the Fisher transformation

z<-(atanh(r)-0)*sqrt(n-3) p<-2*pnorm(-abs(z))