How to calculate the correlation coefficient of two random variables with cov function?
cov(x,y)=EXY-EX*EY
The definition of covariance, EX is the mathematical expectation of random variable x, and EXY is the mathematical expectation of XY, which is more troublesome. I suggest you look at the probability theory CoV (x, y) = exy-ex * ey.
The definition of covariance, EX is the mathematical expectation of random variable x, and EXY is the mathematical expectation of XY, which is more troublesome. I suggest you take a look at probability theory.
For example:
Xi 1. 1.93
Yi 5.0 10.4 14.6
e(X)=( 1. 1+ 1.9+3)/3 = 2
e(Y)=(5.0+ 10.4+ 14.6)/3 = 10
e(XY)=( 1. 1×5.0+ 1.9× 10.4+3× 14.6)/3 = 23.02
Cov(X,Y)= E(XY)-E(X)E(Y)= 23.02-2× 10 = 3.02
In addition, we can also calculate: d (x) = e (x 2)-e 2 (x) = (1.1.2+1.9 2+3 2)/3-4 = 4.60-.
d(y)=e(y^2)-e^2(y)=(5^2+ 10.4^2+ 14.6^2)/3- 100= 15.44σy = 3.93
Correlation coefficient of x and y:
r(X,Y)=Cov(X,Y)/(σXσY)= 3.02/(0.77×3.93)= 0.9979
Explain that the correlation between this set of data x and y is very good!