Correlation
The correlation coefficient rescales covariance to a dimensionless number between -1 and 1, measuring linear association.
Pearson correlation
The correlation coefficient is ρ = Cov(X, Y) / (σ_X σ_Y). Dividing by the standard deviations removes units and bounds the result to [−1, 1]. A value of +1 means a perfect increasing linear relationship, −1 a perfect decreasing one, and 0 no linear relationship.
Interpreting the magnitude
The sign gives direction; the magnitude gives strength of the linear part. The square ρ² is the fraction of variance in one variable explained by a linear fit to the other, which is exactly the coefficient of determination in simple regression.
Correlation is not causation
A high correlation can arise from a direct effect, a reverse effect, a common cause, or coincidence in a small sample. Correlation quantifies co-movement; establishing causation requires additional structure such as a controlled intervention or a credible causal model.
Limits of Pearson correlation
Pearson ρ only sees linear structure and is sensitive to outliers. A curved but deterministic relationship can show near-zero ρ. Rank-based measures like Spearman's or Kendall's capture monotonic but nonlinear associations and resist outliers.
import statistics as st
x = [1,2,3,4,5]; y = [2,4,5,4,5]
cov = sum((a-st.mean(x))*(b-st.mean(y)) for a,b in zip(x,y))/len(x)
rho = cov/(st.pstdev(x)*st.pstdev(y))
print(round(rho,3))
In practice
Before trusting a correlation, plot the data. Anscombe's quartet — four datasets with identical correlation but wildly different shapes — is the standard warning that a single number cannot replace looking at the scatter.