Coding

A LevelEdexcel

Coding

(Note: This topic is Edexcel only.)

Coding is where something is done to every data value to make them easier to work with. Indeed, we can add, subtract, multiply and divide our data values, and as long as we do the same thing to each data value, the mean and standard deviation of the new set can tell us the mean and standard deviation of the original values.

There are three skills you need to know for coding.

A LevelEdexcel

Skill 1: Coding With Raw Data

To code a data point xx, we turn it into y=xaby=dfrac{x-a}{b} where aa and bb are of our choosing. Then we can work with our new data set yy to get information about our original xx.

Recall notation: mean of x=xˉtext{mean of }x=bar{x} and variance of x=var(x)text{variance of }x= text{var}(x)

To get information about xx from our coded set yy, we have the following formulas:

yˉ=xˉabbar{y}=dfrac{bar{x}-a}{b}

var(y)=var(x)b2text{var}(y)=dfrac{text{var}(x)}{b^{2}}

 

Example: Find the mean and variance of 14010,14030,14040,1406014010,14030,14040,14060

If we use the coding y=x1400010y=dfrac{x-14000}{10} we get y=1,3,4,6y=1,3,4,6, which is much easier to work with.

So, find the mean and variance of the yy values:

yˉ=1+3+4+64=3.5bar{y}=dfrac{1+3+4+6}{4}=3.5

var(y)=12+32+42+6243.52=1+9+16+36412.25=62412.25=15.512.25=3.25text{var}(y)=dfrac{1^{2}+3^{2}+4^{2}+6^{2}}{4}-3.5^{2}=dfrac{1+9+16+36}{4}-12.25=dfrac{62}{4}-12.25=15.5-12.25=3.25

 

Then, find the mean of the original values:

3.5=xˉ14000103.5=dfrac{bar{x}-14000}{10}

xˉ14000=35bar{x}-14000=35

xˉ=14035bar{x}=14035

 

and the variance of the original values:

3.25=var(x)1023.25=dfrac{text{var}(x)}{10^{2}}

var(x)=325text{var}(x)=325

 

So the mean and variance of 14010,14030,14040,1406014010,14030,14040,14060 is 1403514035 and 325325

A LevelEdexcel

Skill 2: Coding With Summarised Data

We can also apply coding to simplify summarised data to calculate the mean and variance.

Example: Suppose we have (x100)=18sum{(x-100)}=18 and (x100)2=45sum{(x-100)^{2}}=45 with ten data points.

The obvious coding to try is y=x100y=x-100

This gives y=18sum{y}=18 and y2=45sum{y^{2}}=45

 

So, the mean and variance of the yy values are:

yˉ=1810=1.8bar{y}=dfrac{18}{10}=1.8

var(y)=45101.82=4.53.24=1.26text{var}(y)=dfrac{45}{10}-1.8^2=4.5-3.24=1.26

 

This gives results of:

xˉ=yˉ+100=1.8+100=101.8bar{x}= bar{y} +100 = 1.8 + 100 = 101.8

and

var(x)=var(y)=1.26text{var}(x)= text{var} (y) = 1.26

(the variance of xx is the same as the variance of yy, since we only subtracted 100100 from each number).

A LevelEdexcel

Skill 3: Coding With Grouped Data

We can code grouped data by coding the midpoint and calculating all our sums with the coded midpoint, then converting back at the end.

Example: Estimate the mean and variance of the heights of the teachers at a school from the following table.

Step 1: Find the midpoints.

Step 2: Choose a suitable coding for the midpoints. Here we should go for y=x1.550.1y=dfrac{x-1.55}{0.1}. Now add the coded midpoints to the table.

Step 3: Proceed normally with the coded values, by adding an fyfy column and an fy2fy^{2} column to the table.

Step 4: Calculate the mean and variance estimates for yy.

yˉ=8750=1.74bar{y}=dfrac{87}{50}=1.74

var(y)=191501.742=3.823.0276=0.7924text{var}(y) =dfrac{191}{50}-1.74^{2}=3.82-3.0276=0.7924

 

Step 5: Use the coding formulas to turn these into values for xx.

1.74=xˉ1.550.11.74=dfrac{bar{x}-1.55}{0.1}

xˉ1.55=0.174bar{x}-1.55=0.174

xˉ=1.724bar{x}=1.724

 

