Bivariate data: scatter diagrams, regression and correlation
IB Math AI · Statistics and Probability
What $r$ measures, and what it does not
Pearson's product-moment correlation coefficient $r$ lies in $[-1,1]$ and measures the strength of a linear relationship only. A perfect parabola through the origin can have $r$ near zero; $r$ small therefore means "not linear", not "no relationship".
The coefficient of determination is $r^{2}$: it is the proportion of the variation in $y$ explained by the regression on $x$. With $r=0.966$, the model explains $r^{2}=0.933$, i.e. $93.3\%$ — not $96.6\%$.
The least-squares line
The line $y=ax+b$ minimises the sum of squared vertical residuals $\sum(y_{i}-\hat y_{i})^{2}$. Two consequences are examined directly: the line always passes through $(\bar x,\bar y)$, and the residual at a point is $\text{observed}-\text{predicted}$, so a negative residual means the model overestimates.
The line of $y$ on $x$ is for predicting $y$ from $x$. The line of $x$ on $y$ is a different line, and using the wrong one is a standard exam trap.
Interpolation and extrapolation
Predicting inside the range of the data is interpolation and is supported by the evidence. Predicting outside it is extrapolation and assumes the linear pattern continues where nothing was measured.
Spearman's rank
$$r_{s}=1-\frac{6\sum d^{2}}{n(n^{2}-1)}$$Ranks are used instead of values, so $r_{s}$ detects any monotonic relationship, not just a linear one, and is far less affected by outliers.
Correlation is not causation
A strong $r$ between two quantities may arise from a third, confounding variable acting on both.
Worked example: regression on real data: coefficients, predictions and the limits of the model
An ice cream shop records the midday temperature and the afternoon revenue (million VND) over eight days.
| Temperature $x$ (°C) | $18$ | $20$ | $22$ | $25$ | $27$ | $29$ | $31$ | $33$ |
|---|---|---|---|---|---|---|---|---|
| Revenue $y$ | $45$ | $52$ | $48$ | $64$ | $70$ | $68$ | $82$ | $90$ |
Find the regression line of $y$ on $x$ and the coefficient $r$. Interpret the gradient. Predict the revenue at $24$°C and at $40$°C, then comment on the reliability of each prediction.
Solution
Step 1: run the regression on the GDC. Enter the two lists, choose LinReg:
$$y=2.905x-9.564,\qquad r=0.966,\qquad r^{2}=0.933$$Step 2: interpret the gradient in one sentence with units. For every $1$°C rise in temperature, the afternoon revenue increases on average by about $2.905$ million VND. The word “average” is not filler; the model does not say that every day it rises by exactly that much.
The intercept $-9.564$ can not be interpreted: it corresponds to $x=0$°C, very far from all the measured data, and negative revenue is meaningless. Being able to say this earns a separate mark in the real exam.
Step 3: two predictions.
$$x=24:\quad y=2.905(24)-9.564=60.2\ \text{million VND}$$$$x=40:\quad y=2.905(40)-9.564=106.6\ \text{million VND}$$Step 4: comment, and this is the part that earns marks. The data range from $18$°C to $33$°C. The value $24$°C lies within that range so it is interpolation: with $r=0.966$, the prediction of $60.2$ million is reliable.
The value $40$°C lies outside the range so it is extrapolation. Besides there being no evidence at all in that region, there is a practical reason too: at $40$°C people stay home rather than go out to buy ice cream, so the linear relationship is likely to break down. The prediction of $106.6$ million cannot be trusted.
Quick check of the whole problem: substituting $\bar x=25.625$ into the equation gives $2.905(25.625)-9.564=64.9=\bar y$. The regression line must pass through the mean point, so this test catches every error in entering numbers into the calculator.
Worked example: Spearman, outliers and the question of causation
Eight candidates are ranked from $1$ to $8$ by two judges. The sum of the squared rank differences is $\sum d^{2}=36$.
(a) Calculate $r_{s}$. (b) One of the eight pairs of scores is a clear outlier in value; explain why this affects Pearson's $r$ more than $r_{s}$. (c) Another study finds $r=0.88$ between the number of bookstores in a district and the number of burglaries. Comment.
Solution
(a) With $n=8$:
$$r_{s}=1-\frac{6\sum d^{2}}{n(n^{2}-1)}=1-\frac{6(36)}{8(64-1)}=1-\frac{216}{504}=1-0.4286=0.571$$The value is positive and moderate: the two judges tend to rank similarly, but the differences are still considerable.
(b) Pearson uses the values themselves, so one extreme point contributes a very large term to the sum of squares and drags the whole coefficient. Spearman replaces values with ranks: whether that candidate scored $98$ or $980$, their rank is still just $1$. The outlier is thereby compressed into a single rank step, and its influence almost disappears.
Practical consequence: when the scatter plot shows a monotonic but curved relationship, or has one or two stray points, $r_{s}$ describes the situation more honestly than $r$.
(c) A coefficient of $r=0.88$ is a strong correlation, but it cannot be concluded that bookstores cause burglary or the reverse. Most likely a third variable acts on both: the population of the district. A populous district has more bookstores and also more burglaries, and that alone produces the correlation without any direct link.
The check mentioned in AI papers: divide both quantities by the population to get a rate per ten thousand residents and then recompute $r$. If the correlation disappears, then population was indeed the confounding variable. An answer that only writes “correlation is not causation” without naming a specific third variable usually earns only half the marks.