Module 6 · Statistics for Data Analysis
Correlation
Measure how strongly two numbers move together with a scatter chart and CORREL, interpret r and r², and avoid the classic traps, above all treating correlation as cause.
About 25 minutes
The problem
Kolanut's sales director has noticed that order lines with a discount are much bigger than those without: about 17 packs against 11. Her proposal:
"Discounts make customers buy more. Let's give a 10% discount on everything."
It sounds like the data supports her. But is the discount causing the bigger orders, or are bigger orders getting the discount? The answer decides whether the new policy grows sales or just gives away margin on orders that would have happened anyway.
This lesson measures how strongly two things move together, and then, more importantly, how to think about what that relationship does and doesn't mean.
The concept
Look first: the scatter chart
Put one variable on each axis and plot a dot for each row: Insert → Scatter in Excel or Google Sheets. In a few seconds you see whether the dots rise together, fall, or show no pattern; whether the relationship is a straight line or a curve; and whether a few outliers are doing all the work.
Measure: the correlation coefficient, r
=CORREL(range1, range2) gives Pearson's r, a number from −1 to +1:
| r | Meaning |
|---|---|
| +1 | Perfect positive straight line: as one rises, the other rises exactly |
| about +0.7 to +1 | Strong positive |
| about +0.3 to +0.7 | Moderate positive |
| about −0.3 to +0.3 | Weak or none |
| negative values | The same, but one falls as the other rises |
| −1 | Perfect negative straight line |
These bands are rough guides, not rules. And r only measures straight-line relationships: a strong curve (sales rising then falling with price) can give an r near 0.
r²: how much is explained
Square r to get r² (=RSQ(range1, range2)): the share of the variation in one variable that's explained by a straight-line relationship with the other. r = 0.93 gives r² ≈ 0.87: containers explain about 87% of the variation in freight charges.
The traps
- Correlation is not causation. Two things can move together because:
- A causes B (more containers cause a higher charge);
- B causes A (a supermarket opens more tills because it is busy, not the other way round);
- something else causes both (hot weather raises both ice-cream sales and drowning numbers);
- pure coincidence, especially when you test many pairs.
- Outliers can create or hide a correlation. Check the scatter chart.
- Mixing groups. Two groups with different levels can create a correlation that doesn't exist within either group (the same lesson as Simpson's paradox).
- No correlation isn't "no relationship". It means no straight-line relationship.
Getting closer to cause
Data like Kolanut's is observational: nobody decided at random who gets a discount. The strongest way to establish cause is an experiment: give the discount to a random half of customers for a month and compare (lesson 9 shows how to test the difference). Without one, ask how the data was produced: who decided the discount, and why?
Example
Three correlations from the practice data, with what each one means:
| Pair | r | Reading |
|---|---|---|
| Harbourline: containers vs freight charge | 0.93 | Very strong. And here it is causal: Harbourline prices by container. |
| Kolanut: quantity vs discount % | 0.34 | Moderate. Bigger lines tend to have bigger discounts. But see below. |
| Kolanut HR: years of service vs monthly salary | −0.05 | None. Pay isn't related to how long people have been there. |
Back to the director. The 0.34 is real, but look at who gets discounts. Kolanut's discounts depend mostly on the customer's channel: 62% of wholesale lines are discounted, 27% of supermarket lines and 5% of kiosk lines. And wholesalers also order far more per line (19 packs, against 11 for supermarkets and under 4 for kiosks). Channel drives both the discount and the quantity: it's a third factor, called a confounder.
Check it by looking within one channel, so channel can't be the explanation. Among wholesale lines, discounted lines average 19.2 packs and undiscounted ones 18.7: almost no difference, and the correlation is about 0.02. The same holds inside the other two channels. Once you compare like with like, the "discount effect" disappears.
So a discount on everything would cost margin on every order, with no evidence it would grow volume. The honest recommendation: "Discounted lines are larger overall (r = 0.34), but only because wholesalers get most of the discounts and also place the biggest orders. Within each channel, discounted and full-price lines are the same size. To test whether a discount changes behaviour, offer it to a random half of comparable customers for a month and compare."
And the HR result deserves a sentence too: pay that doesn't rise with service is something HR would want to know about, especially alongside lesson 1's finding about who leaves.
Walkthrough
- Open the logistics
shipments.csv. Insert a scatter chart ofcontainers(x) againstfreight_charge(y). Describe what you see. - Calculate
=CORREL(containers, freight_charge)and=RSQ(…). - Open Kolanut's
orders.csv. CalculateCORREL(quantity, discount_pct). Compare the average quantity of discounted and undiscounted lines withAVERAGEIFS. - Open the HR
employees.csv. Addyears= (exit_dateif there is one, otherwise 30 June 2026, minushire_date) ÷ 365.25. Scatteryearsagainstmonthly_salary, and calculateCORREL. - Add each order line's
channelfromcustomers.csvwith XLOOKUP. Filter to Wholesale and calculateCORREL(quantity, discount_pct)again. What happened to the relationship? - Write the director a two-sentence reply about the discount proposal.
Practice
Practice
What is the correlation (CORREL) between containers and freight_charge across all shipments in shipments.csv? Two decimal places.
Practice
What is the correlation between quantity and discount_pct in Kolanut's orders.csv? Two decimal places.
Practice
What is the average quantity on order lines with a discount (discount_pct > 0)? One decimal place.
Practice
Now look within one channel. Among Wholesale customers' order lines only, what is the correlation between quantity and discount_pct? Two decimal places.
Challenge
Challenge · optional
Total each Kolanut customer's revenue across all orders, then calculate the correlation between that total and the customer's credit_limit. Two decimal places.
Check your understanding
Answer every question to check.