0.7924=var(x)0.120.7924=dfrac{text{var}(x)}{0.1^{2}}

var(x)=0.007924text{var}(x)=0.007924

A LevelEdexcel

Coding Example Questions

Question 1: By applying a suitable coding, find the mean and standard deviation of the data set

1000,1010,1030,1040,10701000,1010,1030,1040,1070

[4 marks]

A Level Edexcel

A suitable coding would be y=x100010y=dfrac{x-1000}{10}, which gives y=0,1,3,4,7y=0,1,3,4,7 as the new data set.

 

yˉ=0+1+3+4+75=155=3bar{y}=dfrac{0+1+3+4+7}{5}=dfrac{15}{5}=3

 

var(y)=02+12+32+42+72532=1+9+16+4959=7559=159=6text{var}(y)=dfrac{0^{2}+1^{2}+3^{2}+4^{2}+7^{2}}{5}-3^{2}=dfrac{1+9+16+49}{5}-9=dfrac{75}{5}-9=15-9=6

 

3=xˉ1000103=dfrac{bar{x}-1000}{10}

xˉ1000=30bar{x}-1000=30

xˉ=1030bar{x}=1030

 

6=var(x)1026=dfrac{text{var}(x)}{10^{2}}

6=var(x)1006=dfrac{text{var}(x)}{100}

var(x)=600text{var}(x)=600

 

var(x)text{var}(x) is the variance, while the question asked for standard deviation.

σ=600=24.5sigma=sqrt{600}=24.5 (33 sf)

MME Premium Laptop

Save your answers with

MME Premium

Gold Standard Education

Question 2: From the summary statistics below, find the mean and variance of xx, provided that there are 88 data points.

x412=24sum{dfrac{x-4}{12}}=24

(x412)2=120sum{left(dfrac{x-4}{12}right)^{2}}=120

[2 marks]

A Level Edexcel

Clearly, we should use the encoding y=x412y=dfrac{x-4}{12} to get:

y=24sum{y}=24

y2=120sum{y^{2}}=120

 

So:

yˉ=248=3bar{y}=dfrac{24}{8}=3

var(y)=120832=159=6text{var}(y)=dfrac{120}{8}-3^{2}=15-9=6

 

Now convert back to xx:

3=xˉ4123=dfrac{bar{x}-4}{12}

xˉ4=36bar{x}-4=36

xˉ=40bar{x}=40

 

6=var(x)1226=dfrac{text{var}(x)}{12^{2}}

6=var(x)1446=dfrac{text{var}(x)}{144}

var(x)=864text{var}(x)=864

MME Premium Laptop

Save your answers with

MME Premium

Gold Standard Education

Question 3: Use a suitable encoding to estimate the mean and variance of the grouped data presented below.

 

 

[6 marks]

A Level Edexcel

Step 1: Find the midpoints of each class and add them to the table.

 

 

Step 2: Choose a suitable coding. In this case, there are a few possibilities, but the one shown here is y=x172525y=dfrac{x-1725}{25}.

 

Step 3: Proceed to create the rest of the table, with an fyfy and an fy2fy^{2} column.

 

 

Step 4: Calculate the mean and variance for yy.

yˉ=445100=4.45bar{y}=dfrac{445}{100}=4.45

var(y)=31851004.452=31.8519.8025=12.0475text{var}(y)=dfrac{3185}{100}-4.45^{2}=31.85-19.8025=12.0475

 

Step 5: Convert back into xx values.

4.45=xˉ1725254.45=dfrac{bar{x}-1725}{25}

xˉ1725=111.25bar{x}-1725=111.25

xˉ=1836.25bar{x}=1836.25

 

12.0475=var(x)25212.0475=dfrac{text{var}(x)}{25^{2}}

12.0475=var(x)62512.0475=dfrac{text{var}(x)}{625}

var(x)=7529.6875text{var}(x)=7529.6875 or 75307530 to 33 significant figures.

MME Premium Laptop

Save your answers with

MME Premium

Gold Standard Education

Additional Resources

Site Logo

Exam Tips Cheat Sheet

A Level
Site Logo

Formula Booklet

A Level

Specification Points Covered

L3 – Interpret measures of central tendency and variation, extending to standard deviation, be able to calculate standard deviation, including from summary statistics
L4 – Be able to clean data, including dealing with missing data, errors and outliers