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.
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
- Correlation Coefficient Calculator: standardise covariance to get Pearson r on a -1 to +1 scale.
- Coefficient of Variation Calculator: compare variability as a proportion of the mean.
- Standard Error Calculator: estimate the precision of a sample mean.
- Percent Error Calculator: measure deviation from an accepted reference value.