Menu
Sign up Sign in

AI HL · AHL 8

Statistics 2

AHL 8.1

Non-linear regression with the calculator

AHL 8.1

Non-linear regression with the calculator

Target: I can decide from a scatter plot and the context whether a quadratic, cubic, exponential, power or sine model is sensible. (+4 more)

By the end of this section

Key points

Choose the model, then let the calculator fit it

  • Draw a scatter plot first. The calculator fits the form you choose and does not tell you whether it is the right form.
  • One turn (a single peak or dip): quadratic \(y=ax^2+bx+c\). Two turns, or an S shape: cubic \(y=ax^3+bx^2+cx+d\).
  • Repeated growth or decay by the same factor: exponential \(y=ae^{bx}\). Growth that bends up and passes through the origin: power \(y=ax^b\). A pattern that repeats: sine.
  • The context must agree with the model. A model that goes negative for a quantity that cannot be negative is a warning.

Reading the output

  • Write the model in the variables of the question, with each coefficient to 3 significant figures, for example \(y = -8.30x^2 + 85.2x - 29.6\).
  • Keep the unrounded model stored on the calculator. Predict from the stored model: rounded coefficients can change the third figure.
  • In \(y=ae^{bx}\), a is the value at x = 0. If b > 0 the model grows, if b < 0 it decays. Some calculators give \(y=a\cdot c^x\): then b = ln c.
  • In \(y=ax^b\), x and y must be positive. Doubling x multiplies y by \(2^b\).

Sine models

  • Set the calculator to radians. In \(y=a\sin(bx+c)+d\): a is the amplitude, d is the midline, the maximum is \(d+a\) and the minimum is \(d-a\).
  • The period is \(\dfrac{2\pi}{b}\): the length of one full cycle.
  • Two calculators can give different values of c for the same curve (they differ by a multiple of 2π). Draw the curve over the points to check.
  • Give the calculator at least one full cycle of data. If the curve does not follow the points, check the mode and try a starting guess for the period.

How good is the fit?

  • A residual is the data value minus the model value, \(y-\hat y\). Positive: the point is above the curve.
  • \(SS_{res}=\sum(y-\hat y)^2\). Squaring stops positive and negative residuals cancelling. A smaller \(SS_{res}\) means the curve is closer to the points.

On the calculator

Quadratic and cubic regression

  • Put the x values in one list and the y values in another, in the same order.
  • Choose quadratic regression or cubic regression.
  • Read a, b, c (and d for a cubic) from the results.
  • Store the regression function so you can graph it and evaluate it.

Screenshot and video to come

Exponential and power regression

  • Choose exponential regression for \(y=ae^{bx}\) or power regression for \(y=ax^b\).
  • If the calculator gives \(y=a\cdot c^x\), find b as ln c.
  • A power model needs every x and every y to be positive.
  • Different calculators can differ slightly in the last figure: some fit a straight line to ln y.

Screenshot and video to come

Sine regression

  • Set the calculator to radians.
  • Choose sine (sinusoidal) regression and read a, b, c and d.
  • If it asks for a number of iterations or a starting guess, give an estimate of the period.
  • Draw the curve over the points. If it misses them, check the mode and the guess.

Screenshot and video to come

Checking a model on a graph

  • Draw a scatter plot of the data.
  • Draw the stored regression function on the same axes.
  • The curve should follow the points without a pattern of misses.
  • Evaluate the stored function to predict a value or find a residual.

Screenshot and video to come

Explore: which model fits?

The dots are data. Choose a model: the orange curve is the fitted model and the teal segments are the residuals. Compare SSres and R² for all five, then look at what each model does beyond the data.

ModelSSresR²

For the exponential and the power model, R² is the R² of the straight line through (x, ln y) or (ln x, ln y), as the calculator gives it. SSres is always measured on y.

Choose a model.

  1. Choose "Crop yield" and go through the five models. Which has the highest R²? Which would you trust, and why?
  2. The cubic never has a lower R² than the quadratic. Does that mean the cubic is the better model? What would you want to know about the context?
  3. Tick "Show beyond the data" for the quadratic and the cubic. What do they do on the right? Could the real quantity do that?
  4. For the caffeine data, compare the exponential model with the quadratic. Which one makes sense a long time after the drink?

Explore: y = a sin(bx + c) + d

Move the four sliders to make the orange curve follow the dots. Each teal segment is a residual. Bring SSres down, then compare it with the calculator's model.

Amplitude
Period
Midline
Smallest SSres you reached
Calculator's model

Move a slider.

  1. Which slider would you set first by looking at the dots? Which can you read straight from the highest and lowest dot?
  2. Change the period a little and watch the residuals at the right-hand end grow faster than those at the left. Why?
  3. Make the curve pass exactly through two dots. Is SSres the smallest it can be? Why or why not?
  4. The same curve can be written with c + 2π instead of c. Move c by 2π (about 6.28) in your head: what changes on the graph?

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
A quadratic from sales data

A school sells tickets to a concert at a price of £x. The table shows the profit £y from each of seven ticket prices. The scatter plot rises, then falls, so a quadratic model is chosen. Find the model \(y=ax^2+bx+c\), with a, b and c to 3 significant figures.

x (£)2345678y (£)108151178189184160121
Working
  1. Enter the data

    x in one list, y in another, in the same order

    The two lists must be the same length. Check the last row before you run the regression.

  2. Run the regression

    From the calculator: Quadratic regression: a = −8.30, b = 85.2, c = −29.6

    The calculator returns the coefficients of the form you chose.

  3. Write the model

    \(y = -8.30x^2 + 85.2x - 29.6\)

    Give 3 significant figures, with the sign of each coefficient.

  4. 1234567891020406080100120140160180200220x (£)y (£)
    Check the curve

    Draw the curve over the scatter plot

    A good fit passes close to every point. Here it rises to a peak near x = 5.

