SECTION 1
Historical Context & Motivation
Humans have always tried to find patterns in data. Long before computers, astronomers and mathematicians sought ways to draw the "best" curve through measured observations. The idea of regression — fitting a mathematical function to data points — grew from the practical need to predict planetary orbits, population growth, and economic trends. Over centuries, this single idea evolved into one of the most powerful tools in modern statistics.
1805 • Legendre's Least Squares
1809 • Gauss's Normal Distribution Link
1886 • Galton Coins 'Regression'
1920s • R² and Goodness-of-Fit
1970s–today • Computer-Driven Model Comparison
The central question this topic addresses is straightforward: when you have a set of data, which type of function — linear, quadratic, cubic, exponential, power, or sinusoidal — best describes the pattern? And how do you measure "best"? The answers lie in residual analysis and goodness-of-fit statistics.
SECTION 2
Core Principles & Definitions
Before diving into calculations, you need a clear understanding of the key ideas that underpin regression and model comparison. These concepts work together like a toolkit: the regression model provides a prediction, residuals tell you how far off those predictions are, and R² summarizes the overall quality of the fit.
Regression Model
Residual
Coefficient of Determination (R²)
Sum of Squared Residuals (SSres)
Model Comparison
KEY TAKEAWAY
SECTION 3
Visual Explanation — Residuals on a Scatter Plot
The diagram below shows six data points with a fitted linear regression line. The vertical segments between each point and the line represent the residuals. Notice that some segments point upward (positive residuals) and some point downward (negative residuals). In a good model, these residuals should appear randomly scattered — no obvious pattern. If the residuals show a curve, a non-linear model may be a better choice.
In the diagram, notice that the two leftmost points sit below the line, the middle points sit above, and the rightmost point is close to the line. This pattern — negative, then positive, then negative — hints that the data may curve, and a quadratic model might yield smaller residuals and a higher R².
SECTION 4
Mathematical Framework
The mathematics behind regression and model comparison rests on a few core formulas. Your GDC (graphing display calculator) handles the heavy computation, but understanding what the formulas mean helps you interpret results and explain your reasoning on IB exams.
RESIDUAL
where eᵢ is the residual for the i-th data point, yᵢ is the observed value, and ŷᵢ is the predicted value from the regression model.
SUM OF SQUARED RESIDUALS
We square each residual so that positive and negative values don't cancel out, then sum them. A smaller SSres means the model's curve hugs the data more closely.
TOTAL SUM OF SQUARES
This measures the total variability in the y-values. Here ȳ is the mean of all observed y-values. SStot serves as a baseline — it's what you'd get if your "model" were just the horizontal line y = ȳ.
COEFFICIENT OF DETERMINATION
R² ranges from 0 to 1. If SSres = 0 (perfect fit), then R² = 1. If SSres = SStot (model no better than the mean), R² = 0.
IB Exam Tip
SECTION 5
Comparing Different Regression Models
In IB AI HL, you are expected to use your GDC to fit several types of models to the same dataset and then decide which fits best. The table below summarizes the regression types you should know, along with their general shapes and typical applications.
| Model Type | Equation Form | Typical Shape | When to Use |
|---|---|---|---|
| Linear | y = ax + b | Straight line | Constant rate of change |
| Quadratic | y = ax² + bx + c | Parabola (U-shape) | Data rises then falls (or vice versa) |
| Cubic | y = ax³ + bx² + cx + d | S-curve or wave | Two turning points visible in data |
| Exponential | y = a × bˣ + c | Rapid growth or decay | Population growth, radioactive decay |
| Power | y = axⁿ | Curve through origin | Scaling laws, physics relationships |
| Sinusoidal | y = a sin(bx + c) + d | Oscillating wave | Seasonal or periodic data |
Summary of regression model types for IB AI HL
When comparing models, don't just pick the highest R². Always check the residual plot for patterns. A model with slightly lower R² but randomly scattered residuals is often more reliable than one with higher R² but patterned residuals, because patterns suggest the model is systematically missing something in the data's behavior.
SECTION 6
Worked Example — Choosing the Best Model
A biologist measures the mass of a bacterial colony (in mg) over several hours. The data is shown below. We will fit a linear and an exponential model, calculate residuals, and compare R² values.
| Time (hours) | Mass (mg) |
|---|---|
| 0 | 2.0 |
| 1 | 2.8 |
| 2 | 4.2 |
| 3 | 5.9 |
| 4 | 8.5 |
| 5 | 12.1 |
Bacterial colony mass over time
Comparing Linear vs. Exponential Regression
- 1
Step 1 — Enter Data into GDC
Enter time values into List 1 (L1) and mass values into List 2 (L2) on your GDC. This is the raw data that both regression models will be fitted to. - 2
Step 2 — Fit a Linear Model
Use the linear regression function (LinReg) on your GDC. The calculator returns: y = 1.91x + 0.48. The GDC also reports R² = 0.964.Linear model: y = 1.91x + 0.48, R² = 0.964 - 3
Step 3 — Fit an Exponential Model
Use the exponential regression function (ExpReg). The calculator returns: y = 1.95 × 1.39ˣ. The GDC reports R² = 0.998.Exponential model: y = 1.95 × 1.39ˣ, R² = 0.998 - 4
Step 4 — Calculate Residuals for Both Models
For each data point, compute e = y − ŷ using the linear model ŷ = 1.91t + 0.48. The calculations are: t = 0: ŷ = 0.48, e = 2.0 − 0.48 = +1.52; t = 1: ŷ = 2.39, e = 2.8 − 2.39 = +0.41; t = 2: ŷ = 4.30, e = 4.2 − 4.30 = −0.10; t = 3: ŷ = 6.21, e = 5.9 − 6.21 = −0.31; t = 4: ŷ = 8.12, e = 8.5 − 8.12 = +0.38; t = 5: ŷ = 10.03, e = 12.1 − 10.03 = +2.07. The signs follow a positive, positive, negative, negative, positive, positive pattern — a U-shape — indicating the linear model systematically underestimates at both ends and overestimates in the middle. This curved pattern in the residuals is a clear signal that a non-linear model is more appropriate. For the exponential model: at t = 0, ŷ = 1.95 × 1.39⁰ = 1.95, so e = 2.0 − 1.95 = 0.05. The exponential residuals are all small and show no clear pattern.Linear residuals show a U-shaped pattern (positive, positive, negative, negative, positive, positive); exponential residuals are randomly scattered. - 5
Step 5 — Compare and Justify
The exponential model has a higher R² (0.998 vs. 0.964) and its residuals show no systematic pattern. Both criteria point to the same conclusion: the exponential model is the better fit for this data. This makes sense biologically, since bacterial growth is expected to be exponential in the early stages.Best model: y = 1.95 × 1.39ˣ (exponential), R² = 0.998
SECTION 7
Interpolation vs. Extrapolation
Once you have fitted a regression model, you can use it to make predictions. However, where you make those predictions matters enormously. The IB AI HL specification explicitly requires you to understand the distinction between interpolation and extrapolation, and this distinction is frequently assessed on IB papers.
Interpolation
Extrapolation
| Feature | Interpolation | Extrapolation |
|---|---|---|
| x-value location | Within the range of observed data | Outside the range of observed data |
| Reliability | Generally reliable — the model has been validated across the surrounding region | Unreliable — the pattern established by the data may not continue |
| Risk level | Low | High — the further outside the data range, the greater the uncertainty |
| IB requirement | Acceptable to use the model for predictions | Must acknowledge limitations; state that prediction may not be valid |
| Example | Data for t = 0 to 10; predicting at t = 6 | Data for t = 0 to 10; predicting at t = 25 |
Key differences between interpolation and extrapolation
IB Exam Tip
Consider a concrete example: a model fitted to bacterial growth data for hours t = 0 to 5 (as in the worked example) gives y = 1.95 × 1.39ˣ. Predicting the mass at t = 3 (interpolation) is reliable. Predicting the mass at t = 20 (extrapolation) is not, because the exponential model would suggest an unrealistically large colony mass, and real bacterial growth is eventually limited by resources. The mathematical model does not know about those real-world constraints — only the analyst does.
SECTION 8
Strengths & Limitations of R² and Residual Analysis
R² and residual analysis are powerful tools, but like any tool, they have boundaries. Understanding both their strengths and limitations will help you avoid common pitfalls on exams and in real-world applications.
| Strengths | Limitations |
|---|---|
| R² gives a single, easy-to-interpret number for model quality (0 to 1). | R² always increases (or stays the same) when you add more parameters, even if the extra complexity isn't justified. |
| Residual plots reveal systematic patterns that a single number like R² might miss. | Residual analysis requires visual judgment, which can be subjective with small datasets. |
| Can compare completely different model types (e.g., exponential vs. quadratic) on the same data. | A high R² doesn't mean the model is correct — it only means the model fits the observed data well. Extrapolation is risky. |
| Identifying a good model allows reliable interpolation within the data range. | Outliers can heavily distort both R² and the fitted model, especially with small samples. |
Strengths and limitations of regression analysis tools
KEY TAKEAWAY
SECTION 9
Connection to Advanced Theory
The regression and model comparison skills you learn in IB AI HL form the foundation for more sophisticated statistical methods used in university courses and professional data science. The table below shows how the concepts you've mastered connect to what comes next.
| IB AI HL Concept | Advanced Extension |
|---|---|
| R² (coefficient of determination) | Adjusted R², which penalizes models for having too many parameters — addresses the limitation of R² always increasing. |
| Visual residual analysis | Formal hypothesis tests on residuals (e.g., Durbin-Watson test for autocorrelation, Shapiro-Wilk test for normality). |
| Comparing 2–3 model types | Information criteria (AIC, BIC) that balance model fit against complexity, allowing comparison of dozens of models. |
| Single independent variable (x) | Multiple regression with several independent variables (x₁, x₂, x₃, …) — used heavily in economics, medicine, and machine learning. |
How IB concepts connect to university-level statistics
If you continue into statistics, data science, or any science that relies on modeling, the intuition you build now — checking residuals, comparing R² values, and thinking critically about whether a model makes contextual sense — will serve you in every course. The core logic never changes, even as the tools grow more sophisticated.
SECTION 10
Practice Problems
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Lesson Summary
Summary
In this lesson you learned that regression is the process of fitting a mathematical function — linear, quadratic, cubic, exponential, power, or sinusoidal — to a set of data points. A residual (e = y − ŷ) measures the vertical distance between each observed value and the model's prediction. By squaring and summing all residuals, you get SSres, and comparing it to the total variation SStot gives you the coefficient of determination R² = 1 − (SSres / SStot).
To choose the best model, fit multiple regression types to the same data using your GDC, then compare their R² values — higher is better — and examine residual plots for patterns. A good model has a high R² and randomly scattered residuals. When using a model to make predictions, always distinguish between interpolation (predicting within the data range — reliable) and extrapolation (predicting outside the data range — unreliable). Always consider real-world context — does the model type make sense for the situation? — and beware of overfitting, where an overly complex model fits the noise rather than the true pattern.