Free access until 31 December 2026 · Physics and Maths questions and notes, updated continuously · Build a test

ExaminerPrep › IB Maths AI › Notes

IB Maths AI · Topic 4 · 4.2 · SL and HL

Correlation and regression

This note covers how to measure and describe the relationship between two variables: scatter diagrams, Pearson's correlation coefficient, Spearman's rank correlation, and the least squares regression line. It also shows how to use a regression line for prediction and when such predictions can be trusted.

Key ideas

Scatter diagrams. Each pair of values \( (x, y) \) is plotted as one point. The explanatory (independent) variable \( x \) goes on the horizontal axis, and the response (dependent) variable \( y \) on the vertical axis. Look at the overall shape: does it rise, fall, or show no pattern? Is it roughly a straight line or curved? Are there points far from the rest?

Pearson's product-moment correlation coefficient \( r \). This measures how close the points are to a straight line.

  • \( -1 \le r \le 1 \).
  • The sign shows the direction: positive means \( y \) tends to increase as \( x \) increases; negative means \( y \) tends to decrease.
  • The size shows the strength. A common guide: \( |r| \) near 1 is strong, around 0.5 moderate, and near 0 weak or none. These labels are descriptions, not strict boundaries.
  • \( r = \pm 1 \) means all points lie exactly on a straight line. \( r = 0 \) means no linear relationship, but there could still be a curved one.
  • Find \( r \) using the two-variable statistics function on your GDC.

Correlation is not causation. Two variables can be strongly correlated because one causes the other, because both are driven by a third variable, or by coincidence. Statistics alone cannot show which.

Spearman's rank correlation coefficient \( r_s \). Replace each value by its rank (1 for the smallest, 2 for the next, and so on, separately for \( x \) and \( y \)), then calculate Pearson's \( r \) on the ranks. Ties receive the mean of the ranks they would have taken. \( r_s \) measures whether the relationship is monotonic, meaning that as \( x \) increases \( y \) always tends to increase (or always tends to decrease), even if it is curved. \( r_s = 1 \) means a perfectly increasing relationship and \( r_s = -1 \) a perfectly decreasing one. Spearman's coefficient is less affected by extreme values, and is the better choice when data is ranked or the pattern is clearly curved but steadily rising or falling.

Regression line of \( y \) on \( x \). The least squares regression line is \( y = ax + b \), the line that makes the sum of the squared vertical distances from the points as small as possible. Your GDC gives \( a \) and \( b \).

  • The gradient \( a \) is the average change in \( y \) for each one-unit increase in \( x \).
  • The intercept \( b \) is the predicted \( y \) when \( x = 0 \). It may be meaningless in context if \( x = 0 \) is far outside the data.
  • The line always passes through the mean point \( (\bar{x}, \bar{y}) \).
  • The line of \( y \) on \( x \) should be used to predict \( y \) from \( x \), not the other way round.

Prediction. Interpolation means predicting for an \( x \)-value inside the range of the data, which is reasonably reliable if \( |r| \) is large. Extrapolation means predicting outside that range. It assumes the pattern continues and is unreliable, even when \( r \) is close to 1.

Non-linear models (HL). When a scatter diagram is clearly curved, your GDC can fit other models, such as quadratic, cubic, exponential, power or sinusoidal functions. The coefficient of determination \( R^2 \) (between 0 and 1) tells you the proportion of the variation in \( y \) explained by the model; the closer to 1, the better the fit. A smaller sum of squared residuals also means a better fit. Choose a model that suits the shape and the context, not just the highest \( R^2 \).

Definitions and formulae

Term or formulaMeaning / when to use
\( r \)Pearson's correlation coefficient: strength and direction of a linear relationship.
\( r_s \)Spearman's rank correlation: strength and direction of a monotonic relationship.
\( y = ax + b \)Regression line of \( y \) on \( x \). Use it to predict \( y \).
\( (\bar{x}, \bar{y}) \)The mean point, which lies on the regression line.
Interpolation / extrapolationPrediction inside / outside the range of the data.
\( R^2 \)Coefficient of determination for a fitted model (HL).

Worked examples

Example 1 A kiosk records the midday temperature \( x \) (°C) and that day's ice cream sales \( y \) (£): \( (14, 110),\ (16, 125),\ (19, 150),\ (21, 148),\ (24, 190),\ (26, 205),\ (29, 230),\ (31, 250) \). (a) Find \( r \) and the regression line. (b) Interpret the gradient. (c) Predict sales at 25 °C and at 40 °C, and comment.

(a) Enter both lists in the two-variable statistics function on your GDC and select linear regression: \( r \approx 0.992 \) and \( y \approx 8.25x - 9.58 \).

The value of \( r \) is close to 1, so there is a strong positive linear correlation.

