3
$\begingroup$

I am really new to probability and statistics. I have been wondering how common it is for two random vectors to be highly correlated. Correlations of exactly zero and one must have very low probabilities but how do the correlations in between behave? Correlations close to 0 should be easier to find that those close to 1.

I don't really know how to estimate this analytically so I decided to try this in R. I computed the correlation of 100 pairs randomly drawn from a uniform distribution and looked for the maximum correlation; I performed this process 1000 times.

I tried the following code:

m<-vector()
for(j in 1:1000)
{
  r=100
  c=100
  cm<-vector()
  x<-matrix(NA,r,c)
  y<-matrix(NA,r,c)
  for(i in 1:c){x[,i]<-runif(100)}
  for(i in 1:c){y[,i]<-runif(100)}
  for(i in 1:c){cm[i]<-cor(x[,i],y[,i])}
  m[j]<-max(abs(cm))
}

The maximum correlation value I found (after doing this a couple of times) was always below 0.5; the average maximum value was always close to 0.27. The histogram looks like this:

Histogram

The QQNorm looks like this:

QQNorm

Here are my questions:

(1) Is my code OK or am I introducing some systematic error destroying randomness?

(2) If the code is OK, why is no correlation higher than 0.5?

(3) Why is the average maximum correlation always close to 0.27?

(4) Is 0.27 the expected value of the correlation between two runif?

(5) I don't know how to perform formal tests but the maximum correlation for each run looks like a normal distribution. Why is this the case? How does this relate to the CLT?

$\endgroup$
1
  • $\begingroup$ Your introductory remarks are confusing: in what sense could one mean that a "correlation ... [has] very low probabilities"? After all, given any finite set of random variables $X_1,\ldots X_n,$ if you were to sample two of them with equal probabilities, the chance their correlation is $1$ would be $1/n$: this occurs whenever you pick the same variable twice! $\endgroup$
    – whuber
    Commented Nov 14, 2018 at 15:41

1 Answer 1

4
$\begingroup$
  1. Your code is OK.

  2. Because the true correlation is 0 (based on your code, $X$ and $Y$ have no any relation, so their correlation should be 0) and your sample size is as large as 100, so the chance to get the sample |r| > 0.5 is very lower.

3,4. You used max(abs(cm)), so it is the mean of maximum of absolute sample correlation coefficient. Its expectation could be derived, but it should be hard, because absolute value function is hard to deal with mathematically, and maybe it is close to 0.27.

  1. The histogram and QQplot do not like normal distribution because there is heavy tail on right side or the distribution is right skewed. If you want, you can use Kolmogorov-Smirnov Test.
$\endgroup$
3
  • $\begingroup$ (2) What do you mean by true correlation? $\endgroup$
    – Zweifler
    Commented Nov 14, 2018 at 19:50
  • $\begingroup$ based on your code, X and Y have no any relation, so their correlation (true correlation) should be 0 $\endgroup$
    – user158565
    Commented Nov 14, 2018 at 20:04
  • $\begingroup$ If you want to create true correlation not be zero X and Y, consider for(i in 1:c){y[,i]<-runif(100)+x[,i]} $\endgroup$
    – user158565
    Commented Nov 14, 2018 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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