Study Blocks

World map › Linear functions & gradient › Lesson 7

Modelling real data: lines of best fit

⏱ about 50 min · MYP criteria A, B, C, D

By the end of this lesson you can…
🌍 The big question

Doctors use growth charts to check that children are growing healthily. Here are the median (middle) heights of boys at each birthday from age 2 to 12, taken from the World Health Organization’s growth charts and rounded to the nearest cm (so treat them as approximate):

age (years)23456789101112
height (cm)8796103110116122127133138143149

Between ages 4 and 12 the height goes up by roughly 6 cm every year. That looks almost linear.

So: if a boy keeps growing “like this”, how tall will he be at age 30? Make a guess — and decide whether you would trust it.

The points in this table are not perfectly on a straight line — real data never is. But they are close to one. Today you will learn to draw the straight line that best describes a cloud of real data, write its equation, use it to predict… and recognise the moment a prediction stops making sense.

🧪 Explore — try it, no scoring

Try these first. Nothing is marked: just have a go.

no hints, nothing is marked

A class measures a sunflower every 10 days (illustrative data):

day10203040
height (cm)30527193

Estimate the sunflower's height on day 25, in cm.

cm
no hints, nothing is marked

The sunflower in the table grew about 2 cm a day between day 10 and day 40. A friend continues this pattern and predicts that on day 400 the sunflower will be about 8 metres tall.

What do you think of the prediction?

no hints, nothing is marked

Water is heated in a kettle. Its temperature yy (°C) is read every minute xx (illustrative data):

xx (min)012345
yy (°C)203135394347

Two students suggest a line. Kim joins the first and last readings: y=5.4x+20y = 5.4x + 20. Lee suggests y=4x+27y = 4x + 27.

Which line describes the readings better? (Try putting some values of xx into each.)

Now fit a line to real data yourself.

  1. Drag the two green handles until your blue line follows the trend of the black points. Use the Balance readout: the main goal is that the total vertical distance above the line roughly cancels the total distance below it. The number of points on each side is a rougher guide.
  2. Is there a line that goes through every point? Does your line need to go through any of them? Does it need to go through (0,0)(0, 0)?
  3. Read your line’s equation. What does the number in front of aa mean for a growing child?
  4. Use the Predict slider. Try age 7.5, then 15, then 30, then 0. Watch the label change between interpolation and extrapolation.
  5. Tick reveal real heights outside the data. How good were your predictions at age 0 and age 19?
🎯 Predict first

Before you explore: a straight line drawn through these points and continued all the way to age 30 would predict a height of about…

Approximate median height of boys aged 2–12 (WHO growth charts, rounded to the nearest cm). Drag the two green handles to place your line of best fit.

→ age (years)↑ height (cm)
Your line: h=7.5a+69.5h = 7.5a + 69.5 (through (3,92)(3, 92) and (11,152)(11, 152))
Balance: 5 above · 5 below · 1 on the line distance above 14.5 cm · below 32.5 cm Points sit mostly below your line — lower it or tilt it.
Your model predicts 125.8 cm Interpolation — inside the data (ages 2–12). Fairly trustworthy.
🔎 What do you notice?
  • No straight line passes through all eleven points — the data bends slightly (children grow faster at 2–3 than at 10–11). A good line goes between the points, not through them.
  • A line that goes exactly through the first and last points is usually not the best: it ignores the nine points in the middle.
  • Good lines found by different people are slightly different — and that is fine. Most have a gradient close to 6 and pass close to (7,120)(7, 120), near the middle of the data.
  • Inside ages 2–12, predictions are close to the real values. Outside, they go wrong fast: about 78 cm at birth (a newborn is about 50 cm long) and over 2.5 m at age 30.
  • The gradient has a meaning — cm per year, the growth rate. The intercept is a “height at age 0” that the real data never says anything about.
  • Try-first 1. Day 25 lies between two measurements (52 cm on day 20, 71 cm on day 30), so an estimate of about 61 or 62 cm is pinned down by real data on both sides.
  • Try-first 2. The arithmetic (about 22 cm a day) is fine, but day 400 is ten times later than the last measurement on day 40, and a sunflower lives for only one growing season. Nothing in the data can warn you that the pattern stops.
  • Try-first 3. The line through the first and last readings, y=5.4x+20y = 5.4x + 20, was tilted by one unusual reading and missed all four readings in between. The line y=4x+27y = 4x + 27 is the better of the two: it follows the direction of five readings. It is not perfectly balanced, though: no reading is above it, so a balanced line would sit slightly lower. Two points chosen from the data are not the same as the trend of the data.
📐 Key idea

Lines of best fit

A scatter plot (also called a scatter graph or scatter diagram) shows paired data as points (x,y)(x, y). When the points roughly follow a straight-line trend, we can model them with a line of best fit (also called a trend line).