Check with the mean point: \( \bar{x} = 22.5 \), \( \bar{y} = 176 \). \( 8.248 \times 22.5 - 9.581 \approx 176 \). Correct.

(b) For each 1 °C rise in temperature, sales increase by about £8.25 on average.

(c) At 25 °C: \( 8.248 \times 25 - 9.581 \approx 196.6 \), so about £197. This is interpolation (25 is within 14 to 31), so it is reasonably reliable.

At 40 °C: \( 8.248 \times 40 - 9.581 \approx 320 \). This is extrapolation (40 is outside 14 to 31), so we cannot be sure the trend continues. It is unreliable.

Answer: \( r \approx 0.992 \); \( y = 8.25x - 9.58 \); £8.25 per °C; about £197 at 25 °C (reliable) and about £320 at 40 °C (unreliable).

Example 2 A biologist counts bacteria \( y \) (thousands) after \( x \) hours: \( (1,2),\ (2,5),\ (3,13),\ (4,30),\ (5,70),\ (6,180) \). Compare Pearson's \( r \) and Spearman's \( r_s \), and say which describes the data better.

On your GDC, Pearson's correlation is \( r \approx 0.861 \). The data curves upwards, so a straight line is not a perfect fit.

For Spearman, rank each variable. The \( x \) ranks are 1, 2, 3, 4, 5, 6. The \( y \) values are already increasing, so their ranks are also 1, 2, 3, 4, 5, 6.

The ranks match exactly, so \( r_s = 1 \).

Every increase in \( x \) is matched by an increase in \( y \): the relationship is perfectly monotonic, but not linear. \( r_s \) describes this better, and the curved shape also suggests an exponential model rather than a straight line.

Answer: \( r \approx 0.861 \), \( r_s = 1 \). The relationship is perfectly monotonic but not linear.

Example 3 A fitness study finds the regression line \( y = 4.2x + 15 \), where \( x \) is weekly training hours (data from 2 to 8 hours) and \( y \) is a fitness score, with \( r = 0.91 \). The mean training time is 5 hours. (a) Find the mean fitness score. (b) Predict the score for 6 hours and for 30 hours. (c) Does the study show that training raises fitness?

(a) The line passes through \( (\bar{x}, \bar{y}) \), so \( \bar{y} = 4.2(5) + 15 = 36 \).

(b) For 6 hours: \( 4.2(6) + 15 = 40.2 \). This is inside the data range (2 to 8), so it is a reasonable estimate. For 30 hours: \( 4.2(30) + 15 = 141 \). This is far outside the range, so the prediction is unreliable, and a fitness score is unlikely to keep rising at the same rate.

(c) A strong positive correlation \( r = 0.91 \) shows a strong association. It does not prove causation, since people who are already fit may choose to train more.

Answer: (a) 36; (b) 40.2 (reliable) and 141 (unreliable); (c) the study shows association, not proof of cause.

Common errors

  • Common error: saying "\( r = 0 \) means no relationship". It means no linear relationship.
  • Common error: stating that a high \( r \) shows one variable causes the other.
  • Common error: trusting extrapolated predictions because \( r \) is close to 1.
  • Common error: using the \( y \) on \( x \) regression line to predict \( x \) from \( y \).
  • Common error: interpreting the intercept literally when \( x = 0 \) is outside the data (for example, a negative sales figure at 0 °C).

Exam tip: When interpreting a gradient, write a sentence in context with units: "for each extra ... the ... increases by about ... on average". Mention whether a prediction is interpolation or extrapolation.

Check yourself

  1. A study gives \( r = -0.95 \). Describe the relationship.
    AnswerThere is a strong negative linear correlation: as \( x \) increases, \( y \) tends to decrease, and the points lie close to a straight line.
  2. For the data \( (1,9),\ (2,7),\ (3,6),\ (4,3),\ (5,2) \), the GDC gives the regression line \( y = -1.8x + 10.8 \). Predict \( y \) when \( x = 3.5 \) and check the line passes through the mean point.
    Answer\( y = -1.8(3.5) + 10.8 = 4.5 \). The means are \( \bar{x} = 3 \) and \( \bar{y} = 5.4 \); \( -1.8(3) + 10.8 = 5.4 \), so the line passes through the mean point.
  3. Two judges rank five dancers and Spearman's coefficient is \( r_s = -1 \). What does this say?
    AnswerThe rankings are exactly reversed: the dancer one judge ranked first, the other ranked last, and so on for every dancer.
  4. A line of best fit was calculated using ages from 20 to 60. Is it sensible to use it for a person aged 85? Explain.
    AnswerNo. 85 is outside the range of the data, so this is extrapolation. The relationship may not continue to hold, so the prediction is unreliable.