Video walkthrough coming
A cubic that turns twice

The depth of water, y cm, in a reservoir is recorded at the start of each month for six months (x = 0 to 6). The data flatten and then rise steeply. Find the cubic model \(y=ax^3+bx^2+cx+d\) to 3 significant figures, then use it to estimate the depth at x = 4.5.

x0123456y (cm)41444343506799
Working
  1. Run the regression

    From the calculator: Cubic regression: a = 0.778, b = −4.04, c = 5.88, d = 41.1

    Choose cubic regression: the shape has two bends, so a quadratic would not do.

  2. Write the model

    \(y = 0.778x^3 - 4.04x^2 + 5.88x + 41.1\)

    Quote 3 significant figures.

  3. Predict

    f(4.5) = 56.7

    Evaluate with the stored regression function, not the rounded coefficients. 4.5 is inside the data range, so this is a reasonable estimate.

  4. 123456730405060708090100110xy (cm)
    Check the curve

    Draw the curve over the points

    The curve is nearly flat from x = 1 to 3, then climbs.

Video walkthrough coming
Exponential decay

After a cup of coffee, the mass of caffeine in a student's blood is measured. The table gives the mass y mg after x hours. The values fall by about the same fraction each hour. Find the model \(y=ae^{bx}\), with a and b to 3 significant figures.

x (h)0123468y (mg)182152129109926446
Working
  1. Choose the form

    Exponential regression, \(y=ae^{bx}\)

    Each hour the mass is multiplied by about the same factor, so the model is exponential.

  2. Run the regression

    From the calculator: Exponential regression, \(y=ae^{bx}\): a = 182, b = −0.172

    If your calculator gives \(y=a\cdot c^x\), then b = ln c.

  3. Write the model

    \(y = 182e^{-0.172x}\)

    b is negative, so this is decay. a = 182 mg is the model's value at x = 0.

  4. 12345678920406080100120140160180200x (h)y (mg)
    Check the curve

    Draw the curve over the points

    The curve drops quickly, then flattens towards 0.

Video walkthrough coming
A power model

The mass, m grams, of a fish of length L cm is recorded for six fish. A power model \(m=aL^b\) is suggested, because mass grows faster than length. Find a and b to 3 significant figures.

L (cm)121620242832m (g)18.544.584.4144.7227.5338.7
Working
  1. Choose the form

    Power regression, \(m=aL^b\)

    A power model needs L and m both positive. They are.

  2. Run the regression

    From the calculator: Power regression, \(y=ax^b\): a = 0.0121, b = 2.95

    a is small because \(L^{2.95}\) is large for lengths of 12 to 32 cm.

  3. Write the model

    \(m = 0.0121L^{2.95}\)

    b is close to 3: mass behaves like a volume.

  4. 481216202428323650100150200250300350400L (cm)m (g)
    Check the curve

    Draw the curve over the points

    The curve passes through the origin and bends upwards.

Video walkthrough coming
A sine model for the tide

The height, y metres, of the tide in a harbour is measured every 2 hours for 14 hours. The values rise and fall. Find the model \(y=a\sin(bx+c)+d\), with the calculator in radians and a, b positive. Give a, b, c and d to 3 significant figures.

x (h)02468101214y (m)4.96.25.23.82.72.84.95.5
Working
  1. Radians

    Set the calculator to radians

    In degree mode the fit is wrong. Check the mode first.

  2. Run the regression

    From the calculator: Sine regression, \(y=a\sin(bx+c)+d\), radians: a = 1.68, b = 0.506, c = 0.426, d = 4.25

    The calculator iterates to the best fit. It needs the data to cover about one full cycle.

  3. Write the model

    \(y = 1.68\sin(0.506x + 0.426) + 4.25\)

    c can differ from another calculator's answer by a multiple of 2π: both give the same curve.

  4. Read the model

    period = 2π ÷ 0.506 = 12.4 h; midline y = 4.25 m; amplitude 1.68 m

    The period is the time for one full cycle.

  5. 1234567891011121314151234567x (h)y (m)
    Check the curve

    Draw the curve over the points

    The curve passes close to all eight points.

Video walkthrough coming
Residuals for the sine model

Use the tide model from the last example. A residual is the data value minus the model value, \(y-\hat y\). Find the residual at each of the eight times, then find \(SS_{res}\), the sum of the squares of the residuals, to 3 significant figures.

Working
  1. Model values

    From the calculator: model values at x = 0, 2, …, 14: 4.94, 5.92, 5.32, 3.72, 2.61, 3.04, 4.61, 5.83

    Put the stored model into a function and evaluate it at each x. Do not use the rounded coefficients.

  2. x (h)02468101214y (m)4.96.25.23.82.72.84.95.5model4.945.925.323.722.613.044.615.83y − model−0.040.28−0.120.080.09−0.240.29−0.33
    Residuals

    Residuals \(y-\hat y\): −0.04, 0.28, −0.12, 0.08, 0.09, −0.24, 0.29, −0.33

    Positive: the point is above the curve. Negative: below.

  3. Square and add

    \(SS_{res}=\sum (y-\hat y)^2\) = 0.368

    Squaring stops positive and negative residuals cancelling. A smaller SS_res means a closer fit.

Video walkthrough coming