Correlation, and what it doesn't say
Not met yet
The correlation r measures how closely two things rise and fall together along a straight line, from 1 through 0 to -1. Take each mean off, multiply the pairs and add them up, then divide by the square root of the two sums of squares; np.corrcoef(x, y)[0, 1] does the same. r is symmetric, has no units, and isn't a slope. It only sees straight lines, so a hump can give 0 when one thing decides the other completely. And a correlation never shows a cause on its own: two things can both follow a third, like the year or the season, which is how the price of coffee correlates with the warming.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks correlation measures any relationship. It measures how well the points fit a straight sloping line, so a hump or a U can give r near 0.
- Thinks a strong correlation shows that one thing causes the other, when both may follow a third thing, like time or the season, or the link may be luck.
- Thinks r is the slope, how much y rises for each step in x. r has no units and stays the same if either set of numbers is stretched.
- Thinks correlation(x, y) and correlation(y, x) are different numbers. Correlation is symmetric.