# Correlation and linear regression

> IB Mathematics Applications and Interpretation HL · Unit 5: Statistics and probability
> Source: https://www.owlsprep.com/study/ib-math-ai-hl-u5-correlation-and-linear-regression/

This subtopic covers analysis of linear relationships between two continuous bivariate variables. You will learn to measure correlation strength, fit least squares regression lines, and interpret results for prediction, a core exam and IA skill.

**Prerequisites:** [Descriptive statistics (mean, standard deviation)](https://www.owlsprep.com/study/ib-math-ai-hl-u4-descriptive-statistics/); [Linear equations and functions](https://www.owlsprep.com/study/ib-math-ai-hl-u1-linear-functions/)

## Learning objectives

- Distinguish between correlation and causation in bivariate data
- Calculate and interpret Pearson's product-moment correlation coefficient
- Fit and interpret a least squares linear regression line
- Distinguish between interpolation and extrapolation and assess prediction reliability
- Use regression lines to make predictions for the response variable

## Bivariate Data and Correlation

Bivariate data describes pairs of values for two different variables collected from the same sample. We use scatter graphs to visualize relationships between variables, and Pearson's correlation coefficient to quantify the strength of linear relationships.

**Pearson's Correlation Coefficient** — A numerical measure of the strength and direction of the linear relationship between two continuous variables, ranging from $-1$ to $+1$.

*Notation:* $r$

*Example:* $r=1$ = perfect positive linear correlation, $r=-1$ = perfect negative linear correlation, $r=0$ = no linear correlation.

General interpretation guidelines: $|r| > 0.75$ = strong correlation, $0.25 < |r| < 0.75$ = moderate correlation, $|r| < 0.25$ = weak/no linear correlation.

**Worked example:** For the data $x = [1, 2, 3, 4, 5]$, $y = [2, 4, 5, 7, 9]$, calculate $r$ and interpret the result.

1. 1. Calculate sample means:
2. $$\bar{x} = 3, \quad \bar{y} = 5.4$$
3. 2. Calculate sample standard deviations:
4. $$s_x \approx 1.581, \quad s_y \approx 2.702$$
5. 3. Calculate covariance: $\text{Cov}(x,y) \approx 4.2$
6. 4. Use the formula $r = \frac{\text{Cov}(x,y)}{s_x s_y}$:
7. $$r \approx \frac{4.2}{(1.581)(2.702)} = 0.984$$
8. Interpretation: There is a very strong positive linear relationship between $x$ and $y$.

> **Exam tip:** Always use your GDC to calculate $r$ in exams, manual calculation is rarely required.

## Least Squares Regression Line

A regression line models the linear relationship between two variables. The least squares method fits the line by minimizing the sum of squared vertical distances (residuals) between observed and predicted $y$ values.

**y on x Regression Line** — A line used to predict the value of the response variable $y$ from the explanatory variable $x$. It always passes through the point $(\bar{x}, \bar{y})$.

*Notation:* $y = a + bx$

*Example:* The gradient $b = r \frac{s_y}{s_x}$ and the intercept $a = \bar{y} - b\bar{x}$.

We use different lines for different prediction goals: $y$ on $x$ predicts $y$ from $x$, and $x$ on $y$ predicts $x$ from $y$. The two lines are not the same.

**Worked example:** Using the previous data ($r \approx 0.984$, $\bar{x}=3$, $\bar{y}=5.4$, $s_x \approx 1.581$, $s_y \approx 2.702$), find the $y$ on $x$ regression line and interpret the gradient.

1. 1. Calculate the gradient $b$:
2. $$b = 0.984 \times \frac{2.702}{1.581} \approx 1.68$$
3. 2. Calculate the intercept $a$:
4. $$a = 5.4 - (1.68)(3) = 0.36$$
5. 3. Final equation:
6. $$y = 0.36 + 1.68x$$
7. Interpretation: For every 1 unit increase in $x$, $y$ is predicted to increase by 1.68 units on average.

> **Exam tip:** Use the fact that the line passes through $(\bar{x}, \bar{y})$ to check your answer in exams.

## Prediction: Interpolation vs Extrapolation

Regression lines are used to predict unknown values of the response variable. The reliability of a prediction depends on whether the input value falls inside or outside the range of the original collected data.

> **info**
>
> **Interpolation**: Predicting for an input within the range of original data. **Extrapolation**: Predicting for an input outside the range of original data.

Interpolation is generally reliable because we know the linear relationship holds for this range. Extrapolation is unreliable because we have no evidence the linear relationship continues outside the observed range.

**Worked example:** Using the regression line $y = 0.36 + 1.68x$ (original $x$ ranges from 1 to 5), predict $y$ for $x=3.5$ and $x=10$, and comment on reliability.

1. For $x=3.5$:
2. $$y = 0.36 + 1.68(3.5) = 6.24$$
3. Comment: $x=3.5$ is inside the original range of 1 to 5, so this is interpolation. The prediction is reliable.
4. For $x=10$:
5. $$y = 0.36 + 1.68(10) = 17.16$$
6. Comment: $x=10$ is outside the original range, so this is extrapolation. The prediction is unreliable, as we do not know if the linear relationship continues to $x=10$.

## Correlation vs Causation

A common misconception is that a strong correlation between two variables proves that one causes the other. This is not true, and correlation can arise from multiple non-causal scenarios.

> **warning**
>
> Correlation does not imply causation. A strong correlation can be caused by: (1) a direct causal link, (2) a third lurking variable that affects both variables, or (3) random coincidence.

**Worked example:** A study finds a strong positive correlation between monthly ice cream sales and monthly drowning deaths. Does ice cream sales cause drowning?

1. 1. Observe that there is a strong positive correlation, but no obvious direct link.
2. 2. Identify the lurking variable: temperature. Higher temperatures increase both ice cream sales and the number of people swimming, leading to more drownings.
3. 3. Conclusion: There is no causal relationship between ice cream sales and drowning deaths. The correlation is explained by the lurking variable.

> **Exam tip:** Always explicitly state that correlation does not imply causation when asked to interpret results in exams.

## Common pitfalls

- **Wrong:** Claiming a strong correlation proves causation
  - Why it fails: Correlation only measures association, not a directional causal link, and can be explained by lurking variables
  - Correct: Always explicitly state that correlation does not imply causation unless experimental evidence confirms a causal link
- **Wrong:** Treating extrapolated predictions as equally reliable as interpolated predictions
  - Why it fails: The linear relationship is only validated for the range of observed data
  - Correct: Always flag extrapolated predictions as unreliable when discussing results
- **Wrong:** Using an x on y regression line to predict y from x
  - Why it fails: Regression lines are fitted to minimize error for a specific response variable, so the wrong line gives biased predictions
  - Correct: Use the y on x line to predict y from x, and the x on y line to predict x from y
- **Wrong:** Assuming a near-zero correlation means no relationship exists
  - Why it fails: Pearson's r only measures linear correlation, and strong non-linear relationships can give a near-zero r
  - Correct: Always plot a scatter graph to check for non-linear patterns before concluding no relationship exists
- **Wrong:** Rounding regression coefficients to 2 decimal places early in calculations
  - Why it fails: Early rounding introduces significant error into final predictions
  - Correct: Keep full unrounded coefficients stored in your GDC until the final step of your calculation

## Cheatsheet

| Concept | Key Value/Formula | Note |
| --- | --- | --- |
| Pearson's $r$ | $-1 \leq r \leq 1$ | Measures strength of linear correlation |
| Strong correlation | $\|r\| > 0.75$ | Clear linear trend |
| Weak correlation | $\|r\| < 0.25$ | No clear linear trend |
| y on x line | $y = a + bx$ | Predict $y$ from $x$ |
| Gradient $b$ | $b = r \frac{s_y}{s_x}$ | Change in $y$ per unit $x$ |
| Intercept $a$ | $a = \bar{y} - b\bar{x}$ | Predicted $y$ when $x=0$ |
| Interpolation | Predict within data range | Generally reliable |
| Extrapolation | Predict outside data range | Usually unreliable |
| Core rule | Correlation $\neq$ Causation | Always mention lurking variables |

## What's next

Correlation and linear regression form the foundation of all statistical modeling for IB AI HL. These skills are directly applicable to your internal assessment, where you will be expected to analyze relationships between variables in your own dataset. Next, you will extend these ideas to non-linear regression, where you transform non-linear relationships to fit a linear model, and learn how to test if an observed correlation is statistically significant. Mastery of this subtopic is critical for all further statistical work in the course.

- [Probability concepts, conditional probability, independent events](https://www.owlsprep.com/study/ib-math-ai-hl-u5-probability-concepts-conditional-probability-independent/)
- [Probability distributions: expected value and variance](https://www.owlsprep.com/study/ib-math-ai-hl-u5-probability-distributions-expected-value-and/)
- [Binomial, Poisson and normal distributions](https://www.owlsprep.com/study/ib-math-ai-hl-u5-binomial-poisson-and-normal-distributions/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/ib-math-ai-hl-u5-correlation-and-linear-regression/
