KS Maths
Topic 4.13 · AI Higher Level only

Non-linear regression and sum of squared residuals

When a line is the wrong shape

Fitting curves, measuring the fit, and the reason the smallest number is not always the right answer.

Words you need (10 key words in this lesson)

The maths words this lesson uses, in plain English. Open this before you start if English is not your first language.

square
Multiply a number by itself. Also, a shape with four equal sides and four right angles.5 squared is 25.
regression
A method for finding the best straight line through data.The regression line predicts y from x.
sum
The answer when you add.The sum of 3 and 5 is 8.
linear
Making a straight line. The letter has power 1.y = 2x plus 1 is linear.
predict
Say what you think will happen using the data.Predict the score for 5 hours of study.
negative
Less than zero. A negative number has a minus sign.Minus 4 is a negative number.
straight line
A line that does not bend.A ruler draws a straight line.
positive
Greater than zero.7 is a positive number.
exponential
Growing or shrinking by multiplying by the same number again and again.Money in a bank grows exponentially.
proportion
A part compared with the whole, or two amounts that grow together.3 of 10 students is a proportion of 0.3.

Preview You are reading the start of this lesson. The rest opens with a plan. See plans Already paid? Sign in

Warm-up

Four quick ones from earlier work. Try each on paper before you open the answer; a slip here shows you what to watch for later in the lesson.

  1. Work out (−1.5)², and then −1.5². Are they the same?
    Answer

    (−1.5)² = 2.25, but −1.5² = −2.25. They are not the same: a square of a negative is positive only when the bracket is squared. This is the slip behind a negative SSres contribution.

  2. An observed value is 17 and the model predicted 20. What is the residual?
    Answer

    Observed minus predicted: 17 − 20 = −3. The negative sign says the point is below the curve. Predicted minus observed would give +3, and the square would be the same.

  3. Work out 5 × 0.8³.
    Answer

    0.8³ = 0.512, and 5 × 0.512 = 2.56. Do the power first, then multiply. The calculator’s exponential model is built from exactly this: a number times a repeated multiplier.

  4. As t becomes very large, what value does 24 + 60 × 0.9t get closer and closer to?
    Answer

    0.9t shrinks towards 0, so the whole expression approaches 24 and never goes below it. 24 is a horizontal asymptote. This is how a model of cooling can “settle” at room temperature.

Words used in this lesson
model
an equation that describes how the data behaves. For example: y = 20 + 55 × 0.92t is a model of a cooling drink.
observed value
the number actually measured. For example: the thermometer read 51.4.
predicted value
the number the model gives for the same input. For example: the model gave 54.0 at 8 minutes.
residual
observed minus predicted: the gap between a point and the curve. For example: 17 − 20 = −3.
parameter
a number inside the model that is chosen to fit the data. For example: a straight line has two parameters, the gradient and the intercept.
asymptote
a value the curve gets close to but never reaches. For example: a cooling drink approaches room temperature.
exponential decay
a quantity that falls by the same factor in each equal step. For example: a drink losing 8% of its excess heat each minute.
extrapolation
estimating beyond the range of the data. For example: predicting at 60 minutes from data up to 20.
justify
give a reason for a choice using the situation. For example: “justify the model” needs the physics, not just the smallest number.
least squares
the method that makes the sum of squared residuals as small as possible. For example: the calculator uses it for every regression.
coefficient of determination
R2: the proportion of the variation in the data that a model explains. For example: R2 = 0.85 means the model explains 85% of the variation.

Predict first. Before you click anything: the coffee data runs to about 20 minutes. Sketch what you think a sensible model does over the next hour. Then predict: when you click through linear, quadratic and cubic, will the curves look more or less sensible after the last data point?

Then check

Now click through all four models and look at the right-hand edge of each curve, beyond the data. Compare each with your sketch. Which model’s curve at that edge agrees with what a cooling drink actually does, and which ones do not?

A cup of coffee is left on a desk in an air-conditioned Bangkok classroom and its temperature is recorded every two minutes. Try a straight line through it.

2030405060708090

sum of squared residuals 211.50  ·  R2 0.9390

2 fitted parameters

What a residual is

A residual is the vertical gap between a data point and the curve: observed minus predicted. Some are positive and some negative.

Squaring them stops the positives and negatives cancelling, and punishes one large miss more than several small ones. Adding up the squares gives SSres, and least squares regression is simply the curve of that family which makes SSres as small as possible.

Worked example: computing a residual

A model predicts 54.0 degrees at 8 minutes. The thermometer read 51.4.

residual= observed − predicted always this way round = 51.4 − 54.0 = −2.6 negative: the point sits below the curve contribution= (−2.6)² = 6.76 what this one point adds to SSres

The rest of this lesson is in the full course

Still to come in this lesson:

In the full lesson every figure moves as you drag it, and every answer you type is checked, with a note on what each wrong answer means.

IB Diploma plan: AI HL$99Every Diploma lesson in both courses and both levels, so a change of course never locks you out, and every lesson from Year 7 for the refreshers. $99 for 12 months or $149 for 2 years.

One plan opens every Diploma lesson, AA and AI, SL and HL, for the whole family.

One payment. Nothing renews. Full refund within 30 days. Prices are in US$; Gumroad shows your local currency at checkout. Pay by card on Gumroad, then come back here and type the email you paid with: we email you a sign-in link. For a refund, reply to your Gumroad receipt or email hello@ksmaths.com.

Try a free sample lesson in every unit, and the whole Skill Tree. See this unit.

Already have a revision pack or the Years 7 to 11 plan? Move up and the unused part of what you paid comes off.

Teaching students who need extra support? Student codes for 5, 10 or 30 students.

AI HL Mock Exam Pack, $25BuyPlan $99