2

R offers three methods for correlations, Pearson, Spearman and Kendall. For speed I use cor(x, y) being x a matrix and y a vector of same length. I get back the correlation of all the variables on x with y (I can't do that with cor.test).

To calculate the p-value of these correlations I created a function for the Pearson correlation value and the number of samples using this formula $t = \frac{\hat{\rho}}{\sqrt{\frac{1-\hat{\rho}^2}{n-2}}}$. Will this p-value work for a Spearman or Kendall correlation too?

I don't fully grasp the formula and where does it comes from. And failed to find three different pairs of data that have the same correlation value for the three methods (aside from 0 and 1).

Nick Cox
  • 48,377
  • 8
  • 110
  • 156
llrs
  • 525
  • 5
  • 25
  • 1
    The `corr.test` function in package `psych` may already do what you are trying to program yourself: https://www.rdocumentation.org/packages/psych/versions/2.0.12/topics/corr.test Alternatively `rcorr` in `Hmisc`: https://rdrr.io/cran/Hmisc/man/rcorr.html – Bernhard Feb 17 '21 at 14:30
  • Didn't know about psych, indeed it does what I was doing. Thanks! But still, would like to understand the p-values of each method. – llrs Feb 17 '21 at 14:47
  • 2
    I would have posted an answer had I thought, this was a suitable answer. For practical purposes, though, it might be better so stay with good packages such as `psych` or `Hmisc`. – Bernhard Feb 17 '21 at 14:49

0 Answers0