001Mathematics · Statistics

Quartiles and the Inter-quartile Range

The IQR quartiles program

Enter each value and frequency of a frequency table (or bar chart); the program follows the DSE method to show the position and value of Q₁, Q₂ and Q₃, then the inter-quartile range.

  • 228 bytes
  • COMP mode
  • Up to 6 groups
01

Worked examples

Example 1

The table shows the distribution of the numbers of pens owned by the students of a class. Find the inter-quartile range of the distribution.

Data for Example 1
Number of pens45678
Number of students68842
  1. A.1
  2. B.1.5
  3. C.2
  4. D.2.5
Answer
A — the inter-quartile range is 1
Standard solution (without a calculator)
  1. Total: N = 6 + 8 + 8 + 4 + 2 = 28
  2. Cumulative frequencies:
    Cumulative frequencies for Example 1
    Number of pens45678
    Cumulative frequency614222628
  3. Median: position = = 14.5, the mean of the 14th and 15th data. From the cumulative frequencies, the 14th datum is 5 and the 15th is 6.
    ∴ Q₂ = = 5.5
  4. Lower quartile: N is even, so the lower half is the 1st to 14th data.
    Q₁ = = = 5
  5. Upper quartile: the upper half is the 15th to 28th data.
    Q₃ = = = 6
  6. Inter-quartile range = Q₃ − Q₁ = 6 − 5 = 1
    ∴ The answer is A.
Do it on the calculator

Example 2

The bar chart shows the distribution of the numbers of days on which 25 students of a class did exercise last week. Find the inter-quartile range of the distribution.

Days of exercise last weekNumber of days → Number of students: 1 → 3; 2 → 3; 3 → 7; 4 → 8; 5 → 4123450123456789Number of daysNumber of students
  1. A.1
  2. B.1.5
  3. C.2
  4. D.2.5
Answer
B — the inter-quartile range is 1.5
Standard solution (without a calculator)
  1. Total: N = 3 + 3 + 7 + 8 + 4 = 25
  2. Cumulative frequencies:
    Cumulative frequencies for Example 2
    Number of days12345
    Cumulative frequency36132125
  3. Median: position = = 13, ∴ Q₂ = the 13th datum = 3
  4. The two halves: N is odd, so the median (the 13th datum) belongs to neither half. The lower half is the 1st to 12th data; the upper half is the 14th to 25th data.
  5. Lower quartile: Q₁ = median of the lower half = = = 2.5
  6. Upper quartile: Q₃ = median of the upper half = = = 4
  7. Inter-quartile range = 4 − 2.5 = 1.5
    ∴ The answer is B.

Common mistake: counting the median in both halves (1st to 13th for the lower half) gives Q₁ = 3, Q₃ = 4 and IQR = 1 — the wrong option A.

Do it on the calculator

Example 3

The table shows the distribution of the numbers of siblings of 40 students.

Data for Example 3
Number of siblings012345
Number of students10128631
  1. (a)Find the median of the distribution.
  2. (b)Find the inter-quartile range of the distribution.
Answer
(a) Median = 1 (b) Inter-quartile range = 2
Standard solution (without a calculator)
  1. Total: N = 10 + 12 + 8 + 6 + 3 + 1 = 40
  2. Cumulative frequencies:
    Cumulative frequencies for Example 3
    Number of siblings012345
    Cumulative frequency102230363940
  3. (a) Median: position = = 20.5
    Median = = = 1
  4. (b) Lower quartile: the lower half is the 1st to 20th data.
    Q₁ = = = 0.5
  5. Upper quartile: the upper half is the 21st to 40th data.
    Q₃ = = = 2.5
  6. Inter-quartile range = Q₃ − Q₁ = 2.5 − 0.5 = 2
Do it on the calculator
02

When to use it

In the Statistics strand of HKDSE Mathematics (Compulsory Part) you often need the lower quartile Q₁, the median Q₂, the upper quartile Q₃ and the inter-quartile range (IQR) from a frequency table or a bar chart. By hand you count the total, build cumulative frequencies and locate each position — and when N is odd you must remember to leave the median out of both halves. There are many steps, and it is easy to miscount.

Program 001 does the counting for you. Enter each value and its frequency, and it shows the position and value of Q₁, Q₂ and Q₃ in turn, then the IQR. The positions tell you which quartile is on screen and make it easy to compare with your own working.

  • Use it for

    • Frequency tables or bar charts of discrete data
    • The lower quartile, median, upper quartile or IQR
    • Checking Paper 1 answers; answering Paper 2 MCs quickly
  • You enter

    • Each value x and its frequency f (x first), smallest value first
    • Up to 6 groups; then press EXE once at X? and once at Y?
    • With exactly 6 groups it starts by itself
  • It shows

    • Position of Q₁ → Q₁
    • Position of Q₂ → Q₂ (the median)
    • Position of Q₃ → Q₃
    • Finally: IQR = Q₃ − Q₁

The DSE method it follows

  1. Arrange the N data in ascending order.
  2. The median Q₂ is at position .
  3. Split the data into a lower half and an upper half; when N is odd, the median belongs to neither half.
  4. Q₁ = median of the lower half, Q₃ = median of the upper half, IQR = Q₃ − Q₁.
  5. A position ending in .5 (e.g. 7.5) means the mean of the 7th and 8th data.

Limits and tips

  • Up to 6 groups; at least 2 data in total.
  • Each x must be a whole number, entered in ascending order; the first x can be at most 99, and neighbouring values can differ by at most 99.
  • The cumulative frequency before the last group can be at most 99 (the last frequency can be larger).
  • Large values (e.g. 150): subtract the same number from every x first, then add it back to Q₁, Q₂ and Q₃; the IQR is unchanged.
  • Decimal or negative values: multiply by 10 or add a constant to get non-negative whole numbers, then convert back.
  • The program switches to Fix 0 while computing and back to Norm 1 at the end. If you stop it with AC, press SHIFTMODERight31 to return to Norm 1.
