# Strange test of correlation!

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.

• Also, note that cor(x, y) is different from cor(x, y, method = "s"), which is why you're seeing different estimates of $\rho$ between the cor() and cor.test() calls. The default for both cor() and cor.test() is Pearson correlation. The argument method = "s" makes the function use Spearman correlation. For more, see, e,g, <stats.stackexchange.com/questions/259664/…> May 17 '18 at 15:39
• @DanHicks -- I noticed that. The help file suggests that Spearman's or Kendall's tests could be useful for samples with no independent normal distribution. I have a small sample with a different distribution, which seems to be the case. Thank you! May 17 '18 at 15:48
• Just for curiosity: Why to test for correlation between residuals and regressors? The sample correlation is 0 by construction (in a linear model). May 17 '18 at 15:53
• @MichaelM It is "dependent variable" (fitted values), instead of "independent". I'll edit that. May 17 '18 at 16:47
• Equally strange because also this correlation is 0 by construction ;-) May 17 '18 at 18:09