Skip to content

Correlation vs covariance

5 min read

Short answer

Covariance measures how two variables vary together, but its size depends on the units. Correlation rescales it: ρ=Cov⁡(X,Y)σXσY\rho=\dfrac{\operatorname{Cov}(X,Y)}{\sigma_X\sigma_Y}, which always lies between −1-1 and 11. Correlation near ±1\pm1 means a strong linear relationship; near 0 means little linear relationship.

Covariance compared with CorrelationCovarianceCov(X, Y)Any size, has unitsSign gives directionChanges if you rescaleHard to compareCorrelationρ = Cov / (σx σy)Always in [−1, 1]Sign gives directionUnchanged by rescalingEasy to compare
Correlation is covariance with the units divided out, so it is the one to compare across different datasets.

Reading correlation

ρ=1\rho=1 is a perfect increasing line, ρ=−1\rho=-1 a perfect decreasing line, and ρ=0\rho=0 means no linear association. Squared, ρ2\rho^2 is the fraction of variation in one variable explained by a linear fit to the other.

What it cannot tell you

Correlation does not mean causation, can be produced by a third hidden factor, is thrown off by outliers, and misses curved relationships. Always look at a scatter plot as well as the number.

Worked example

For the data x=(1,2,3)x=(1,2,3) and y=(2,4,5)y=(2,4,5), compute the sample covariance and correlation.

xˉ=2\bar x=2, yˉ=113\bar y=\tfrac{11}3. Deviations: xx: −1,0,1-1,0,1; yy: −53,13,43-\tfrac53,\tfrac13,\tfrac43.

Sxy=(−1)(−53)+0+(1)(43)=3S_{xy}=(-1)(-\tfrac53)+0+(1)(\tfrac43)=3, Sxx=2S_{xx}=2, Syy=25+1+169=143S_{yy}=\tfrac{25+1+16}9=\tfrac{14}3.

Sample covariance =Sxyn−1=1.5=\tfrac{S_{xy}}{n-1}=1.5. r=SxySxxSyy=32⋅14/3=328/3≈0.982.r=\frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}=\frac3{\sqrt{2\cdot14/3}}=\frac{3}{\sqrt{28/3}}\approx0.982. A very strong positive linear relationship.

Try it yourself

If the covariance of XX and YY is 12, σX=3\sigma_X=3 and σY=5\sigma_Y=5, what is the correlation?

Show the answer

ρ=123⋅5=0.8\rho=\dfrac{12}{3\cdot5}=0.8, a strong positive linear relationship.

Keep going with practice

Covariance and correlation connect Vidi's probability lessons to the symmetric matrices of its linear algebra lessons.