# 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.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  -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/…> – Dan Hicks 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! – André Oliveira 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). – Michael M May 17 '18 at 15:53
• @MichaelM It is "dependent variable" (fitted values), instead of "independent". I'll edit that. – André Oliveira May 17 '18 at 16:47
• Equally strange because also this correlation is 0 by construction ;-) – Michael M May 17 '18 at 18:09

## 1 Answer

You have your interpretation of the p-values exactly backwards. Small p-values (<0.05, generally) mean that you should reject the null hypothesis, meaning your correlation is significantly different from 0. The p-value is telling you that it's very unlikely that you'd observe this much correlation if the null hypothesis (no correlation) was true. Large p-values (>0.05) indicate that you don't have sufficient evidence to reject the null hypothesis, meaning that you cannot conclude that you have non-zero correlation.

Your first case with near-zero correlation has a p-value of 0.66, meaning you cannot reject the null hypothesis of 0 correlation. Your second case has a significant p-value (close to 0), meaning you should reject the null hypothesis of no correlation, and accept the alternative hypothesis that the correlation is not equal to 0.

• Oh, such a kids mistake... I think I got confused because the test prints "alternative hypothesis", while I had in mind the null hypothesis. Thank you! – André Oliveira May 17 '18 at 15:38
• The test output is simply telling you whether the alternative you had is one or two tailed; that's the only reason it mentioned the alternative. – Glen_b May 17 '18 at 23:15
• @Glen_b Yeah, I noticed that latter, when I chose "greater" instead of "two tailed". Thank you anyway. – André Oliveira May 21 '18 at 17:32