# Correlation of random variables

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: The QQNorm looks like this: 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?

• 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! – whuber Nov 14 '18 at 15:41

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.
• 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]} – user158565 Nov 14 '18 at 20:56