MathorynMathematical Formula Database

Statistics & Probability

Sample Covariance

Covariance measures how two variables vary together: it is positive when they tend to increase together and negative when one rises as the other falls. It is used to compute correlation and regression slopes and in multivariate statistics.

cov⁡(x,y)=1n−1∑i=1n(xi−xˉ)(yi−yˉ)\operatorname{cov}(x,y)=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar x)(y_i-\bar y)
LaTeX\operatorname{cov}(x,y)=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar x)(y_i-\bar y)

Variables

xi, yix_i,\ y_i
paired observations
xˉ, yˉ\bar x,\ \bar y
sample means
nn
number of pairs

Example

Find the covariance of x=1,2,3x=1,2,3 and y=2,4,5y=2,4,5.

  1. xˉ=2\bar x=2, yˉ=113\bar y=\frac{11}{3}.
  2. ∑(xi−xˉ)(yi−yˉ)=3\sum(x_i-\bar x)(y_i-\bar y)=3.
  3. cov⁡=32\operatorname{cov}=\frac{3}{2}.

Answer: cov⁡(x,y)=1.5\operatorname{cov}(x,y)=1.5.

Related formulas