03

Program and keys

001_IQR_quartiles.fx50COMP · 228 bytes
ClrMemory:1→B:For 1→C To 6:X→D:?→X:−1→Y:?→Y:Y<0⇒Break:100A+X−D→A:100B+M→B:YM+:Next:(2M+1−(−1)^(M))÷8→D:(M+1)÷2−D→C:Lbl 1:Fix 0:1→X:0→Y:While X<A+1:Rnd(B÷X−.5)−100Rnd(B÷100X−.5:Y+(Rnd(A÷X−.5)−100Rnd(A÷100X−.5))((Ans<C−.5)+(Ans<C))÷2→Y:100X→X:WhileEnd:Norm 1:C◢Y◢M>0⇒−Y→M:C+D→C:C<3D+1⇒Goto 1:Y+M
  • : is EXE while editing; ◢ is SHIFT34 — do not press EXE after ◢.
  • The − in −1→Y and (−1)^( is the negative sign (−); every other − is the subtraction key −.
  • Line breaks are only for reading; the : at the end of each line must be keyed.

How it works

StatementWhat it does
ClrMemory:1→BClears memory and puts a leading 1 in B as a marker
For 1→C To 6 … NextReads up to 6 groups (no loop inside the For)
X→D:?→XD = the previous x; asks for the new x (the prompt shows the previous x)
−1→Y:?→Y:Y<0⇒BreakAsks for the frequency; the prompt shows −1, and EXE alone ends the input
100A+X−D→APacks the gap from the previous x into A, two digits per group
100B+M→BPacks the cumulative frequency before each group into B, two digits per group
YM+M = the total N
(2M+1−(−1)^(M))÷8→DD = the distance between neighbouring quartile positions
(M+1)÷2−D→CC = the position of Q₁
Lbl 1 … C<3D+1⇒Goto 1Runs three times (Q₁, Q₂, Q₃), adding D to C each time
Fix 0 … WhileEndUnpacks the groups from the last one back and finds the value at position C (the mean of two data when C ends in .5)
Norm 1:C◢Y◢Back to normal display; shows the position C and the value Y
M>0⇒−Y→MFirst time only (Q₁): stores −Q₁ in M
Y+MFinally shows Q₃ − Q₁ = IQR

Typing the program in

  1. MODE 6 (PRGM) → 1 (EDIT) → an empty program area, e.g. 1 (P1) → 1 (COMP).
  2. Key in the table below, from step 1 to the last step.
  3. Press AC to leave the editor.
  4. Check: press MODE 6 1 again. The lower line should show P-1234 452 (680 − 228 = 452 bytes free; less if other areas hold programs). Then press AC.

The step most often missed is step 67: the ) after (−1. Without it the program is 227 bytes (the check shows 453) and every result is wrong — the first position becomes −42.625, for example. If a position is negative, check this step first.

Key reference

Every kind of symbol the program uses, with its keys.

SymbolKeysMeaning
Loading the table… (this table needs JavaScript)

Every key, in order (209 steps)

Work from step 1 to the last step to finish. The table scrolls and its header stays in view.

Every key, in order (209 steps)
StepSymbolKeys
Loading the table… (this table needs JavaScript)
04

On the calculator

Each example run on the calculator: the question and its data, then every key to enter from starting the program and what the screen shows afterwards.

Example 1

Question

The table shows the distribution of the numbers of pens owned by the students of a class. Find the inter-quartile range of the distribution.

Data for Example 1
Number of pens45678
Number of students68842
  1. A.1
  2. B.1.5
  3. C.2
  4. D.2.5
Enter
4,65,86,87,48,2EXE only:EXEEXE
Shows
7.5514.55.521.561
Keys and screen for Example 1
#EnterScreen afterwardsNotes
Loading the table… (this table needs JavaScript)

Example 2

Question

The bar chart shows the distribution of the numbers of days on which 25 students of a class did exercise last week. Find the inter-quartile range of the distribution.

Days of exercise last weekNumber of days → Number of students: 1 → 3; 2 → 3; 3 → 7; 4 → 8; 5 → 4123450123456789Number of daysNumber of students
  1. A.1
  2. B.1.5
  3. C.2
  4. D.2.5
Enter
1,32,33,74,85,4EXE only:EXEEXE
Shows
6.52.513319.541.5
Keys and screen for Example 2
#EnterScreen afterwardsNotes
Loading the table… (this table needs JavaScript)

Example 3

Question

The table shows the distribution of the numbers of siblings of 40 students.

Data for Example 3
Number of siblings012345
Number of students10128631
  1. (a)Find the median of the distribution.
  2. (b)Find the inter-quartile range of the distribution.
Enter
0,101,122,83,64,35,1
Shows
10.50.520.5130.52.52

This table has exactly 6 groups: the program starts as soon as the 6th frequency is entered — no blank EXE needed.

Keys and screen for Example 3
#EnterScreen afterwardsNotes
Loading the table… (this table needs JavaScript)

Notes

  • Input prompts (X?, Y?) sit at the left of the lower line, with the variable’s current value on the right; the upper line stays blank until you type, and EXE confirms.
  • Whole numbers on the lower line keep their decimal point: 5 shows as “5.” and −1 as “-1.”.
  • When the program pauses to show a result, Disp lights at the bottom right of the lower line; press EXE for the next one. Disp goes off when the program ends. While it runs, PRGM and the boxed program area (e.g. P1) light at the top.
  • Step 1 opens the P1–P4 list with the Prog key; press 1 to run P1. MODE 6 → 2 (RUN) → 1 works as well.