Skip to main content
Albero Academy

Correlation & Covariance

Measure how two variables move together — covariance, the correlation coefficient, Pearson vs Spearman, and the causation trap.

Chapter 8Statistics14 min readBeginner friendly
  • #Statistics
  • #Correlation

Correlation quantifies how strongly two variables move together — the number behind "does more experience mean a higher salary?". It's one of the most used (and most misused) statistics, so understanding what it does and doesn't tell you is essential.

Covariance

Covariance measures whether two variables tend to move in the same direction (positive) or opposite directions (negative). Its problem: its size depends on the units, so you can't compare covariances — which is why we standardise it into correlation.

The correlation coefficient

The Pearson correlation (r) rescales covariance to a fixed range from −1 to +1, so it's comparable and interpretable:

r valueMeaning
+1Perfect positive linear relationship
+0.7Strong positive
0No linear relationship
−0.7Strong negative
−1Perfect negative linear relationship
computing correlation
df["experience"].corr(df["package"]) # a single r
df.corr(numeric_only=True) # a correlation matrix of all pairs

Pearson vs Spearman

  • Pearson measures linear association — best for straight-line relationships.
  • Spearman measures monotonic association using ranks — robust to outliers and works for curved-but-consistent relationships.

Correlation ≠ causation

The cardinal rule: two variables correlating does not mean one causes the other. A hidden confounder may drive both (ice-cream sales and drownings both rise with temperature), or it may be coincidence. Only a controlled experiment (A/B test, Chapter 5) can establish causation.

Practice

Compute the correlation between experience and package, and build a correlation matrix for a dataset. Find a pair with high correlation and argue whether causation is plausible or a confounder is likely. Compare Pearson and Spearman on a column with an outlier.

Key takeaways

  1. 01Covariance shows direction of joint movement but depends on units — not comparable.
  2. 02Correlation (r) rescales it to −1…+1: comparable and interpretable.
  3. 03Pearson measures linear association; Spearman (rank-based) handles monotonic/curved and resists outliers.
  4. 04A near-zero Pearson can still hide a strong non-linear relationship — always plot.
  5. 05Correlation is not causation — a confounder or coincidence may explain it; only experiments prove cause.