Statistics
Sample covariance
stats.sample-covarianceAlso called sample covariance, covariance, cov, unbiased covariance
where
where
Unbiased estimate of the covariance of two paired samples, dividing by n − 1.
Notation
first variable
x ∈ ℝn
second variable
y ∈ ℝn
number of observations
Size, at least 2
Result: the sample covariance
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 3.66666666667
Given
Result
Given
Result
Common mistakes
Divides by n instead of n − 1
This is the population covariance (np.cov with bias=True); the result is (n − 1)/n times the sample value.
Fix: Divide by n − 1.
Source
Casella and Berger 2002
Casella, George; Berger, Roger L. Statistical Inference. 2nd ed. Duxbury, 2002.