Skip to content
MasterMath

Covariance Calculator

The covariance of two variables, sample and population, alongside the correlation. Covariance gives the direction of the relationship; for the strength it has to be normalised.

Sample covariance

—

Sample covariance—
Population covariance—
Pearson correlation—
Direction of the relationship—
Pairs of values—
Means—
#XYPredicted Y

How this was worked out

    The formula

    cov = Σ(x − x̄)(y − ȳ) / (n − 1)

    What it means

    Covariance averages the product of the two deviations from their means. When x is above its mean and y is too, the products are positive and the covariance comes out positive; when they move opposite ways, negative. The problem is magnitude: covariance is in the product of the two units and its size depends on the scale, so a big number does not mean a strong relationship. That is what correlation is for: a normalised covariance.

    How to work it out by hand

    1. Work out the mean of each variable
    2. For each pair, multiply x's deviation by y's deviation
    3. Add all those products together
    4. Divide by n − 1 for the sample version, or by n for the population one

    What is worth knowing

    That covariance cannot be compared across different problems does not make it useless: it is the building block of the covariance matrix, and that matrix is at the heart of portfolio optimisation, principal component analysis and much of multivariate statistics. What you should not do is interpret it on its own: if you want to say "they move together a lot", the number to quote is the correlation.

    Frequently asked questions

    How does it differ from correlation?

    Correlation is covariance divided by the two deviations. That leaves it between −1 and 1 and makes it comparable; covariance is not.

    Is a covariance of 500 high?

    There is no way to tell: it depends on the units and the scale. To judge strength, look at the correlation.

    What does a negative covariance mean?

    That when one variable goes up, the other tends to go down.

    Can it be zero when a relationship exists?

    Yes, if the relationship is not linear. A U-shaped one can give a covariance of zero.

    Sample or population?

    Sample, dividing by n − 1, unless you have data for the entire population.