1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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/…> $\endgroup$ – Dan Hicks May 17 '18 at 15:39
  • $\begingroup$ @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! $\endgroup$ – André Oliveira May 17 '18 at 15:48
  • 1
    $\begingroup$ Just for curiosity: Why to test for correlation between residuals and regressors? The sample correlation is 0 by construction (in a linear model). $\endgroup$ – Michael M May 17 '18 at 15:53
  • $\begingroup$ @MichaelM It is "dependent variable" (fitted values), instead of "independent". I'll edit that. $\endgroup$ – André Oliveira May 17 '18 at 16:47
  • $\begingroup$ Equally strange because also this correlation is 0 by construction ;-) $\endgroup$ – Michael M May 17 '18 at 18:09
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – André Oliveira May 17 '18 at 15:38
  • $\begingroup$ 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. $\endgroup$ – Glen_b May 17 '18 at 23:15
  • $\begingroup$ @Glen_b Yeah, I noticed that latter, when I chose "greater" instead of "two tailed". Thank you anyway. $\endgroup$ – André Oliveira May 21 '18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.