Covariance Calculator

Covariance measures the direction of the linear relationship between two variables by showing how they move together relative to their respective means. When both variables tend to be above their means at the same time, covariance is positive. When one tends to be above its mean while the other is below, covariance is negative. A covariance near zero indicates little or no linear relationship. Unlike correlation, covariance is not constrained to a fixed scale, so a covariance of 1.5 could represent a weak relationship if the variables have large standard deviations, or a strong one if they are tightly distributed. This is why covariance is often used as a building block for other statistics, such as the Pearson correlation coefficient, rather than as a standalone measure. The key distinction between sample and population covariance is the denominator: population covariance divides by n (the number of pairs), while sample covariance divides by n minus 1. The n minus 1 version applies Bessel's correction to give an unbiased estimate when your data are a sample drawn from a larger population. Enter your x and y values as comma-separated lists of equal length and the calculator returns both versions of covariance, the mean of each variable, and the number of pairs used in the calculation. It suits students, researchers, and data analysts who need to check the direction and raw magnitude of association between two continuous variables before computing correlation or building a regression model.

Calculate.co.nz is proud to be partnered with Health Based Building, a leader in sustainable and health-conscious building innovation. With over a century of experience, they develop high-performance systems like Foreverbreathe Specification, Magnum Board, and Foreverbreathe Paints to support energy-efficient, non-toxic living environments. Their commitment to healthier homes aligns with our belief that informed choices lead to better outcomes for Kiwi households.
Calculate.co.nz partner: Health Based Building
Advertise on this page
1.5000
sample covariance
Population covariance1.2000
Mean of x3.0000
Mean of y4.0000
Pairs (n)5

How it works

The calculator parses the two comma-separated lists and takes the shorter length as n. It computes the mean of x and the mean of y. For each pair it calculates (xi minus x-bar) times (yi minus y-bar) and sums those products. Population covariance is that sum divided by n. Sample covariance divides by n minus 1 instead, applying Bessel's correction to reduce bias when working with a sample rather than the whole population.

Worked example

With x values 1, 2, 3, 4, 5 and y values 2, 4, 5, 4, 5, the mean of x is 3 and the mean of y is 4. The sum of (xi minus 3) times (yi minus 4) across all five pairs is (1-3)(2-4) + (2-3)(4-4) + (3-3)(5-4) + (4-3)(4-4) + (5-3)(5-4) = 4 + 0 + 0 + 0 + 2 = 6. Population covariance is 6 / 5 = 1.2000. Sample covariance is 6 / 4 = 1.5000. These match the default values pre-filled above.

Related calculators