Correlation and independance
- The Correlation coefficient is defined as:
ρ=Cov(X,Y)√Var[X]Var[Y]
- If X and Y are independent, then the book proves they are uncorrelated:
Cov(X,Y)=0and soE[XY]=E[X]E[Y]
Note that this is “one way door”: Covariance can be zero for dependent variables.
Computing from data:
ˆρ=1N∑Nn=1xnyn−ˉxˉy√1N∑Nn=1(xn−ˉx)2√1N∑Nn=1(yn−ˉy)2
sigma <- matrix(c(3,1,1,1),nrow=2)
m <- mvrnorm(n=10000, mu=c(0,0), Sigma = sigma)
data <- tibble(x = m[,1], y=m[,2])
print(cor(data$x,data$y))
## [1] 0.5746705
## [1] 0.5773503