Before you start
You will be able to
- Calculate the sample covariance of two variables by hand and with COVARIANCE.S, and explain what its sign and its units tell you.
- Calculate Pearson’s r from the covariance and the two standard deviations, and as the average product of z-scores.
- Explain why r lies between −1 and 1, why linear changes of units leave it unchanged, and why it measures only straight-line association.
- Interpret r² as the share of variance that a straight line accounts for, without overclaiming.
- Use CORREL, PEARSON, RSQ, COVARIANCE.S and COVARIANCE.P correctly, and report correlations along a chain of measures.
Review first
- Scatterplots — Covariance and r summarise what a scatterplot shows; read the plot first.
- Describing distributions — Means, standard deviations and z-scores are the building blocks of r.
- Descriptive statistics and regression in Excel — CORREL, RSQ and the R Square of a regression, met there as Excel outputs.
Fictional case A fictional coffee business founded by Ana Lim. It starts as a catering and barista-training service, opens its own cafés and an online shop for beans, and plans a canned cold brew.
The idea
Fictional case
Ana’s scatterplots of the café log show footfall and transactions rising together in a thin band, and transactions and sales doing the same within each café. Before she presents them, she wants one number per pair that says how closely each pair moves together: a number that doesn’t change if footfall is counted in hundreds, and that she can compare across pairs and cafés.
From a plot to a number
Draw a vertical line through the mean of x and a horizontal line through the mean of y. They split the scatterplot into four quarters. For a positive association most points lie upper right (both values above their means) or lower left (both below); for a negative one, upper left or lower right. Each point’s deviation from the mean, and , says how far it lies from those lines, with a sign.
Multiply each point’s two deviations. A point in the upper right gives (+) × (+), positive; lower left, (−) × (−), also positive; the other two quarters give negative products. Add the products up: a large positive total means the points mostly agree in direction, a large negative one that they mostly disagree, and a total near 0 that neither wins. Of the 612 café-days, 592 lie upper right or lower left for footfall and transactions.
Covariance
Divide the sum of products by n − 1 and you have the sample covariance, : roughly the average product of deviations, with n − 1 for the same reason the sample variance uses it. For the gym, the six products add to 347, so . Excel’s =COVARIANCE.S(A2:A7,B2:B7) gives the same.
The sign is the useful part: positive covariance means the variables tend to move together, negative means they move in opposite directions. The size is hard to read. Its units are the product of the two variables’ units: footfall and transactions over the 612 café-days have a covariance of 4,252.4 people × transactions, a unit nobody can picture. Count footfall in hundreds of people instead and the covariance falls to 42.52, though nothing about the relationship has changed.
Size also mixes strength with spread. Millbrook’s covariance of footfall and transactions, 3,666, is larger than Harbourside’s, 2,292, but the two relationships are equally tight: each café’s correlation is 0.985. Millbrook’s figure is bigger only because its days vary more. So a covariance can’t be compared across pairs measured in different units, or even across groups with different spreads.
Pearson’s r: covariance without the units
To remove the units, divide the covariance by both standard deviations. The result is Pearson’s r, the Correlation coefficient B03 calculated with CORREL:
For the gym, classes and towels, so . For footfall and transactions at the two cafés, , the 0.98 of the scatterplots lesson. The units cancel (people × transactions over people times transactions), so r is a pure number, and the same whichever units the variables are measured in.
r runs from −1 to +1. It is +1 only when every point lies exactly on a rising straight line and −1 only on a falling one; 0 means no straight-line trend at all. Values in between say how close the points come to a line. In the log, footfall and transactions (0.98) come very close, iced share and the day’s high (0.94) close, and rain and footfall (−0.14) hardly at all.
r as the average product of z-scores
There is a second way to see r. Turn each value into a Z-score, its distance from the mean in standard deviations: . Then r is the sum of the products of the two z-scores, divided by n − 1:
This is the same calculation in a different order: dividing each deviation by its standard deviation first, instead of dividing the covariance afterwards. It explains why r has no units (z-scores have none) and why it ignores where each variable’s values sit and how widely they spread: z-scores have mean 0 and standard deviation 1 whatever the original scale. For the 612 café-days the average product of z-scores for footfall and transactions is 0.981, the same as r.
In depth
Why r stays between −1 and 1
The products of deviations can’t add up to more than the deviations themselves allow. In symbols, , a result called the Cauchy–Schwarz inequality, with equality only when every y-deviation is the same multiple of its x-deviation, which is to say when the points lie on one straight line. Dividing both sides by the right-hand side gives . That is why an r of exactly ±1 means a perfect straight line and nothing else does.
Changes of units leave r alone
A linear transformation changes a variable to : adding a constant shifts it, multiplying by a constant rescales it. Converting °F to °C, , is one; so is counting in hundreds, or in dollars instead of cents. Shifting changes every deviation by nothing; rescaling multiplies every deviation, and the standard deviation, by the same factor, so the factors cancel in r.
At Millbrook the day’s high and the iced share have a covariance of 3.935 (°F × share) and r = 0.944. In °C the covariance becomes 2.186, five-ninths as large, and r is still 0.944. Express the share as a percentage instead and the covariance becomes 393.5, a hundred times larger; r doesn’t move. Multiply by a negative number, as when a thermometer reading is replaced by “degrees below 100°F”, and r keeps its size but flips its sign (−0.944). Only a nonlinear change, such as taking logs, can change r’s size: the log of the high (always above 0°F here) gives r = 0.904 with the iced share.
r measures straight-line association only
r answers one question: how closely do the points follow a straight line? A strong relationship of another shape can have a modest r, or none. Take seven points on the U-shape , for x from −3 to 3: y is completely determined by x, yet r = 0, because the falling half cancels the rising half exactly. The iced share’s S-curve has r = 0.94, but Spearman’s rank correlation, which asks only whether the points always rise, is 0.96; the rank-correlation lesson explains the difference. Peak waits climb slowly with the load per barista and then steeply, a hockey stick whose strength r understates; the nonlinear-and-restricted lesson deals with it.
So r is a fair summary of a relationship only when the plot shows a roughly straight band with no points that break it. When the plot shows a curve, clusters or a stray point, report what the plot shows and treat r with suspicion, as the scatterplots lesson’s Anscombe quartet showed.
r² and shared variance
Squaring r gives , which B03 met as R squared in Excel’s regression output. With one x it is the share of the variance of y that the least-squares line on x accounts for: OpenStax’s wording is the percent of variation in the dependent variable that can be explained by variation in x using the regression line. The rest, , is variation the line leaves unexplained. For footfall and transactions, : a straight line in footfall accounts for about 96% of the day-to-day variance in transactions.
Three cautions keep that sentence honest.
- “Accounts for” is statistical, not causal. r² is symmetric too: footfall accounts for the same share of the variance in transactions as transactions do of footfall. It says how much variance the two share, not which way any influence runs.
- r² shrinks faster than r. An r of 0.5 sounds like halfway, but : a line accounts for a quarter of the variance. An r of 0.3 gives 0.09. Moderate correlations leave most of the variation unexplained.
- r² is not predictive accuracy. It is a share of variance, not the size of a typical prediction error; a high r² can still leave misses too big for the decision at hand. Prediction and its errors belong to B06.
Samples, populations and missing values
The covariance with n − 1, COVARIANCE.S, is the sample covariance, the right choice when the data are a sample from a larger process, as 306 days are from the cafés’ trading. COVARIANCE.P divides by n and describes the data as a complete population. The r you get is the same either way, as long as the standard deviations match: COVARIANCE.S with STDEV.S, or COVARIANCE.P with STDEV.P. Mixing them multiplies r by (n − 1) ÷ n: for Millbrook’s 306 days, 3.9217 ÷ (14.997 × 0.2778) = 0.9412 instead of 0.9443, a small slip with 306 rows and a larger one with 12.
The r of a sample estimates the population correlation, written (rho): the correlation over all the days the cafés could have traded under the same conditions. The testing-correlation lesson asks how far r can stray from by chance. Note that also names Spearman’s rank correlation, so this course writes “Spearman’s ρ” or for that.
When a value is missing, the course’s engine and this site’s worksheets use every row that has both values and skip the rest: Pairwise deletion. Microsoft’s documentation says only that CORREL and COVARIANCE.S ignore text, logical values and empty cells, so in Excel clear or filter out incomplete rows first, and count the pairs used. Each pair’s r may then come from slightly different rows, which matters when you compare several correlations; say how many pairs each one uses.
The Excel functions
| Function | Returns | Note |
|---|---|---|
=COVARIANCE.S(x,y) | Sample covariance (n − 1) | Units of x × units of y |
=COVARIANCE.P(x,y) | Population covariance (n) | Pair it with STDEV.P |
=CORREL(x,y) | Pearson’s r | Ignores text, logical values and blanks; #N/A if the ranges differ in size |
=PEARSON(x,y) | Pearson’s r | The same as CORREL |
=RSQ(y,x) | r² | The order doesn’t matter; it loses r’s sign |
=STANDARDIZE(x,mean,sd) | A z-score | With SUMPRODUCT, gives r as the average product of z-scores |
CORREL returns #DIV/0! if either range has no spread (every value the same), because a standard deviation of 0 can’t be divided by. Its arguments can be given in either order, like every function in the table, since r and the covariance are symmetric.
How strong is strong?
There is no agreed scale. Different textbooks attach “weak”, “moderate” and “strong” to different cut-offs, and what counts as strong depends on the field: in a café’s till data, footfall and transactions at 0.98 is unremarkable, while in a study of people’s behaviour 0.3 can be a notable finding. If you use a scale, name its source and say it is a convention. Better still, give the number, show the plot, and say what the relationship means for the decision: “a line in footfall accounts for about 96% of the variance in transactions” tells the reader more than “strong”.
Formulas
Sample covariance
- Sample covariance of x and yunits of x × units of y
- The paired values of unit itheir units
- The means of x and ytheir units
- Number of pairs
Assumes. Paired numeric data; rows with a missing value are left out (pairwise deletion).
Excel: COVARIANCE.S(x, y). COVARIANCE.P divides by n instead.
Pearson’s correlation coefficient
- Pearson’s correlation coefficient, from −1 to +1
- Sample covarianceunits of x × units of y
- Sample standard deviations of x and y (STDEV.S)their units
- The paired valuestheir units
- The meanstheir units
Assumes. Measures straight-line association only; read it with a scatterplot.
Excel: CORREL(x, y) or PEARSON(x, y). The n − 1 cancels, so the right-hand form needs no n.
r as the average product of z-scores
- Pearson’s correlation coefficient
- Number of pairs
- The paired valuestheir units
- The meanstheir units
- Sample standard deviationstheir units
In Excel: turn each column into z-scores with STANDARDIZE (using AVERAGE and STDEV.S), add up the products of the paired z-scores with SUMPRODUCT, and divide by COUNT minus 1.
r under a change of units
- Pearson’s correlation of x and y
- The original variablestheir units
- Constants added to x and y (shifts)units of x, y
- Constants multiplying x and y (rescaling), not zero
- +1 if b and d have the same sign, −1 if not
The covariance becomes b × d × s_xy: it changes with the units, r doesn’t. A nonlinear change (logs, squares) can change r.
Coefficient of determination for one x
- Share of the variance of y that the least-squares line on x accounts for, from 0 to 1
- Sum of squared residuals from the least-squares lineunits of y squared
- Sum of squared deviations of y from its meanunits of y squared
Excel: RSQ(y, x). Symmetric in x and y; a share of variance, not a measure of prediction accuracy (B06).
Worked examples
Fictional figures
Northgate Gym (fictional) recorded the classes booked and the towels laundered on six days: (4, 60), (6, 75), (7, 90), (9, 95), (10, 110), (12, 128). Calculate the covariance and Pearson’s r by hand, and check r as the average product of z-scores.
| Day | Classes x | Towels y | x − x̄ | y − ȳ | Product |
|---|---|---|---|---|---|
| 1 | 4 | 60 | −4 | −33 | 132 |
| 2 | 6 | 75 | −2 | −18 | 36 |
| 3 | 7 | 90 | −1 | −3 | 3 |
| 4 | 9 | 95 | 1 | 2 | 2 |
| 5 | 10 | 110 | 2 | 17 | 34 |
| 6 | 12 | 128 | 4 | 35 | 140 |
| Sum | 48 | 558 | 0 | 0 | 347 |
- Means: classes and towels. The deviations in each column add to 0, as deviations from a mean always do.
- Products of deviations: all six are positive, because every day is above both means or below both. Their sum is 347, so the covariance is class-towels.
- Standard deviations: the squared x-deviations add to 42, so ; the squared y-deviations add to 2,940, so .
- Pearson’s r: . Equivalently , where the n − 1 has cancelled.
- Check with z-scores: the products are 1.878, 0.512, 0.043, 0.028, 0.484, 1.992; they add to 4.937, and 4.937 ÷ 5 = 0.9875, the same r.
Answer. Covariance 69.4 class-towels; r = 0.987.
What it means. On these six days more classes went with more towels, almost exactly in a straight line. The covariance, 69.4, is in class-towels and would change if towels were counted in loads; r = 0.987 would not. Six days is a very small sample: the testing-correlation lesson shows how uncertain an r from six pairs is.
Fictional figures
For Millbrook’s 306 days, Ana’s sheet gives the covariance of the day’s high (°F) and the iced share (a proportion) as 3.9346, with standard deviations 14.997°F and 0.2778. Her supplier works in °C and percentages. Calculate r, then the covariance and r in the supplier’s units, and find what goes wrong if she divides COVARIANCE.P by the STDEV.S figures.
- r in Ana’s units: .
- To °C: . Subtracting 32 doesn’t change any deviation; multiplying by 5/9 multiplies every temperature deviation, and the standard deviation, by 5/9. So the covariance becomes and °C.
- To percentages: multiplying the share by 100 multiplies its deviations and standard deviation by 100: covariance (°C × percentage points), points.
- r in the supplier’s units: , the same as before: the factors 5/9 and 100 appear above and below the line and cancel.
- The mixed-up version: COVARIANCE.P divides by n = 306 instead of 305, giving 3.9217; divided by the sample standard deviations it gives , which is . With 306 rows the error is in the third decimal place; with 12 rows it would be 1/12, about 8%.
Answer. r = 0.944 in both sets of units. The covariance changes from 3.9346 (°F × share) to 218.59 (°C × percentage points). Mixing COVARIANCE.P with STDEV.S gives 0.9412, slightly too small.
What it means. Report r, not the covariance, when people use different units: the supplier and Ana will agree on 0.94 whatever thermometer they use. The covariance is still useful as an ingredient (it reappears in regression slopes in B06), but its size means nothing on its own. And keep the n − 1 or n consistent across the numerator and denominator.
Fictional figures
Ana wants to know whether the door counter is worth reading every morning as an early guide to the day’s sales. Footfall leads to transactions, and transactions add up to sales: the log is built that way. Calculate the correlation at each link, pooled and for each café, and say what she should report.
| Pair | Both cafés | Harbourside | Millbrook |
|---|---|---|---|
| footfall – transactions | 0.981 | 0.985 | 0.985 |
| transactions – sales | 0.834 | 0.992 | 0.982 |
| footfall – sales | 0.885 | 0.981 | 0.968 |
- Plot first: each pair, one café at a time. Footfall–transactions is a thin straight band in each café; transactions–sales too; pooled, transactions–sales splits into two bands (the scatterplots lesson).
- Footfall–transactions: r = 0.981 pooled, 0.985 and 0.985 by café. r² ≈ 0.96: a line in footfall accounts for about 96% of the variance in transactions.
- Transactions–sales: r = 0.834 pooled but 0.992 and 0.982 within the cafés. The pooled figure is lower because Harbourside’s average ticket (about $5.34) is much higher than Millbrook’s (about $3.27), so the two cafés lie on different lines. The within-café figures describe the link; the pooled one mixes two groups.
- Footfall–sales, the end-to-end link: r = 0.981 at Harbourside and 0.968 at Millbrook (r² ≈ 0.96 and 0.94). Each café’s footfall is a close guide to its own sales. Pooled, r = 0.885.
- Language: in the log, footfall becomes transactions and transactions add up to sales, so here the direction is known from how the business works, not from the correlations. The correlations measure how tightly each link holds.
Answer. By café, every link is very close to a straight line: r is about 0.97–0.99 at each step. Footfall alone accounts for about 94–96% of the variance in each café’s daily sales. Report by café; the pooled transactions–sales r of 0.83 mixes two different ticket sizes.
What it means. Yes, the morning door count is a good early guide, café by café. The useful lesson for Ana’s report is where the chain is loose: not between people and purchases, but between the two cafés’ ticket sizes. A single pooled correlation would have hidden that. What the correlations can’t tell her is how to raise sales: that takes knowing what brings people through the door and what they spend, which the last lessons of the course discuss.
Explore
Common mistakes
“Millbrook’s covariance is bigger, so its relationship is stronger.”
Covariance grows with the spread of each variable. Millbrook’s 3,666 beats Harbourside’s 2,292 because Millbrook’s days vary more, but both cafés’ r is 0.985. Compare correlations, not covariances.
“r = 0.5 means a relationship halfway to perfect.”
r² = 0.25: a line accounts for a quarter of the variance, and three quarters is left over. Square r before deciding how much of the variance a line accounts for.
“r² = 0.96, so footfall causes 96% of transactions.”
r² is a share of variance that two variables have in common, and it is symmetric. It says nothing about which way influence runs, and nothing about a percentage of the transactions themselves.
Converting units and expecting r to change
Any linear change of units (°F to °C, dollars to thousands, a share to a percentage) leaves r alone; only the sign can flip, when one variable is multiplied by a negative number. If converting units changed your r, there is a mistake in the conversion.
Mixing sample and population formulas
COVARIANCE.P ÷ (STDEV.S × STDEV.S) is r × (n − 1) ÷ n, too small. Use COVARIANCE.S with STDEV.S, COVARIANCE.P with STDEV.P, or just CORREL.
Reading a near-zero r as “no relationship”
r measures straight-line association. A U-shape can be a perfect relationship with r = 0. Plot first.
Guided practice
Work through these with hints when you need them. Every hint and every worked solution is there to be used.
Loading four questions…
On your own
No hints this time. Answer, check, and read the feedback; the solution appears once you have answered or if you ask for it. Your first answers count toward mastery.
Loading six questions…
In practice
Fictional case
Ana’s report to her two managers has one page per link in the chain: a scatterplot for each café, and under it r and r² for each café and pooled. Her summary line reads: “At both cafés, the morning door count is a close guide to the day’s sales: a straight line in footfall accounts for about 94–96% of the day-to-day variance in sales. The two cafés differ in ticket size, not in how footfall turns into sales, so we report them separately.”
This is the everyday professional use of r: a compact, unit-free summary that lets you compare how tightly different pairs hold together, and spot where a chain of measures is loose. It is always reported with the plot, with the number of pairs, and broken down by group when the groups differ.
Covariance has a quieter role. It is rarely reported on its own, because its size depends on the units, but it is the ingredient behind r, behind regression slopes in B06 (the slope of the least-squares line is the covariance divided by the variance of x), and behind portfolio risk in finance, where the covariance of two assets’ returns decides how much combining them reduces risk. Wherever it appears, read its sign and convert it to r before judging its size.
Finally, use r² carefully. “A straight line in footfall accounts for 96% of the variance in transactions” is accurate. “Footfall explains 96% of transactions” is not: it sounds causal, it misnames variance as transactions, and it hides that the line is a straight one fitted to these 306 days at each café, not a law. The causal question, whether getting more people through the door would raise sales, needs more than a correlation, as the last lesson of this course shows.
Knowledge check
Six questions, one attempt each, no hints. Score 80% or more to complete the lesson; you can take it again at any time.
Loading six questions…
Summary
- Covariance averages the products of deviations from the means (dividing by n − 1): positive when the variables move together, negative when they move apart. Its size depends on the units and the spreads.
- Pearson’s r = s_xy ÷ (s_x s_y): covariance without the units, always between −1 and +1, and ±1 only for a perfect straight line.
- r is also the average product of z-scores, Σ z_x z_y ÷ (n − 1).
- Linear changes of units (°F to °C, shares to percentages) never change r; a negative multiplier flips its sign; only nonlinear changes such as logs can change its size.
- r measures straight-line association only: a curve or a U-shape can be strong with a modest or zero r.
- r² is the share of the variance of y that a straight line in x accounts for. It is symmetric, shrinks faster than r, and is neither causal nor a measure of prediction accuracy.
- In Excel: COVARIANCE.S, COVARIANCE.P, CORREL (= PEARSON) and RSQ. Keep sample with sample and population with population.
- Along the chain, footfall–transactions–sales are each close to a straight line within each café (r ≈ 0.97–0.99); pooling the cafés lowers transactions–sales to 0.83 because their ticket sizes differ.
Key formulas
- Sample covariance
- Pearson’s correlation coefficient
- r as the average product of z-scores
- r under a change of units
- Coefficient of determination for one x
Terms introduced
- Deviation from the mean
- How far a value lies above or below the mean of its variable: x − x̄, positive above the mean and negative below.
- Covariance
- The average product of two variables’ deviations from their means (dividing by n − 1 for a sample, by n for a population): positive when they tend to move together, negative when they move in opposite directions. Its units are the product of the two variables’ units.
- Pearson’s r
- The correlation coefficient for straight-line association: the covariance of two variables divided by the product of their standard deviations, from −1 to +1. Also called the Pearson product-moment correlation.
- Population correlation
- The correlation of two variables over a whole population or process, written ρ (rho), which a sample’s r estimates.
- Linear transformation
- A change of a variable to a + b × x, such as a change of units; it shifts and rescales the values, keeping their order when b is positive and reversing it when b is negative, and leaves the shape of their relationships straight.
Sources
- Holmes, A., Illowsky, B. & Dean, S. (2023). Introductory Business Statistics 2e, section 13.1, “The Correlation Coefficient r”. OpenStax. openstax.org/books/introductory-business-statistics-2e/pages…
- Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, section 12.3, “The Regression Equation” (the correlation coefficient and the coefficient of determination). OpenStax. openstax.org/books/introductory-statistics-2e/pages/12-3-the…
- Microsoft Support. “CORREL function”. support.microsoft.com/en-US/excel/functions/correl-function
- Microsoft Support. “COVARIANCE.S function”. support.microsoft.com/en-US/excel/functions/covariance-s-fun…