Drawing one by eye:

  • Follow the direction of the trend.
  • Balance them: the vertical distances of points above the line should roughly cancel those below it. Similar numbers of points on each side is a useful rough guide.
  • Because real data often curves slightly, the counts and the distances can disagree. The line h=6a+78h = 6a + 78 in the example has 6 points above, 3 below and 2 exactly on it — yet its distances come reasonably close to cancelling (9 cm in total above, 5 cm below: a net 4 cm spread over 11 points). Trust the distances more than the counts.
  • It does not have to pass through any data point, and not through the origin.

Finding its equation: pick two points on your line (not data points, unless the line goes exactly through them), far apart and easy to read. Then

m=y2−y1x2−x1,c=y1−mx1,y=mx+cm = \frac{y_2 - y_1}{x_2 - x_1}, \qquad c = y_1 - m x_1, \qquad y = mx + c

Interpreting it (always with units):

  • mm = the average change in yy for each 1 unit of xx (e.g. cm per year).
  • cc = the model’s value of yy when x=0x = 0 — meaningful only if x=0x = 0 is a sensible, nearby situation.
🔍 Why it works

Why balance, and why take the two points from the line

Why balance the distances? Count a distance as positive when the point is above the line and negative when it is below, and add them up. A big positive total means the points are, on average, above the line: it sits too low. Raising the line by dd makes every one of these distances dd smaller, so you can always slide it until the total is 00. Then the line runs through the middle of the data’s height. Balancing only fixes the height; following the direction of the trend fixes the tilt. A good line needs both. (The usual method in calculators and spreadsheets, called least squares, also makes this total 00. It fixes the tilt with a further rule that you will meet later.)

Why read the two points off the line? Your line is a summary of all the points. Each single data point also carries its own wobble: a measuring error, rounding, or simply a year that was a little different. An equation built from two data points copies those two wobbles and ignores every other point, as Try-first 3 showed. Points read off your line already carry the balance of all the data.

Why far apart? A small reading error matters less over a long run. If one point is misread by 22 cm, the gradient changes by 2÷1=22 \div 1 = 2 cm per year when the two points are 11 year apart, but only by 2÷8=0.252 \div 8 = 0.25 cm per year when they are 88 years apart.

📐 Key idea

Predicting: inside or outside the data

  • Interpolation = predicting inside the range of the data. Usually reliable.
  • Extrapolation = predicting outside it. The further outside, the riskier: the pattern may change or stop.
🔍 Why it works

Why trust drops outside the data

Inside, the data keeps the line honest. A prediction for age 7.5 sits between real measurements at ages 7 and 8, and the line stays close to both of them.

Outside, small differences grow. Take two lines for the growth data that both pass near (7,120)(7, 120): h=6a+78h = 6a + 78 and h=5.5a+82h = 5.5a + 82. They meet at age 8. Their gradients differ by 0.50.5 cm per year, so for every year you move away from age 8 they drift another 0.50.5 cm apart. From age 2 to age 12 they are never more than 0.5×6=30.5 \times 6 = 3 cm apart, but at age 30 they are 0.5×22=110.5 \times 22 = 11 cm apart. Nobody can know the gradient exactly, and the further out you go, the more that uncertainty is multiplied.

And the pattern itself may stop. The data cannot tell you what happens where nobody measured: children stop growing in their late teens, a battery charges more slowly when it is nearly full, prices change. Trust an extrapolation only a short way beyond the data, and only when you have a reason to believe the pattern carries on.

⚠️ Watch out

Three traps

  • Don’t use two data points just because they are there. The line of best fit summarises all the points. Read your two points off your line.
  • Don’t force the line through (0,0)(0, 0). Only do that if you know yy must be 0 when xx is 0 — and even then, check the data agrees.
  • Don’t trust the intercept blindly. In h=6a+78h = 6a + 78, the 78 is not “the height of a newborn”: age 0 is outside the data, and the real value is about 50 cm.
🧱 Worked example

A model for children's growth

Use the growth data from the Hook.

Step 1 — Draw the line and choose two points on it

Suppose your line of best fit passes through (4,102)(4, 102) and (10,138)(10, 138). These are points on the line, read from the grid (the data at age 4 is 103, not 102 — the line runs just below that point, which is fine).

Step 2 — Gradient, with units

m=138−10210−4=366=6 cm per yearm = \frac{138 - 102}{10 - 4} = \frac{36}{6} = 6\ \text{cm per year}

Step 3 — Intercept and equation

Substitute (4,102)(4, 102) into h=6a+ch = 6a + c:   102=24+c\;102 = 24 + c, so c=78c = 78.

h=6a+78h = 6a + 78

