I had a strange correlation test result between two variables ($y$ = residuals of a linear regression, $x$ = dependent variable).
In RStudio, cor(y0,x0)
, which answer is [1] -1.676535e-16
Oh, ok, I have almost zero correlation!
I decided to test that, and discovered cor.test()
function, for which follows:
cor.test(y0, x0, method = "s")
Spearman's rank correlation rho
data: y0 and x0
S = 1076, p-value = 0.6623
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.1104231
If p-value = 0.66 $\Rightarrow$ reject null hypothesis (true rho equal to 0) $\Rightarrow$ true rho isn't zero
And rho = -0.11. Cool! It seems that $y_0$ and $x_0$ are correlated in some way.
But I tried another example:
Again, in RStudio, cor(y1,x1)
, which answer is [1] -0.6859127
Spearman's rank correlation rho
data: y1 and x1
S = 1100, p-value < 2.2e-16
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.9642857
If p-value < 2.2e-16 ~ 0 $\Rightarrow$ accept null hypothesis (true rho equal to 0)
But rho = -0.96
How can I accept null hypothesis if rho ($\rho$) is nearly -1?
That does not make any sense to me.
cor(x, y)
is different fromcor(x, y, method = "s")
, which is why you're seeing different estimates of $\rho$ between thecor()
andcor.test()
calls. The default for bothcor()
andcor.test()
is Pearson correlation. The argumentmethod = "s"
makes the function use Spearman correlation. For more, see, e,g, <stats.stackexchange.com/questions/259664/…> $\endgroup$