Coded Data
Coding means replacing each value by a simpler one, usually for some convenient number , before doing the arithmetic. The syllabus asks you to find the mean and standard deviation "from coded totals and ", and to use them in problems with up to two data sets. This appears on almost every Paper 5: a short question gives coded totals and asks for and the standard deviation, or asks you to recover and , or to combine two sets that were coded differently.
Why coding works
Suppose the masses of six bags of flour, in grams, are
Squaring numbers like is slow and error-prone. Subtract from each value instead:
These coded values are exactly the original values slid units to the left on the number line. Sliding every value by the same amount moves the mean by that amount but does not change how far apart the values are. So:
- the mean of the coded values is less than the mean of the original values;
- the standard deviation of the coded values is the same as the standard deviation of the original values.
The coded values have and . Their mean is , so the mean mass is . Their variance is , so the standard deviation of the masses is , with no large numbers anywhere.
The coded formulas
For values coded as :
Subtracting changes the mean by and leaves the variance and standard deviation unchanged.
The variance formula is just the usual "mean of the squares minus the square of the mean", applied to the coded values. The appears only when you convert the mean back.
Adding to the standard deviation. The most common error in coding questions is writing . Shifting values does not change their spread. Only the mean gets added back.
Subtracting in the variance. The variance is . The second term is the square of the coded mean, not and not .
Converting coded totals to and
Some questions, especially ones that combine data sets, need the uncoded totals. Expand the brackets:
In the second line the "" comes from the cross term: , and summing copies of gives . There is no need to memorise these; write out and sum each term.
An equivalent route, often quicker, is to find and the standard deviation from the coded totals first, then use and from the standard deviation note.
. Subtracting from every one of values subtracts in total. Likewise .
Combining two coded data sets
Totals can only be added when they are on the same code. Two cases:
- Same . Add the s, add the s and add the s, then use the coded formulas.
- Different s. Convert one set to the other's code, or convert both to and , then add.
- Check whether both sets use the same coding constant.
- If not, convert: either find and for each set, or re-code one set. To change to , write , so and .
- Add the totals for the two sets.
- Find the combined mean and standard deviation from the combined totals.
Scaling as well as shifting
Sometimes every value is multiplied by a constant, for instance converting units or giving everyone a percentage pay rise. Multiplying every value by multiplies the distances between values by too.
If every value is transformed to (with ):
Adding affects the mean only; multiplying by affects both.
The same idea run backwards handles codes such as : then , so and . Paper 5 coding questions mostly use the shift alone, but scaled versions do appear in context (temperature conversions, pay rises, unit changes).
Choosing a coding constant
If a question asks you to choose the code yourself, pick close to the middle of the data (or a round number near the mean). The coded values are then small and both positive and negative, so the squares stay small. Any value of gives the same final answers; a good choice just reduces the arithmetic.
Worked examples
For values of , and . Find the mean and standard deviation of .
Solution
Note that the being squared is the coded mean, not .
For values of , and .
(a) Find and .
(b) Find the variance of in two ways, and confirm that they agree.
Solution
(a) .
Expand: , so
(b) From coded totals: (3 s.f.).
From uncoded totals: , and (3 s.f.).
Both give , as they must: coding by subtraction does not change the variance.
The marks of students in an examination have mean and standard deviation . Find and .
Solution
The coded values have mean and the same standard deviation, .
For the coded values, , so
For values of , and . The mean of is . Find and the standard deviation of .
Solution
The lengths, cm, of fish of species A satisfy and . The lengths of fish of species B satisfy and . Find the mean and standard deviation of the lengths of all fish.
Solution
The codes differ, so convert species B to the code . Write .
Combine with species A on the same code: , , .
Check by the other route. Species A: and . Species B: and . Together and , so and the variance is , as before. Re-coding one set involved smaller numbers, which is why it is usually the faster method.
The daily midday temperatures in a town during one month had mean and standard deviation . The temperature in degrees Fahrenheit is . Find the mean and standard deviation of the temperatures in .
Solution
Mean: .
Standard deviation: . Adding shifts every temperature equally and so does not change the spread.
- State the uncoded mean clearly: examiners see many answers that stop at the coded mean ( instead of ).
- Show the coded formula with numbers in it, for example . This earns the method mark even if the arithmetic goes wrong.
- When asked for , write out before substituting; the term is where marks are usually lost.
- When combining sets, say which code you are converting to. Combining totals with different codes is a zero-mark error.
- Give answers to 3 significant figures, but keep exact values (, ) in the working.
- Coding makes arithmetic easier and does not change the answers.
- : add back to the coded mean.
- Variance and standard deviation are unchanged by subtracting : use .
- and .
- Totals on different codes cannot be added until one is converted.
- For : mean then ; standard deviation only; variance .
Practice questions
- For values of , and . Find the mean and standard deviation of .
- The masses, kg, of six parcels are . Using the coding , find the mean and standard deviation of the masses.
- The ages, years, of people have mean and standard deviation . Find and .
- For values, and . Find the mean and standard deviation of .
- Ten values of have mean and standard deviation . Find and .
- The mean of values of is , and . Find the standard deviation of .
- Each of the employees in a small firm earns a weekly wage. The wages have mean $1200 and standard deviation $150. Every wage is increased by and then by a further $50. Find the new mean and standard deviation.
- For values of , , and . Find , and the mean and standard deviation of .
- Set A has values with and . Set B has values with and . Find the mean and standard deviation of all values.
- For values of , and . Also . Find , the mean of and the standard deviation of .
Answers
-
. Standard deviation (3 s.f.).
-
The coded values are : , . , and the standard deviation of is . Since : mean mass ; standard deviation (3 s.f.).
-
Coded mean , so . .
-
Coded mean , so . Standard deviation .
-
Coded mean , so . .
-
Coded mean . Variance , so the standard deviation is .
-
New wage . New mean , i.e. $1298. New standard deviation , i.e. $156 (adding $50 does not change the spread).
-
, so and . Mean . Standard deviation (3 s.f.).
-
Convert set B to the code , using : ; . Combined: , , . Mean . Standard deviation (3 s.f.).
-
, so and . Mean . Standard deviation .