Karl Pearson's coefficient of correlation — also called the product moment or simple correlation coefficient — gives a precise numerical value for the degree of linear relationship between two variables X and Y. It should be used only when the relationship is linear; applied to a non-linear relation (as in figures 6.6 and 6.7) it can mislead. So one should examine the scatter diagram first.
Building blocks. For N paired values, the arithmetic means are
Xˉ=N∑X,Yˉ=N∑Y
Writing the deviations from the mean as x=X−Xˉ and y=Y−Yˉ, the variances are
σX2=N∑(X−Xˉ)2=N∑x2,σY2=N∑(Y−Yˉ)2=N∑y2
The standard deviations σX and σY are the positive square roots of these variances. The covariance is
Cov(X,Y)=N∑(X−Xˉ)(Y−Yˉ)=N∑xy
The sign of the covariance fixes the sign of the correlation coefficient (the standard deviations are always positive); if the covariance is zero, so is the correlation.
Four equivalent formulas for r.
r=σXσY∑xy/N(1)
r=∑(X−Xˉ)2∑(Y−Yˉ)2∑(X−Xˉ)(Y−Yˉ)(2)
r=∑X2−N(∑X)2∑Y2−N(∑Y)2∑XY−N(∑X)(∑Y)(3)
r=N∑X2−(∑X)2N∑Y2−(∑Y)2N∑XY−(∑X)(∑Y)(4)
Worked example (Example 1): years of schooling of farmers (X) vs annual yield per acre in '000 Rs (Y).
X
Y
X−Xˉ
(X−Xˉ)2
Y−Yˉ
(Y−Yˉ)2
(X−Xˉ)(Y−Yˉ)
0
4
-6
36
-3
9
18
2
4
-4
16
-3
9
12
4
6
-2
4
-1
1
2
6
10
0
0
3
9
0
8
10
2
4
3
9
6
10
8
4
16
1
1
4
12
7
6
36
0
0
0
Σ = 42
Σ = 49
112
38
42
Here N=7, so Xˉ=42/7=6 and Yˉ=49/7=7. Using formula (2): …