top of page

2.5 Coding

A-level Maths Statistics and Mechanics Year 1 (AS) · Edexcel 9MA0 · Chapter 2: Measures of Location and Spread

A free A-level Maths Stats and Mechanics Year 1 lesson for Pearson Edexcel A level Mathematics (9MA0) from OBA School: using a linear code to simplify data, then decoding the mean and standard deviation. Watch the video, read the explanation and worked examples, then try the revision questions. You can work through the full lesson, with more videos, an interactive lesson, a practice quiz and printable worksheets, in our free online course.

What you will learn

  • Explain how adding, subtracting, multiplying and dividing every value affects the mean and the standard deviation
  • Use a code of the form y = (x − a)/b to find the mean and standard deviation of x
  • Decode summary statistics, including from grouped data
  • Convert a mean and standard deviation between units, such as °C and °F

Key words

  • Coding: Replacing each value by a simpler one using a linear rule, to make calculations easier.
  • Linear code: A rule of the form y = (x − a)/b, or y = mx + c, applied to every value.
  • Decode: Turn a statistic for the coded data y back into one for the original data x.
  • Translation: Adding or subtracting the same number to every value: the data shift but keep their spread.
  • Scaling: Multiplying or dividing every value by the same number: the data stretch or shrink.

What coding does

If you subtract 1000 from every value, the whole data set slides along: the mean drops by 1000 but the gaps between values (the spread) stay the same. If you then divide every value by 10, all the gaps shrink to a tenth, so the mean and the standard deviation are both divided by 10.

  • add a (or subtract a); Mean add a (subtract a); Standard deviation no change; Variance no change
  • multiply by b; Mean multiply by b; Standard deviation multiply by b; Variance multiply by b²
  • divide by b; Mean divide by b; Standard deviation divide by b; Variance divide by b²

Worked example: a simple translation

Masses of four bags (g): 1003, 1005, 1008, 1004. Use y = x − 1000.
Coded values 3, 5, 8, 4: y̅ = 5, so x̅ = 5 + 1000

Answer: x̅ = 1005 g, and σₓ = σ_y

Decoding the mean and standard deviation

Formula: If y = (x − a)/b then y̅ = (x̅ − a)/b and σ_y = (σₓ)/b. So x̅ = by̅ + a and σₓ = bσ_y. The value of a never affects the spread.

Worked example: decoding

Data are coded with y = (x − 50)/10, giving y̅ = 2.3 and σ_y = 1.4.
x̅ = 10 × 2.3 + 50 = 73
σₓ = 10 × 1.4 = 14 (do not add 50)

Answer: x̅ = 73, σₓ = 14

A safe method is to substitute the statistic into the code and solve: 2.3 = (x̅ − 50)/10 gives x̅ = 73. For the standard deviation, only the division by b matters.

Coding with summary statistics

Exam questions often give Σ y and Σ y² for the coded data. Find y̅ and σ_y first, exactly as in section 2.4, then decode.

Worked example: from coded totals

For 12 values, y = (x − 20)/5 gives Σ y = 18 and Σ y² = 75.
y̅ = 18/12 = 1.5; σ_y² = 75/12 − 1.5² = 6.25 − 2.25 = 4, so σ_y = 2
x̅ = 5 × 1.5 + 20 = 27.5; σₓ = 5 × 2 = 10

Answer: x̅ = 27.5, σₓ = 10

Note: Variance scales by b²: here σₓ² = 25 × 4 = 100.

Coding grouped data

Grouped data with equal class widths have midpoints that go up in equal steps. A code that turns the midpoints into ..., −2, −1, 0, 1, 2, ... makes the arithmetic very easy.

  • 100 ≤ m < 110; Midpoint x 105; y = (x − 125)/10 −2; f 6; fy −12; fy² 24
  • 110 ≤ m < 120; Midpoint x 115; y = (x − 125)/10 −1; f 14; fy −14; fy² 14
  • 120 ≤ m < 130; Midpoint x 125; y = (x − 125)/10 0; f 20; fy 0; fy² 0
  • 130 ≤ m < 140; Midpoint x 135; y = (x − 125)/10 1; f 7; fy 7; fy² 7
  • 140 ≤ m < 150; Midpoint x 145; y = (x − 125)/10 2; f 3; fy 6; fy² 12
  • Total; Midpoint x ; y = (x − 125)/10 ; f 50; fy −13; fy² 57

Worked example: masses of 50 eggs

y̅ = (−13)/50 = −0.26; σ_y² = 57/50 − (−0.26)² = 1.0724, σ_y = 1.0355...
x̅ = 10 × (−0.26) + 125 = 122.4; σₓ = 10 × 1.0355... = 10.355...

Answer: mean ≈ 122.4 g, standard deviation ≈ 10.4 g

Changing units

Changing units is a linear code too. Temperatures convert with F = 1.8C + 32. The mean converts with the full formula; the standard deviation is only multiplied by 1.8.

Worked example: Celsius to Fahrenheit

Daily maximum temperatures at a station have mean 14.5 °C and standard deviation 3.2 °C.
Mean: 1.8 × 14.5 + 32 = 58.1 °F. Standard deviation: 1.8 × 3.2 = 5.76 °F

Answer: mean 58.1 °F, standard deviation 5.76 °F

Key fact: Coding changes the size of the numbers, not the shape of the data. Measures of location change with both parts of the code; measures of spread (range, IQR, standard deviation) only with the multiplying part.

Common mistakes

  • Adding a when decoding a standard deviation: if y = (x − a)/b then σₓ = bσ_y, not bσ_y + a.
  • Multiplying the variance by b instead of b².
  • Decoding in the wrong order: from y = (x − a)/b, x̅ = by̅ + a, not (y̅ + a)/b.
  • Coding the class boundaries instead of the midpoints for grouped data.
  • Thinking a negative coded mean must be wrong: it just means that x̅ is less than a.

Revision questions

Try these, then check your answers below each one.

Question 1. Every value in a data set is increased by 5. What happens to the standard deviation? (Choose from: It is unchanged; It increases by 5; It is multiplied by 5; It increases by 25.)

Answer: It is unchanged

Working: Adding 5 moves every value along by the same amount; the spread is unchanged.

Question 2. A data set has mean 4. Each value is transformed by y = 3x − 7. Find the mean of y.

Answer: 5

Working: y̅ = 3 × 4 − 7 = 5.

Question 3. Data are coded with y = (x − 20)/5 and the variance of y is 4. Amira says the variance of x is 20. Is she correct?

Answer: No

Working: No. σₓ = 5σ_y = 5 × 2 = 10, so the variance of x is 100 = 25 × 4.

Related lessons

Continue in the full course

This lesson is section 2.5 of our free A-level Maths Statistics and Mechanics Year 1 (AS) course. In the full course you get every video for this section, an animated interactive lesson, a self-marking practice quiz, a printable worksheet with a mark scheme, an end-of-chapter test and your progress saved. Go to the full A-level Maths Statistics and Mechanics Year 1 (AS) course.

 

 

 

 

 

 

 

bottom of page