Covariance Calculator

Next

Covariance measures how two variables vary together. Positive covariance means they tend to move in the same direction, negative means they move opposite, and zero means no linear relationship. Unlike correlation, covariance is in the original units squared, so its magnitude is hard to interpret without context. This calculator returns both the sample covariance (dividing by n-1) and the population covariance (dividing by n).

How to calculate covariance

  1. 1

    Paste paired X/Y data

    One X and one Y per row. Comma, tab or space separated. Same count in each column.

  2. 2

    See both results

    The calculator always shows both: the sample covariance (dividing by n-1) and the population covariance (dividing by n).

  3. 3

    Run the calculation

    The calculator computes the means, the cross-deviations, and divides by n or n-1.

  4. 4

    Read the result

    Read the two covariance values. A positive value means the variables tend to move together, a negative value means they move in opposite directions.

Formulas

Sample covariance: cov(X, Y) = Σ((xᵢ - x̄)(yᵢ - ȳ)) / (n - 1)

Population covariance: cov(X, Y) = Σ((xᵢ - x̄)(yᵢ - ȳ)) / n

The n - 1 divisor (Bessel’s correction) makes the sample covariance an unbiased estimator of the population covariance. Statistical software defaults to the sample version.

The sign is what matters

Sign Meaning
Positive X and Y tend to be above/below their means together
Negative X above mean tends to pair with Y below mean
Zero No linear pattern (could still be non-linear)

The magnitude depends on the units: cov(height_cm, weight_kg) for adults is roughly +70, but change to height in metres and it drops to +0.7, same relationship, different number. This is why correlation is more commonly reported.

Covariance vs. correlation

correlation = covariance / (σ_X × σ_Y)

Correlation is the unit-free version, always in [-1, +1], comparable across datasets. Covariance is mostly useful inside formulas (portfolio variance, regression, PCA) rather than as a summary statistic.

Where covariance is used directly

  • Portfolio theory: portfolio variance = Σ wᵢ wⱼ cov(rᵢ, rⱼ). You need covariance, not correlation, because the weights and variances matter.
  • Linear regression: the slope estimate β = cov(X, Y) / var(X).
  • Principal component analysis (PCA): the covariance matrix is what gets diagonalised.
  • Signal processing: cross-covariance measures similarity between signals at different lags.

Common mistakes

  • Mixing n and n-1: sample and population covariance can differ by a few percent on small datasets and cause reproducibility issues. Decide which you need and state it.
  • Interpreting magnitude: a covariance of 50 is not “big” on its own; it depends entirely on the units and variance of X and Y.
  • Assuming zero covariance = independence: zero covariance means no linear relationship. Two variables can have covariance 0 and still be perfectly predictable non-linearly (e.g., Y = X² on symmetric X).

Frequently Asked Questions

Sample (divide by n-1) when your data is a sample of a larger population, the normal case in research. Population (divide by n) only when your dataset literally contains every possible observation. Default to sample unless you are sure.

Because covariance is in the product of the two units. If X is in dollars and Y is in units, covariance is in dollar-units. Convert to correlation (divide by σ_X × σ_Y) if you want a unit-free number.

No. |cov(X, Y)| ≤ σ_X × σ_Y (Cauchy-Schwarz). Equality holds only when Y is a perfect linear function of X. If your calculator shows a larger covariance, there is a bug.

Not necessarily. Zero covariance means no linear relationship. Y = sin(X) over [0, 2π] has covariance 0 with X but is perfectly determined. Only for jointly normal variables does zero covariance imply independence.

Related Tools