Correlation & Regression

Relationships between variables. Learn covariance and the correlation coefficient r, simple linear regression by least squares, slope and intercept, residuals and R², prediction vs extrapolation, multiple and non-linear regression, and why correlation is not causation.

Calibrating a sensor, estimating fuel use from speed, or predicting strength from curing time all require fitting a relationship to data. Regression quantifies it; correlation measures its strength.

An analogy

Regression is like stretching a rubber band through a cloud of points so that it sits as close as possible to all of them at once.

Scatter and correlation

r near ±1: strong linear relationship; near 0: no linear relationship (could still be non-linear). r is unitless and symmetric in x and y.

Least squares fit

Minimises the sum of squared residuals. Always plot residuals: patterns (curves, funnels) mean the model is wrong or variance isn't constant.

Correlation is not causation

Two variables can correlate because a third factor drives both (ice-cream sales and drowning both rise in summer), by coincidence, or with reversed cause. Only controlled experiments establish causation.

Beyond simple regression

Multiple regression (several predictors), polynomial and non-linear fits, transformations (log-log for power laws), regularisation, and prediction intervals. Never extrapolate far outside the data range.

Formulas

Worked example: Sensor calibration

Given: x = 1…5, y = 2.1, 3.9, 6.2, 7.8, 10.1

Find: Line, r, R².

Answer: ŷ = 0.05 + 1.99x; R² = 0.997

Worked example: Spurious correlation

Given: Cooling-fan failures correlate with ice-cream sales (r = 0.8)

Find: Interpretation.

Answer: No causal link — control for temperature

Common mistakes

Applications

Key takeaways

Going further