Foundations — Covariance and correlation
Before you can read the parent note Covariance and correlation you must own every symbol it throws at you. This page builds each one from nothing, in the order they depend on each other. Never worry that a symbol looks scary — by the time we use it, you will have seen its picture.
1. The random variable
Plain words: think of as a labelled slot that gets filled with a number each time you run the experiment. Roll a die → becomes the face showing. Measure a house → becomes its square footage.
Picture: imagine a number line, and each trial drops a dot somewhere on it. Over many trials you get a cloud of dots.
Why the topic needs it: covariance compares two such slots, and , filled at the same time. Without the idea of a random number, there is nothing to compare. (Build more at 1.3.01-Random-variables.)
2. The expectation and the mean
Plain words: if you ran the experiment a million times and averaged all the numbers, that average is . The two symbols and mean exactly the same thing — is the operation "take the average of", and is the name of the answer for .
Picture: place a finger under the number line where the dots would perfectly balance like a see-saw. That balance point is .
Why the tool and not a plain average? Because we rarely have all the data — we have probabilities. is the average weighted by probability, which works even for infinite or continuous possibilities where you cannot literally list every trial. (See 1.3.05-Expectation-and-variance.)
3. The deviation
Picture: draw an arrow from the balance point to where a dot landed. Arrow pointing right = positive deviation; pointing left = negative deviation.
Why the topic needs it: covariance never asks "was big?" — it asks "was above or below its usual, and was above or below its usual, at the same time?" That "above/below usual" is exactly the deviation. Multiplying two deviations is the heart of the whole idea (next section).
4. Variance and standard deviation
Plain words: variance measures how spread out the cloud is. We square the deviations so that below-average (negative) and above-average (positive) misses both count as "spread" instead of cancelling.
Why take the square root to get ? Squaring changed the units (metres became metres²). The square root undoes that, so is back in the same units as — a genuine "typical distance from the mean".
Picture: is the typical width of the cloud, a ruler you lay along the number line.
Why the topic needs it: correlation divides covariance by . To divide by spread, you must first have spread — that is . (More: 1.3.05-Expectation-and-variance.)
5. The joint pair and
Plain words: now every trial produces two numbers, so each dot lives on a 2-D plane, not a line. The dot's horizontal position is , its vertical position is .
Picture: a scatter plot. Each experiment = one dot at coordinates .
Why the topic needs it: covariance is a two-variable idea. You cannot see "do they move together" from two separate number lines — you must see the pairs side by side, which is exactly the scatter plot. (Build this at 1.3.08-Joint-and-marginal-distributions.)
6. The product of deviations
This is the single cleverest symbol on the parent page, so we picture it carefully.
Take one dot at . Draw the vertical line and the horizontal line . These two lines split the plane into four quadrants, meeting at the "average point" .
For a dot, look at the sign of each deviation and multiply:
| Region | product | ||
|---|---|---|---|
| top-right | |||
| bottom-left | |||
| top-left | |||
| bottom-right |
This is why the parent defines Every symbol in it you now own: (section 2), the deviations (section 3), their product (this section).
7. The correlation symbol and its scale
Plain words: covariance's size depends on the units of and , so a big number could just mean "big units", not "strong link". Dividing by cancels the units and squeezes the answer into the fixed range , where means "perfectly on a line" and means "no straight-line trend". This makes comparable across any pair of variables.
Why the topic needs it: it is the rating on a universal scale the parent's intuition promised.
8. Sample symbols: , ,
When you only have real data (finitely many measured pairs) rather than a probability formula, the parent switches to lower-case sample symbols:
- — the count of data points you collected.
- — the -th data value; the little is just a counter running .
- — the summation sign: "add up the thing to my right for from to ."
- — "x-bar", the sample mean, . It is the data-only stand-in for .
Why the topic needs them: in machine learning you never see the true — you estimate it from a spreadsheet of rows. The bar and the are how theory becomes computable.
Prerequisite map
Where these tools go next
- Covariance of many features at once builds the matrix behind 2.4.01-Principal-component-analysis.
- The same "move together" idea drives the slope in 3.2.05-Linear-regression and the warning of 3.2.06-Multicolinearity.
- Zero covariance is a weaker cousin of 1.2.04-Independence — never confuse them.
- Correlation strength is one criterion in 4.1.03-Feature-selection.