IB MYP Extended Mathematics · Statistics and probability
Regression
1From a scatter graph to a model
Regression finds the equation of the line (or curve) that best fits a set of bivariate data, so that one variable can be predicted from the other.
- The independent (explanatory) variable, $x$, is the one used to predict.
- The dependent (response) variable, $y$, is the one predicted.
A line of best fit drawn by eye depends on who draws it. The regression line is calculated, so everyone gets the same answer.
The most common method is least squares: it chooses the line that makes the sum of the squares of the vertical distances from the points to the line as small as possible. Those vertical distances are called residuals.
The regression line of $y$ on $x$ has the form $y = ax + b$, and it always passes through the mean point $(\bar{x}, \bar{y})$.
In practice the equation comes from a graphing calculator or spreadsheet: enter the data in two lists and choose linear regression. Your job is to set it up correctly, and to interpret and judge the result.
Check yourself
Which point does a regression line always pass through?
Show the answer
The mean point
The least squares line passes through the mean of x and the mean of y.
2Finding the regression line
The gradient and intercept can be calculated from the data.
$$a = \frac{\sum (x - \bar{x})(y - \bar{y})}{\sum (x - \bar{x})^2}, \qquad b = \bar{y} - a\bar{x}$$
x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5
- Means: $\bar{x} = 3$ and $\bar{y} = 4$.
- Deviations in $x$: −2, −1, 0, 1, 2. Deviations in $y$: −2, 0, 1, 0, 1.
- Products: 4, 0, 0, 0, 2. Sum: 6.
- Squares of the $x$ deviations: 4, 1, 0, 1, 4. Sum: 10.
- Gradient: $a = 6 \div 10 = 0.6$.
- Intercept: $b = 4 - 0.6 \times 3 = 2.2$.
- Regression line: $y = 0.6x + 2.2$.
- Check: at $x = 3$, $y = 4$, the mean point.
A calculator gives the same line directly. Knowing the method shows where it comes from: the gradient compares how $x$ and $y$ vary together with how $x$ varies on its own.
Check yourself
A regression line is y = 0.6x + 2.2. What is the predicted y when x = 5?
Show the answer
5.2
0.6 × 5 + 2.2 = 5.2.
3The correlation coefficient
The correlation coefficient, $r$, measures the strength and direction of the linear relationship. It always lies between −1 and 1.
- $r = 1$: perfect positive correlation. All the points lie on a rising line.
- $r = -1$: perfect negative correlation.
- $r = 0$: no linear correlation.
- The closer $r$ is to 1 or −1, the stronger the correlation.
A rough guide for the size of $r$: below 0.3 weak; 0.3 to 0.7 moderate; above 0.7 strong.
The data above
- A calculator gives $r \approx 0.77$.
- This is a fairly strong positive correlation: as $x$ increases, $y$ tends to increase.
Important limits:
- $r$ measures linear relationships only. Points on a perfect curve, such as a parabola, can have $r$ close to 0.
- $r$ has no units and does not change if the units of the data change.
- A high $r$ does not show that one variable causes the other.
- $r$ from a small sample is unreliable, and a single outlier can change it greatly.
The value $r^2$ is the coefficient of determination: the proportion of the variation in $y$ explained by the linear relationship with $x$. Here $r^2 = 0.6$, so about 60% of the variation is explained.
Check yourself
What does a correlation coefficient of −0.95 show?
Show the answer
A strong negative linear correlation
It is close to −1, so the points lie close to a falling line.
4Interpreting and predicting
Interpret the gradient and intercept in context, with units.
Revision and scores
- For 12 students, with $x$ = hours of revision and $y$ = test score, the regression line is $y = 5.2x + 41$, with $r = 0.92$. The data cover 1 to 9 hours.
- Gradient: each extra hour of revision is associated with about 5.2 more marks.
- Intercept: a student who did no revision would be predicted to score about 41.
- Prediction for 6 hours: 5.2 × 6 + 41 = 72.2. This is interpolation, inside the data range, and $r$ is high, so it is reliable.
- Prediction for 20 hours: 5.2 × 20 + 41 = 145, which is impossible on a test out of 100. This is extrapolation, and it fails.
The regression line of $y$ on $x$ predicts $y$ from $x$. Do not rearrange it to predict $x$ from $y$: strictly, that needs the regression line of $x$ on $y$, which is a different line unless the correlation is perfect.
A prediction is reliable when:
- it is within the range of the data;
- the correlation is strong;
- the scatter graph looks linear;
- the sample is reasonably large.
Check yourself
A regression line was found from data with x between 10 and 50. For which x is a prediction most reliable?
Show the answer
x = 30
Only 30 is inside the range of the data.
5Residuals, outliers and other models
A residual is the difference between an actual value and the predicted value:
$$\text{residual} = \text{actual } y - \text{predicted } y$$
Residuals for y = 0.6x + 2.2
- At $x = 2$ the actual value is 4. Predicted: 0.6 × 2 + 2.2 = 3.4. Residual: +0.6. The point is above the line.
- At $x = 4$ the actual value is 4. Predicted: 4.6. Residual: −0.6. The point is below the line.
- For a least squares line, the residuals add to zero.
Residuals test whether a line is a suitable model. Plot them against $x$:
- scattered randomly about zero: a linear model is suitable;
- a clear pattern, such as a curve: the relationship is not linear, and another model is needed.
Other models: technology can fit quadratic, exponential and power curves. Choose using the scatter graph and the context.
- A quantity that grows by a constant percentage suggests an exponential model.
- A path under gravity suggests a quadratic model.
- Do not choose a model only because its $r^2$ is highest: it should also make sense.
Outliers have a large residual. Investigate each one. Correct it if it is an error; if it is genuine, report the regression with and without it and explain the difference.
Every model is a simplification. State the range over which it is valid, and what it leaves out.
Check yourself
At x = 10 the actual value of y is 28 and the regression line predicts 25. What is the residual?
Show the answer
3
Actual minus predicted: 28 − 25.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera