Do two things rise together? Five points answer it with rectangles. Watch each one draw its rectangle to the means.
Do two things rise together?
Five pairs of numbers: each point's rectangle to the means, signed by its quadrant, and their sum.
Five points. The dashed lines mark the mean of the first numbers, 3, and of the second numbers, 3.
Describe this picture
Five points on a grid from 0 to 6, drawn to one scale across and up: , , , and . A dashed vertical line at the mean of the first numbers, 3, and a dashed horizontal line at the mean of the second numbers, 3, cut the plane into four quadrants. One point at a time, each point draws the rectangle between itself and the crossing of the dashed lines, and the caption gives its sides and area. A rectangle in the top-right or bottom-left quadrant is shaded in the accent colour and marked + as positive; one in the other two quadrants is shaded in a second colour and marked − as negative; the two points on a dashed line draw flat rectangles that add 0. A bar beside the plot, from −12 to 12, adds up the signed areas as they appear: 2, 4, 4, 4, then 8. Readouts give the means and the sum. When the clip has finished, any point can be dragged, or focused and moved with the arrow keys in steps of 0.5, and its rectangle, the dashed lines, the bar and the readouts follow it.
Rectangles around the means
Take five pairs of measurements, say a plant’s height and its number of leaves. Plot each pair as a point. Do the two numbers go up together?
Here is a way to measure it. Draw a line at the mean of each number; for these five points both means are 3. Every point now sits in one of four quadrants. A point to the top right is above average in both numbers. A point to the bottom left is below average in both. Both agree, so I count their rectangle as positive. A point to the top left or bottom right disagrees, so its rectangle counts as negative.
The rectangle’s sides are the point’s distances from the two means, so its area is the product of the two deviations, with its sign. For the point that is . For it is : both deviations are negative, and their product is positive. The points and sit on a dashed line, so one side of their rectangle is 0.
Add the five areas, . A large positive total says the points mostly agree: when one number is high, so is the other. A large negative total says they mostly disagree. A total near 0 says neither wins.
After the clip, drag a point into a disagreeing quadrant and watch the total drop.
Covariance
Write the points as for , with means and . The sum of the signed rectangles is
It grows with the number of points, so I divide by it. The average rectangle, , is the covariance of the data: here. Some books divide by instead and get ; the reason belongs to estimation, and it does not change anything on this page.
For two random variables and , with means and , the covariance is the expected rectangle:
The second form comes from multiplying out the brackets. The covariance of with itself is its variance, from Variance and standard deviation: every rectangle is then a square.
Correlation
Covariance has a problem: it depends on the units. Measure the heights in centimetres instead of metres and every rectangle gets 100 times wider, so the covariance is 100 times larger. The points have not changed at all.
So scale it. Divide by the spread of each number, and the units cancel. The result is the correlation. For data,
where and . For the five points, and , so . For random variables,
The correlation always lies between and . It is when the points lie on a rising straight line, and on a falling one. For , ; for , . Changing units, centimetres to metres, leaves alone.
Why can it never pass 1? Collect the deviations into two lists: for the first numbers and for the second. Treat each list as an arrow with five entries. Then is their dot product, and and are their lengths. So is the cosine of the angle between the two arrows, and a cosine stays between and . Here the angle is 36.87°, which is 0.6435 radians, and its cosine is .
Where this leads · angles between data
The cosine comes from Length and the dot product in the linear algebra course. A correlation of 0 means the two lists of deviations are at a right angle.
Correlation is not the slope of the line through the points. The best line through them rises by for each step in , where and are the standard deviations of the and values. For the five points, the two spreads are equal, so the slope happens to be too. If but the spread of is twice the spread of , the slope is .
What correlation misses
Correlation measures only how close the points come to a straight line. Two variables can depend on each other completely and still have correlation 0. Let be one of , each with chance , and let . Knowing tells you exactly. But the points and cancel, and so do and : and , so the covariance is 0. The points lie on a curve, not a line.
So zero correlation does not mean independent. The other way round does hold: independent variables have covariance 0, because the expected product of independent variables is the product of their means.
Correlation can also point the wrong way. Watch six points, first in one colour, then in two.
Two falling groups, one rising cloud
Six pairs of numbers, first as one group, then as the two groups they came from.
Six points rising from bottom left to top right: their correlation is 0.632.
Describe this picture
Six points in one colour on a grid of first numbers 0 to 7 and second numbers 2 to 10, rising from bottom left to top right, with a readout of their correlation, 0.632. Then the points split into two groups by colour: , , keep the first colour and , , take a second. A line falls through each group, and a readout for each group shows a correlation of . The picture has no control.
All six points together have : they seem to rise together. Inside each group, they fall together perfectly. A third thing, the group, raises both numbers at once, and that makes the pooled cloud rise. Imagine the groups are two schools, is hours of homework and is a test score. In the pooled data more homework goes with a higher score, while inside each school more homework goes with a lower score.
This is why correlation is not cause. A correlation says the numbers move together in this data. It does not say that one moves the other, and a hidden third variable can create or reverse it.
Worked example
- Five points. , , so . The covariance is dividing by , or dividing by .
- Dependent but uncorrelated. equally likely to be and : covariance 0, though is fixed by .
- Two groups. The six points have , and , so , although each group alone has .
- Lines. has ; has .
- Slope. With and the spread of twice that of , the best line has slope , not .
Where you’ll meet this
An investor who holds two shares whose prices have a negative correlation tends to lose less on a bad day, because one tends to rise when the other falls. That is the idea behind spreading money over many investments.
A robot that combines two sensors, say a wheel counter and a camera, needs to know how their errors are correlated; errors that move together cannot cancel. And a data analyst choosing which measurements to feed a model often drops one of two measurements that are almost perfectly correlated, because the second adds little.
In signal processing · uncorrelated sinusoids
In Signals as sums of sinusoids, each arrow of a Fourier series is measured by multiplying the signal by one sinusoid and averaging. Two different harmonics multiplied and averaged over a period give 0: they are uncorrelated in the sense of this page, with the average over a period in place of the mean. That is why each one can be measured alone.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Sum of rectangles | positive: the numbers agree | |
| Covariance | ||
| Correlation, data | no units | |
| Correlation | between and | |
| As an angle | of the deviation lists | 0 means a right angle |
| Slope of the best line | not itself | |
| Independent | covariance 0 | but 0 does not mean independent |