Professor Turing

Study guides

Correlation and covariance

Last updated: 2026-11-26

Covariance and correlation both describe how two variables move together along a straight-line trend. Covariance carries the units of one variable times the units of the other, so its size changes when you change units. Correlation divides covariance by the two standard deviations, which removes the units and keeps the result between −1 and 1.

Start learning No account needed

1. The two formulas

For a sample of n pairs, take each value's distance from its own mean, multiply the two distances for each pair, add the products and divide by n − 1. That is the sample covariance, as given in NIST's handbook.

The sample correlation, r, is the covariance divided by the standard deviation of x times the standard deviation of y. Introduction to Modern Statistics writes it as the sum of the products of standardized distances divided by n − 1, which is the same expression rearranged. It says correlation describes the strength and direction of a linear relationship, lies between −1 and 1, and has no units.

2. A worked example: temperature and iced drinks

Over five days you record the temperature and the number of iced drinks sold. The figures are made up.

Day12345
Temperature (°C)1821242730
Drinks sold2227263540

The numbers below are computed by scripts/correlation-vs-covariance-worked-example.py in the Professor Turing repository. Output:

mean temperature = 24, mean drinks = 30
temperature deviations: -6, -3, 0, 3, 6
drink deviations: -8, -3, -4, 5, 10
products: 48, 9, 0, 15, 60 | sum = 132
covariance = 132 / 4 = 33
standard deviations: temperature = 4.743, drinks = 7.314
correlation = 33 / (4.743 x 7.314) = 0.951
Fahrenheit: 64.4, 69.8, 75.2, 80.6, 86
with Fahrenheit: covariance = 59.4 (= 33 x 1.8), correlation = 0.951
curve 4, 1, 0, 1, 4: products -12, 3, 0, -3, 12 | covariance = 0, correlation = 0.000
drinks doubled: covariance = 66, correlation = 0.951
drinks sign flipped: covariance = -33, correlation = -0.951

The covariance is 33, measured in degrees Celsius times drinks. The sign tells you that warmer days came with more sales. The correlation, 0.951, indicates a strong upward linear association in these five days. The number alone does not show the shape of a pattern, so plot the points too.

3. Change the units

Record the same days in Fahrenheit. Each temperature distance is multiplied by 1.8, so the covariance becomes 59.4. The standard deviation of temperature is also multiplied by 1.8, so the two cancel and the correlation stays at 0.951. Adding 32 changes the mean and leaves the distances from it alone.

4. A common misconception: a bigger covariance means a stronger relationship

The jump from 33 to 59.4 came from the temperature scale. The days, the sales and the tightness of the pattern are the same. Counting half-size servings instead of drinks would double each sales figure and take the Celsius covariance to 66, again with a correlation of 0.951. To compare the strength of linear relationships measured on different scales, compare correlations, and look at the scatterplots too.

5. Zero does not mean unrelated

Keep the temperatures and pair them with 4, 1, 0, 1 and 4, a U shape built from the temperature itself: square the number of 3-degree steps away from 24. The products cancel, so the covariance and the correlation are both 0. Introduction to Modern Statistics warns that a strong nonlinear trend can produce a correlation that does not reflect the strength of the relationship.

6. Test yourself

Work each one on paper before you open the answer.

Question 1. Sales are recorded as negatives, as stock leaving the fridge. What happens to the covariance and the correlation?

Answer to question 1

Both change sign: −33 and −0.951.

Question 2. One report gives a covariance of 59.4 and another a covariance of 33. Which shows the stronger linear relationship?

Answer to question 2

You cannot tell from covariance alone. On this page the two figures describe the same five days in different temperature units.

Question 3. Why does the Fahrenheit change leave r alone?

Answer to question 3

The factor of 1.8 appears in the covariance on top and in the temperature standard deviation underneath, so it cancels.

Related guides: correlation and causation, what is standard deviation and what is principal component analysis, which works with covariances among many variables.

What the sources found, and their limits

NIST/SEMATECH e-Handbook of Statistical Methods, section 6.5.4.1, "Mean Vector and Covariance Matrix." Gives the sample covariance with the n − 1 divisor and shows a covariance matrix, with variances on the diagonal. Limits: it does not discuss correlation on that page. Source: 6.5.4.1, read on 2026-11-25.

Introduction to Modern Statistics, chapter on linear regression with a single predictor. Mine Çetinkaya-Rundel and Johanna Hardin, OpenIntro, second edition. Defines correlation, gives its formula, states its range and lack of units, and shows nonlinear patterns where the correlation does not reflect the strength of the relationship. Source: openintrostat.github.io, model-slr, relevant passages read on 2026-11-25. The five days and the unit changes are ours.

How Professor Turing helps

Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start. It's an AI tutor, free to try.

Bring a pair of variables you are working with. Its first reply asks about your attempt, such as how you got your deviations, before it teaches anything. You must be 18 or older. Guest conversations are deleted 7 days after your last activity; with an account they are kept while the account is active.

FAQ

Can covariance be greater than 1? Yes. In our example it is 33 with temperature in Celsius. Covariance has no fixed range, and its size depends on the units and spread of both variables.

What does a negative covariance mean? Above-average values of one variable tend to come with below-average values of the other. Correlation has the same sign as covariance when both variables vary.

Does a correlation of zero mean the variables are unrelated? No. It means there is no linear trend of the kind correlation measures. Our curved example has a correlation of 0 although each value follows from the temperature by a rule.

Start with what you're working on

Tell the tutor which calculation you are working on and let it ask you the questions.

Start learning No account needed

See also: correlation and causation · all study guides