Updated · By Pete Bromfield, IB examiner

IA modelling, step by step · Piecewise

Piecewise model, step by step: when the rule changes part-way

AA SLAA HLAI SLAI HL

Some data follow one rule and then another: water heats steadily and then boils, a tariff changes at a threshold, a runner speeds up for the finish. Split the domain where the context says the rule changes, fit each piece, and join them.

Example data, invented for this guide. The context is realistic, but the numbers were made up to show the method. Use your own measured or sourced data in your IA.

When to use it

The shape of the data

  • A sudden change of gradient (a kink) or a change of shape part-way through.
  • One model fits the first part well but clearly fails on the rest.

The context

  • A physical change of state (heating then boiling, melting).
  • Rules with thresholds: tax bands, tariffs, speed limits.
  • A process with phases: acceleration then steady speed.

Course fit: AI HL (piecewise models); domain notation is used everywhere. Justifying the split from the context is what makes it strong at any level.

The example data

A pan of water is heated on a hob at a constant setting; a thermometer is read every minute until it has been boiling for a few minutes.

Example data: water temperature and time
ix: Time (min)y: Water temperature (°C)
1018.4
2127.6
3237.3
4346.5
5456.2
6565.3
7675
8784.1
9893.8
10998.9
111099.2
121199
131299.1
141398.9
Scatter graph of water temperature against time for the example data
Step 1 of any modelling IA: plot the data and describe the shape before fitting anything.

The method: split, fit each piece, join

The water heats at a steady rate until it boils, then stays at boiling point. Split after x = 8 (the last reading before the temperature stops rising), fit a line to the first piece and a constant to the second, then find where they meet.

Step 1 · Split the domain

Split the data where the behaviour changes (from the graph and the context): piece 1 for x ≤ 8 (9 points), piece 2 for x > 8 (5 points).

Step 2 · Tabulate the sums for piece 1

Sums for the least-squares line
ixyx²xyy²
1018.400338.56
2127.6127.6761.76
3237.3474.61391.29
4346.59139.52162.25
5456.216224.83158.44
6565.325326.54264.09
7675364505625
8784.149588.77072.81
9893.864750.48798.44
Σ36504.22042582.133572.64

n = 9 points.

Step 3 · Gradient

m = (nΣXY − ΣX ΣY) / (nΣX² − (ΣX)²)

m = (9 × 2582.1 − 36 × 504.2) / (9 × 204 − 36²) = 5087.7 / 540 = 9.422

Here X = x and Y = y.

Step 4 · Intercept

X̄ = ΣX/n = 4.0000,   Ȳ = ΣY/n = 56.022

c = Ȳ − m X̄ = 56.022 − 9.422 × 4.0000 = 18.34

The line of best fit always passes through the mean point (X̄, Ȳ).

Step 5 · Correlation

r = (nΣXY − ΣX ΣY) / √[(nΣX² − (ΣX)²)(nΣY² − (ΣY)²)] = 5087.7 / √(540 × 47936.12) = 1.000

r² = 1.000: a very strong positive linear correlation between x and y.

Step 6 · Piece 2: a constant

The context says the second piece should be level, so the least-squares constant is the mean of its y values: y = 99.02.

Step 7 · Where the pieces meet

Set the two pieces equal: 9.422x + 18.34 = 99.02, so x = 8.564, y = 99.02. Using this as the boundary makes the model continuous (no jump), which usually matches the context better than the split you started with.

Model: y = 9.422x + 18.34 for x ≤ 8; y = 99.02 for x > 8

Step 8 · Residuals and goodness of fit

For each point, the residual is the observed value minus the model's value: e = y − ŷ.

Residuals
ixy (data)ŷ (model)y − ŷ(y − ŷ)²
1018.418.340.06440.00415
2127.627.76−0.1570.0247
3237.337.180.1210.0147
4346.546.60−0.1010.0101
5456.256.020.1780.0316
6565.365.44−0.1440.0207
767574.870.1340.0181
8784.184.29−0.1870.0351
9893.893.710.09110.00830
10998.999.02−0.1200.0144
111099.299.020.1800.0324
12119999.02−0.02000.000400
131299.199.020.08000.00640
141398.999.02−0.1200.0144
Σ0.2354
  • Sum of squared residuals: SSR = Σ(y − ŷ)² = 0.2354
  • Total sum of squares about the mean ȳ = 71.38: SST = Σ(y − ȳ)² = 11270
  • Coefficient of determination: R² = 1 − SSR/SST = 1 − 0.2354/11270 = 1.000
  • Root-mean-square error: RMSE = √(SSR/n) = 0.130 — a typical size of a residual, in the units of y.
