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?