Check with the other point: 6×10+78=1386 \times 10 + 78 = 138 ✓.

Step 4 — Interpret
  • Gradient 6: between ages 2 and 12, the median boy grows about 6 cm per year on average.
  • Intercept 78: the model’s “height at age 0”. Age 0 is outside the data, so we must not read this as a real birth length.
Step 5 — Predict (interpolation)

Age 7.5 (seven and a half): h=6×7.5+78=45+78=123h = 6 \times 7.5 + 78 = 45 + 78 = 123 cm. That lies between the data values at 7 (122 cm) and 8 (127 cm) — believable.

Step 6 — Is the answer sensible? (extrapolation)

Age 30: h=6×30+78=258h = 6 \times 30 + 78 = 258 cm. Not sensible. People stop growing in their late teens, so a typical adult man is about 165–180 cm in most countries, and 258 cm is almost as tall as the tallest person ever recorded (about 272 cm). Age 0: h=78h = 78 cm — but newborns are about 50 cm long.

Conclusion: the model h=6a+78h = 6a + 78 is good for ages about 2 to 12 — the range of the data. Outside it, the real pattern changes (fast growth in babies, a growth spurt in the teens, then no growth at all), and the straight line cannot know that.

IB Standard

A student's line of best fit for the growth data passes through the points (3,96)(3, 96) and (11,144)(11, 144) on the line.

Find the equation of the line. Use xx for age (years) and yy for height (cm).

→ age (years)↑ height (cm)
Foundation

The growth model was built from data for ages 2 to 12. Which prediction is an interpolation?

🎬 Another explanation

Still stuck after the example? Hearing it from another teacher often helps. These videos were checked against this lesson. Try the questions again afterwards.

Scatter Graphs - Corbettmaths · corbettmaths · about 8 min

Plotting real bird measurements, drawing a line of best fit by eye with a ruler, using it to estimate a value, and why estimating far outside the data is not sensible.

Same idea, different words: The video also names types of correlation, which this lesson does not need. It says to keep an equal number of points above and below the line; remember to balance the distances above and below as well.

WCLN - Math - Interpolation & Extrapolation · WCLN · about 6 min

What interpolation and extrapolation mean, and why a prediction made outside your data is less trustworthy, because the pattern might change there.

🤔 Pause and think

Can a straight-line model ever be trusted to predict the future?

Predicting the future is always extrapolation — the future is outside the data by definition. Yet scientists, economists and engineers do it every day.

When would you trust a straight-line prediction for next year? For the next 50 years? What would make you more confident: more data, data over a longer time, a reason why the pattern should continue…? Can you think of a trend that was linear for a while and then suddenly stopped?

⛏ Practice — choose your level

Which line is the best line of best fit for these points?

🏗 Build project — real-life task

How long to charge the electric car?

A family’s electric car is plugged into a fast charger. Their daughter records the battery level every 5 minutes (illustrative data):

time tt (min)0510152025
battery BB (%)122232435162

She plots the points and draws a line of best fit that passes through (0,12)(0, 12) and (20,52)(20, 52). Answer the questions in order, and keep asking: does this make sense for a real car?

IB StandardCriterion D

Find the equation of the line of best fit through (0,12)(0, 12) and (20,52)(20, 52). Use tt for time in minutes and BB for battery %.

IB StandardCriterion D

Use your model to estimate the battery level (in %) after 17 minutes.

%
FoundationCriterion D

The battery was measured from 0 to 25 minutes. Is your estimate for 17 minutes an interpolation or an extrapolation?

IB StandardCriterion D

According to the model, how many minutes after plugging in will the battery reach 100%?

min
ExtensionCriterion D

The family plans their journey assuming the car will be full after 44 minutes. Is that reasonable?

Discuss: interpolation vs extrapolation here, what really happens to charging speed as a battery gets full, and what you would recommend to the family. Mention at least one other limitation of the model.

📓 Work it out in your notebook first — sketch, calculate, then write your answer here in full sentences. A model answer appears after you submit, so you can compare.

🔗 Connections

Lines of best fit are a basic tool in every science lab: stretching a spring (Hooke’s law — linear only up to a limit), heating water, the speed of a cart down a ramp. In geography they show trends in population or temperature; in sport, in training data. Two big ideas come next in your maths journey: correlation (how strongly points follow a line) and the warning that correlation is not causation — two things can rise together without one causing the other. And in later years you will meet models that curve, for data that a straight line can’t capture. Next: lines that meet at right angles, and lines written in a new form, ax+by=dax + by = d.

🪞 Reflect

Explain the difference between interpolation and extrapolation to someone who missed today's lesson. Use the growth data as your example.

Your line of best fit and a friend's are slightly different. Is one of you wrong? How would you decide whose line is better?