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.

18 23 28 33 nhiệt độ (°C) doanh thu 50 70 90 ngoại suy: không tin được phần dư −6,3 (25,6 ; 64,9) y = 2,905x − 9,564 r = 0,966
The regression line does not pass through the data points; it passes through exactly one required point, the mean point $(\bar x,\bar y)$ drawn as the green circle. This is the one property of the least-squares line that problems often ask about directly: substituting $\bar x=25.6$ into $y=2.905x-9.564$ gives $64.9=\bar y$, and that is true for every data set. The red point at $x=22$ illustrates the idea of a residual: the observed value is $48$ and the model gives $54.3$, so the residual is $48-54.3=-6.3$, meaning the line predicts higher than reality on that day. Least squares means the sum of the squares of vertical segments like this is as small as possible, not the perpendicular distance to the line. Finally, the pale dashed segment on the right is the extrapolation region: the data only span $18^\circ$ to $33^\circ$, so every prediction outside that range assumes the linear relationship still holds where it has never been measured. With $r=0.966$, $r^{2}=0.933$, meaning the model explains $93.3\%$ of the variation in revenue; the figure $96.6\%$ does not mean that and must not be written.

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.

Common mistake

Trap number one, and the one that costs the most marks: reporting $r$ when the problem asks for the proportion of variation explained. That proportion is $r^{2}$. With $r=0.966$ the answer is $93.3\%$, and $96.6\%$ is wrong; the two numbers are close so nothing gives it away. Trap number two: rearranging the regression equation to predict in the other direction. Solving $y=2.905x-9.564$ for $x$ to guess the temperature from revenue uses the wrong line; the line of $x$ on $y$ has a quite different gradient and must be rerun on the calculator. Trap number three: extrapolating without saying anything. The problem always plants a value outside the data range, and the mark lies in the comment, not in the number. Trap number four: reading the residual with the wrong sign. The residual is observed minus predicted; a negative residual means the point lies below the line, that is, the model predicts higher than reality. Trap number five: concluding causation. No matter how large $r$ is, to claim causation you need a controlled experiment, and in an AI problem there is always a plausible third variable ready to point out.

Key takeaway

A bivariate problem in AI always follows the same four beats: draw the scatter plot to see whether the relationship is linear, run the regression to get the equation and $r$, interpret the gradient in one sentence with units, then state clearly which predictions are interpolation and which are extrapolation. Skip the first beat and you may be fitting a line to a curve; skip the last and you lose exactly the marks reserved for modeling thinking.

← Sampling, summary statistics and outliers · All IB Math AI lessons · Practice IB Math AI questions (free, instant scoring) · Distributions and hypothesis tests: binomial, normal, chi-squared and t →