Graph of the data with the fitted piecewise (two lines) (piecewise model)
Split, fit each piece, join: the fitted curve over the example data.
Residual plot for the piecewise (two lines) fitted to the example data
Residuals against x. Look for a pattern: random scatter about 0 means the model has captured the shape; a curve or a trend means it has not.

What the model tells you

  • Gradient of piece 1 ≈ 9.42 °C per minute: the heating rate at this hob setting.
  • Piece 2 ≈ 99.0 °C: the boiling point. It is slightly below 100 °C, which could be thermometer calibration or air pressure — good reflection.
  • The pieces meet at about 8.6 minutes: the model's estimate of when boiling starts.

The same on a GDC

Enter and plot the data first, then fit. The key sequences are for current operating systems; menus differ slightly between versions.

TI-84 Plus CE

  1. Data: [stat] → 1: Edit… Type the x values in L1 and the y values in L2. To plot: [2nd] [y=] (STAT PLOT) → Plot1: On, Type: scatter, Xlist: L1, Ylist: L2, then [zoom] → 9: ZoomStat.
  2. Put the first piece (x ≤ 8) in L1, L2 and the second in L3, L4.
  3. LinReg(ax+b) L1, L2 for piece 1; for a constant piece, 1-Var Stats L4 gives the mean.
  4. Graph each piece with a domain: Y1 = (9.422X + 18.34)/(X ≤ 8.564) draws only where the condition is true.

TI-Nspire CX

  1. Data: Add a Lists & Spreadsheet page; name column A xs and column B ys and type the data. Add a Data & Statistics page (or a Graphs page with menu → Graph Entry/Edit → Scatter Plot) and choose xs and ys.
  2. Fit each piece's columns with Linear Regression; define the model with a template: menu → Functions… or type a piecewise function with the { template.

Casio fx-CG50

  1. Data: [MENU] → Statistics. Type the x values in List 1 and the y values in List 2. To plot: [F1] (GRAPH) → [F6] (SET): Graph Type Scatter, XList List1, YList List2; [EXIT], then [F1] (GRAPH1).
  2. Fit each piece's lists separately with REG; in Graph mode add a domain after a comma: Y1 = 9.422X + 18.34, [0, 8.564].

In Desmos

Free at desmos.com/calculator. In a regression, ~ means “fit this model”; subscripts are typed with an underscore (x_1 shows as x₁).

  1. Two tables (one per piece), each with its own regression: y_1 ~ m x_1 + c and y_2 ~ k.
  2. Draw with domains: y = 9.422x + 18.34 {0 ≤ x ≤ 8.564} and y = 99.02 {x ≥ 8.564}.

More on technology in the IA: using Desmos, GeoGebra and Excel.

How to write it up in your IA

  • Explain from the context why the rule changes and where.
  • Fit each piece and show its working; justify the form of each piece.
  • Find where the pieces meet and discuss whether the model should be continuous.
  • Write the model with its domains in correct notation.
  • Discuss how sensitive the result is to where you split (try moving the split by one point).

These are the points to cover, not sentences to copy. Write every explanation in your own words, about your own data.

Common mistakes

  • Splitting where it makes the numbers look best rather than where the context says.
  • Pieces that do not meet when the context has no jump.
  • Missing or overlapping domains in the written model.

Is this good enough for Criterion E?

  • The split is justified by the context and visible in the data.
  • Each piece is fitted and justified; the join is found algebraically.
  • The model is written with correct domain notation.
  • Sensitivity to the split point is tested.
  • HL: the split point is estimated by minimising the total SSR over possible splits.

SL or HL? Criterion E asks for mathematics that fits your course. At SL, fitting with technology is fine when you explain the method and justify every choice. At HL, show more of the mathematics yourself — the last item in the list is an example. See Criterion E and Criterion D.

Frequently asked questions

Where should I split the data for a piecewise model?

Where the context says the rule changes (boiling, a tariff threshold), confirmed by the graph. Then check how much the parameters change if you move the split by one point.

Free: the IA checklist an examiner uses

Every check for Criteria A–E in a 4-page PDF, the mistakes that cost the most marks and a self-assessment grid. We'll email it with a short IA tip every few days, timed to your deadline if you give it. Free — no account, no payment.