IB MATHEMATICS: APPLICATIONS AND INTERPRETATION • FUNCTIONS

Regression & Model Comparison — AHL 2.8 Further regression and model comparison; residuals and goodness-of-fit (HL)

Learn to fit the best mathematical model to real-world data using residuals and the coefficient of determination.

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
Adrien-Marie Legendre published the method of least squares, providing a systematic way to minimize the total squared distance between data points and a fitted line.
1809
Gauss's Normal Distribution Link
Carl Friedrich Gauss demonstrated that least squares yields the best estimates when errors follow a normal distribution, giving the method a strong theoretical foundation.
1886
Galton Coins 'Regression'
Francis Galton introduced the term regression while studying how children's heights tend to 'regress' toward the average height of the population.
1920s
R² and Goodness-of-Fit
Ronald Fisher and others formalized the coefficient of determination (R²), giving researchers a single number to judge how well a model captures the variation in data.
1970s–today
Computer-Driven Model Comparison
With modern computing, analysts can quickly fit linear, quadratic, exponential, power, and other models to the same dataset and compare their R² values to choose the best fit.

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.

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.

1

Regression Model

A mathematical function (linear, quadratic, exponential, etc.) fitted to data using a method like least squares. The model generates a predicted value (ŷ) for every input x.
2

Residual

The difference between the observed value (y) and the predicted value: residual = y − ŷ. Positive means the data point sits above the curve; negative means it sits below.
3

Coefficient of Determination (R²)

A number between 0 and 1 that tells you the proportion of the data's variation explained by the model. An R² of 0.95 means the model captures 95% of the variability.
4

Sum of Squared Residuals (SSres)

The total of all squared residuals: Σ(y − ŷ)². A smaller SSres means the model's predictions are closer to the actual data.
5

Model Comparison

The process of fitting several different types of functions to the same dataset and choosing the one with the highest R² (or the most randomly scattered residuals) as the best-fit model.
KEY TAKEAWAY
Think of regression like trying on different shoes. A linear model is a sneaker — it works for many situations but not all. A quadratic model is a hiking boot — great for hills. The residuals are like checking whether the shoe pinches (data points far from the curve). R² is your overall comfort score: the closer to 1, the better the fit.

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.

Each cyan dot is an observed data point. The dashed violet line is the regression model. The vertical dashed segments show residuals: green = positive (data above line) and red = negative (data below line).

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².

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
eᵢ = yᵢ − ŷᵢ
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
SSres = Σ(yᵢ − ŷᵢ)²
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
SStot = Σ(yᵢ − ȳ)²
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² = 1 − (SSres / SStot)
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
On IB AI HL papers, you may be given R² values from several models and asked to justify which one is most appropriate. Always state the R² value, note whether residuals show a pattern, and consider real-world reasonableness. A model with R² = 0.97 and randomly scattered residuals is preferred over one with R² = 0.98 but a clear pattern in its residuals.

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.

Summary of regression model types for IB AI HL
Model TypeEquation FormTypical ShapeWhen to Use
Lineary = ax + bStraight lineConstant rate of change
Quadraticy = ax² + bx + cParabola (U-shape)Data rises then falls (or vice versa)
Cubicy = ax³ + bx² + cx + dS-curve or waveTwo turning points visible in data
Exponentialy = a × bˣ + cRapid growth or decayPopulation growth, radioactive decay
Powery = axⁿCurve through originScaling laws, physics relationships
Sinusoidaly = a sin(bx + c) + dOscillating waveSeasonal or periodic data
The same eight data points are fitted with four different models. The power model (R² = 0.96) provides the highest R² in this example, meaning it explains the most variation in the data.

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.

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.

Bacterial colony mass over time
Time (hours)Mass (mg)
02.0
12.8
24.2
35.9
48.5
512.1
Comparing Linear vs. Exponential Regression
1
Step 1 — Enter Data into GDCEnter 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 ModelUse 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 ModelUse 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 ModelsFor 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 JustifyThe 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

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.

1

Interpolation

Using the regression model to predict a y-value for an x-value that lies within the range of the original data. For example, if data was collected for x = 0 to x = 10, predicting at x = 6 is interpolation. This is generally considered reliable, because the model has been tested across the surrounding values.
2

Extrapolation

Using the regression model to predict a y-value for an x-value that lies outside the range of the original data. For example, if data was collected for x = 0 to x = 10, predicting at x = 20 is extrapolation. This is unreliable because the model's pattern may not continue beyond the observed range.
The blue shaded region shows the range of the original data. Predictions within this range (interpolation) are generally reliable. Predictions beyond this range (extrapolation, red region) are unreliable because the model's pattern may not continue. The dashed section of the curve beyond x = 7 illustrates this uncertainty.
Key differences between interpolation and extrapolation
FeatureInterpolationExtrapolation
x-value locationWithin the range of observed dataOutside the range of observed data
ReliabilityGenerally reliable — the model has been validated across the surrounding regionUnreliable — the pattern established by the data may not continue
Risk levelLowHigh — the further outside the data range, the greater the uncertainty
IB requirementAcceptable to use the model for predictionsMust acknowledge limitations; state that prediction may not be valid
ExampleData for t = 0 to 10; predicting at t = 6Data for t = 0 to 10; predicting at t = 25
💡 IB Exam Tip
IB AI HL exam questions frequently ask you to use a regression model to predict a value and then comment on the reliability of that prediction. Always check: is the x-value inside or outside the data range? If it is outside, you must state that this is extrapolation and that the prediction may not be reliable. Failing to comment on this costs marks. A good response identifies the x-value, states whether it is interpolation or extrapolation, and explains why extrapolation carries risk.

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.

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 and limitations of regression analysis tools
StrengthsLimitations
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.
KEY TAKEAWAY
R² is like a student's overall grade — it tells you how well they're doing on average, but it doesn't show which specific questions they got wrong. The residual plot is like looking at the test paper: it reveals exactly where the model struggles. Always use both together.

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.

How IB concepts connect to university-level statistics
IB AI HL ConceptAdvanced Extension
R² (coefficient of determination)Adjusted R², which penalizes models for having too many parameters — addresses the limitation of R² always increasing.
Visual residual analysisFormal hypothesis tests on residuals (e.g., Durbin-Watson test for autocorrelation, Shapiro-Wilk test for normality).
Comparing 2–3 model typesInformation 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.

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.

Practice Problems

PROBLEM 1CONCEPTUAL
A student fits a linear model to a dataset and obtains R² = 0.95. They then plot the residuals against x and see a clear U-shaped curve. Should they conclude the linear model is appropriate? Explain your reasoning.
PROBLEM 2BASIC CALCULATION
A regression model predicts ŷ = 14.3 for a data point whose actual value is y = 17.1. Calculate the residual and explain what the sign tells you.
PROBLEM 3INTERMEDIATE
Given SStot = 480 and SSres = 36, calculate R². If a different model applied to the same data gives SSres = 24, what is the new R²? Which model is better according to R²?
PROBLEM 4APPLIED
A city planner collects data on commute distance (km) and commute time (minutes) for 50 residents. A linear model gives R² = 0.78 and a power model gives R² = 0.89. The linear residual plot shows a clear fan shape (residuals spread out as x increases). The power residual plot looks random. Which model should the planner use for predicting commute times, and why?
PROBLEM 5CRITICAL THINKING
A student fits a degree-5 polynomial to 7 data points and obtains R² = 0.999. They claim this is clearly the best model. Evaluate this claim. What potential problems exist, and what advice would you give the student?

Lesson 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.

Varsity Tutors • IB Mathematics: Applications and Interpretation • Regression & Model Comparison