Statistics for
Data Science 1
Describing categorical data: frequency tables, charts, honest graphs, and the mode and median.
Chapters
- 01Frequency DistributionsLecture 2.1
- 02Relative FrequencyLecture 2.1
- 03Pie ChartsLecture 2.2
- 04Bar ChartsLecture 2.2
- 05Pareto Charts and Ordinal DataLecture 2.2
- 06Best Practices and Misleading GraphsLectures 2.3 and 2.4
- 07ModeLecture 2.5
- 08Median for Ordinal DataLecture 2.5
- 09Week 2 Summary SheetAll lectures
Based on lectures by Usha Mohan, IIT Madras
Frequency Distributions
Week 2 is about describing one categorical variable. Everything starts with a frequency table: a list of the categories and how many times each one occurs.
1.1Where this fits
Lecture 2.1 starts with a review of Week 1. Frequency tables are the first tool for one categorical variable, so three ideas from Week 1 are the background.
- Descriptive and inferential statistics.
- Sample versus population.
- Variables and cases (observations) in a data set.
- Categorical (qualitative) or numerical (quantitative).
- Cross-sectional versus time-series; measurement scales.
1.2Steps to build a frequency distribution
- List the distinct values. Write each different category once, in the first column.
- Tally every observation. Go through the data one value at a time and put a tally mark in that value's row.
- Count the tallies. Turn each row of tally marks into a number. This is the frequency.
1.3Lecture examples: four data sets
The lecture builds a frequency table for four lists of categories. Read each list from left to right; every observation adds one tally to its row. After counting, the frequencies must add up to the number of observations.
Data set 1 (10 observations): A, A, B, C, A, D, A, B, D, C
| Category | Tally | Frequency |
|---|---|---|
| A | |||| | 4 |
| B | || | 2 |
| C | || | 2 |
| D | || | 2 |
| Total | 10 |
Check: , the number of observations.
All four data sets together
| Data set | n | A | B | C | D | Sum |
|---|---|---|---|---|---|---|
| Data set 1 | 10 | 4 | 2 | 2 | 2 | 10 |
| Data set 2 | 15 | 6 | 3 | 3 | 3 | 15 |
| Data set 3 | 15 | 3 | 6 | 3 | 3 | 15 |
| Data set 4 | 18 | 6 | 3 | 4 | 5 | 18 |
- Data set 2:
A, A, B, C, A, D, A, B, D, C, A, B, C, D, A - Data set 3:
A, B, B, C, A, D, B, B, D, C, A, B, C, D, B - Data set 4:
A, A, B, C, A, D, A, B, D, C, A, B, C, D, A, C, D, D
A,A,B,C,A,A,B,B,D,C,A,B,C,D,B. The solution slides use A,B,B,C,A,D,B,B,D,C,A,B,C,D,B, and their frequencies (A = 3, B = 6, C = 3, D = 3) match only this second list. These notes use the second list.1.4Frequency table in a Google Sheet
- Select (highlight) the cells that have the data you want to summarise.
- In the formatting bar click the Data option.
- Go to Pivot table and create it in a new sheet.
- In the Pivot table editor, first add Rows and then add Values.
1.5Going deeper: reading and checking a frequency table
- The total is your safety check. The frequencies must add up to the number of observations. If they do not, you skipped or double-counted something.
- Count from the list, not from the table. Cross out each observation as you tally it, so none is counted twice.
- Order of the rows does not matter for a nominal variable. Write the categories in any sensible order (here A to D).
- Frequency is a count, so it is a whole number: 0, 1, 2, ... It is never negative and never a fraction. Fractions come in the next topic.
- Always write the total row and check it against the number of observations.
- A table with the right shape but the wrong total means a counting slip: recount the largest category first.
- Listing a category twice in the first column.
- Calling the tally marks the frequency. The frequency is the number you get by counting them.
- Forgetting the total check.
Practice questions (graded-assignment style)
Multiple Choice Question (MCQ): choose the one correct option.
The observations are B, A, B, C, B, A, C, B, D, B. What is the frequency of B?
Count the B's while going through the list once.
- B appears at positions 1, 3, 5, 8 and 10.
- That is 5 tallies, so the frequency is 5.
- Answer: option 3.
Numerical Answer Type (NAT).
A frequency table for 25 observations has A = 9, B = 6, C = 4, D = 3 and a fifth category E whose frequency is missing. Find the frequency of E.
The frequencies add up to the number of observations.
- .
- .
- Answer: 3
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Frequency is a count; a fraction is a relative frequency.
- Option 1 is correct: that is the definition.
- Option 2 is correct: it is the check at the end.
- Option 3 is correct: that is Step 2.
- Option 4 is wrong: fractions between 0 and 1 are relative frequencies.
- Answer: options 1, 2 and 3.
Multiple Choice Question (MCQ): choose the one correct option.
The colours of ten cars are R, G, B, R, G, R, R, B, G, R. Which frequency table is correct?
Count each colour and check the total is 10.
- R is at positions 1, 4, 6, 7, 10: 5 times.
- G is at positions 2, 5, 9: 3 times.
- B is at positions 3, 8: 2 times. Total .
- Answer: option 1.
Relative Frequency
Raw counts cannot compare two data sets of different sizes. Dividing each count by its own total gives a proportion, and proportions can be compared.
2.1Steps to construct it
- Obtain a frequency distribution of the data.
- Divide each frequency by the total number of observations.
A relative frequency is always between 0 and 1, and the relative frequencies of all categories add to 1.
2.2Why use relative frequency?
- Two data sets can have different numbers of observations. Raw counts are not comparable, but proportions are.
- Relative frequencies always fall between 0 and 1, so they give a standard for comparison.
On the first figure the bars for data set 2 are taller because it has 15 observations instead of 10. On the second, both data sets give 0.4, 0.2, 0.2, 0.2: once each count is divided by its own total, the two data sets have exactly the same pattern.
2.3Lecture examples: relative frequencies
The lecture leaves the last column blank for data sets 3 and 4, so those values are worked out here from the frequencies.
| Data set | n | A | B | C | D |
|---|---|---|---|---|---|
| 1 | 10 | 4 ÷ 10 = 0.4 | 2 ÷ 10 = 0.2 | 2 ÷ 10 = 0.2 | 2 ÷ 10 = 0.2 |
| 2 | 15 | 6 ÷ 15 = 0.4 | 3 ÷ 15 = 0.2 | 3 ÷ 15 = 0.2 | 3 ÷ 15 = 0.2 |
| 3 | 15 | 3 ÷ 15 = 0.2 | 6 ÷ 15 = 0.4 | 3 ÷ 15 = 0.2 | 3 ÷ 15 = 0.2 |
| 4 | 18 | 6 ÷ 18 = 0.333 | 3 ÷ 18 = 0.167 | 4 ÷ 18 = 0.222 | 5 ÷ 18 = 0.278 |
- Data set 1: . Data set 2 gives the same relative frequencies although the counts differ.
- Data set 3: . B is the largest share, 40 percent.
- Data set 4: . When a division does not end, the values are rounded to three decimals, so the rounded column can differ from 1 in the last digit (see Chapter 6, round-off errors).
2.4Going deeper: frequency versus relative frequency
- Use frequency when you want to know how many. Use relative frequency when you want to compare shares or compare two data sets.
- Percent is relative frequency times 100. A relative frequency of 0.4 is 40 percent.
- To go back, multiply by the total: . For and relative frequency 0.25 the frequency is 10.
- Obtain the frequency table first, then divide. Do not divide the raw list.
- Add the column at the end: it should be 1 (or 1.000 after rounding).
- Dividing by the number of categories instead of the number of observations.
- Concluding that two data sets differ because their counts differ. Compare relative frequencies.
Practice questions (graded-assignment style)
Numerical Answer Type (NAT).
A category has frequency 18 in a data set of 60 observations. Find its relative frequency.
Divide the frequency by the total.
- .
- Answer: 0.3
Multiple Choice Question (MCQ): choose the one correct option.
Data set X has 40 observations with 12 A's. Data set Y has 60 observations with 15 A's. Which statement is correct?
Compare proportions, not counts.
- X: .
- Y: .
- Y has more A's in count, but X has the larger proportion.
- Answer: option 1.
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Relative frequency is frequency divided by total.
- Options 1 and 2 are the two standard properties.
- Option 3 is correct: data sets 1 and 2 both give 0.4, 0.2, 0.2, 0.2.
- Option 4 is wrong: it is frequency divided by total.
- Answer: options 1, 2 and 3.
Numerical Answer Type (NAT).
In a data set of 40 observations the relative frequencies are A = 0.35, B = 0.40 and C = 0.25. Find the frequency of C.
Multiply the relative frequency by the total.
- .
- Check: A = 14, B = 16, C = 10 and .
- Answer: 10
Pie Charts
The two most common displays of a categorical variable are a bar chart and a pie chart. Both describe the variable by displaying its frequency table.
3.1Steps to construct a pie chart
- Obtain a relative-frequency distribution of the data.
- Divide a circle into pieces proportional to the relative frequencies.
- Label the slices with the distinct values and their relative frequencies.
3.2Finding the angle of each slice
Use a protractor and the fact that a full circle has . Each slice gets an angle equal to its relative frequency times .
For the first slice of the lecture example the relative frequency is 0.4, so the angle is .
3.3Lecture examples: slice angles
Data set 1: A, A, B, C, A, D, A, B, D, C
| Category | Frequency | Relative freq | Degrees |
|---|---|---|---|
| A | 4 | 0.4 | 144° |
| B | 2 | 0.2 | 72° |
| C | 2 | 0.2 | 72° |
| D | 2 | 0.2 | 72° |
| Total | 10 | 1 | 360° |
Check: , the full circle.
Data set 2: same slices
The frequencies are 6, 3, 3, 3 with total 15, so the relative frequencies are again 0.4, 0.2, 0.2, 0.2 and the angles are again . The pie chart looks identical: a pie chart depends only on the relative frequencies, not on the number of observations.
3.4Pie chart in a Google Sheet
- Select (highlight) the cells that have the data you want to visualise.
- Click the Insert chart option in the toolbar.
- Change the visualisation type in the Chart editor.
- Set the Chart type to Pie chart.
3.5Going deeper: when to use a pie chart
- A pie chart shows parts of a whole. It is a good way to show that one category makes up more than half of the total.
- Angles always add to 360°, and relative frequencies always add to 1. Use whichever sum is easier as a check.
- Too many thin slices are hard to read. Chapter 6 shows how to group small categories.
- From a table: angle = relative frequency × 360. From a pie: relative frequency = angle ÷ 360.
Practice questions (graded-assignment style)
Numerical Answer Type (NAT).
In a data set of 30 observations a category has frequency 9. What is the angle of its slice in a pie chart, in degrees?
Relative frequency first, then multiply by 360.
- .
- .
- Answer: 108
Numerical Answer Type (NAT).
A category has relative frequency 0.35. Find the angle of its slice, in degrees.
Angle = relative frequency × 360.
- .
- Answer: 126
Multiple Choice Question (MCQ): choose the one correct option.
In a pie chart the slices for A, B, C and D have angles 144°, 72°, 72° and 72°. What is the relative frequency of A?
Relative frequency = angle ÷ 360.
- .
- Check: .
- Answer: option 2.
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
A pie chart depends only on relative frequencies.
- Options 1 and 2 are the rules.
- Option 3 is correct: both have relative frequencies 0.4, 0.2, 0.2, 0.2.
- Option 4 is wrong: same relative frequencies mean the same pie.
- Answer: options 1, 2 and 3.
Bar Charts
4.1Steps to construct a bar chart
- Obtain a frequency or relative-frequency distribution of the data.
- Draw a horizontal axis on which to place the bars and a vertical axis to display the frequencies or relative frequencies.
- For each distinct value, construct a vertical bar whose height equals the frequency or relative frequency of that value.
- Label the bars with the distinct values, the horizontal axis with the name of the variable, and the vertical axis with “Frequency” or “Relative frequency”.
4.2Anatomy of a bar chart
The horizontal axis carries the categories and is named after the variable. The vertical axis carries the frequency, so the bar for A reaches 4 and the other three reach 2. The gaps between the bars remind us that the categories are separate groups, not one continuous scale.
4.3Lecture example: bar chart from a frequency table
- The frequency distribution of data set 1 is .
- Axes: categories A to D along the bottom, frequency from 0 to 5 up the side.
- Draw bars of height 4, 2, 2 and 2, separated by gaps.
- Label the bars A to D, the horizontal axis “Category” and the vertical axis “Frequency”.
Using the relative frequencies instead gives the same shape with the vertical axis running 0 to 0.4.
4.4Bar chart in a Google Sheet
- Select (highlight) the cells that have the data you want to visualise.
- Click the Insert chart option in the toolbar.
- Change the visualisation type in the Chart editor.
- Set the Chart type to Bar chart.
4.5Going deeper: what to remember about bar charts
- A bar chart shows the frequencies or relative frequencies of a categorical variable.
- If the variable is ordinal, the order of the categories is preserved. The bars are not re-sorted (Chapter 5).
- The bars can be vertical or horizontal. The rule that matters is that bar length is proportional to the value.
- Bars must not touch. That is what separates a bar chart (categories) from a histogram (numbers on a continuous scale, a later topic).
- Drawing the bars touching each other.
- Leaving the axes unlabelled.
- Starting the vertical axis above zero (Chapter 6).
Practice questions (graded-assignment style)
Multiple Choice Question (MCQ): choose the one correct option.
In a bar chart of a categorical variable, the bars should
The gaps show the categories are separate groups.
- Option 1 is wrong: touching bars belong to a histogram.
- Option 3 is wrong: ordinal variables keep their natural order.
- Option 4 is wrong: the lecture says bars can be horizontal or vertical.
- Answer: option 2.
Numerical Answer Type (NAT).
Data set 4 has 18 observations with frequencies A = 6, B = 3, C = 4, D = 5. In a bar chart of relative frequencies, what is the height of the bar for D? Give the answer to three decimal places.
Divide the frequency by the total.
- To three decimal places: .
- Answer: 0.278
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Recall the definition and the summary points.
- Options 1, 2 and 4 are all stated in the lecture.
- Option 3 is wrong: the bars should not touch.
- Answer: options 1, 2 and 4.
Multiple Choice Question (MCQ): choose the one correct option.
A bar chart of frequencies and a bar chart of relative frequencies are drawn for the same data. How do they compare?
Dividing every frequency by the same total keeps all the ratios between bars.
- Every bar is divided by the same number, so the pattern does not change; only the axis labels do.
- Answer: option 1.
Pareto Charts and Ordinal Data
5.1Lecture example: a Pareto chart
Data (15 observations): A, B, B, C, A, D, B, B, A, C, B, B, C, D, A.
| Category | Frequency | Relative freq | As printed on the slide |
|---|---|---|---|
| A | 4 | 4/15 = 0.267 | 0.26 |
| B | 6 | 6/15 = 0.400 | 0.40 |
| C | 3 | 3/15 = 0.200 | 0.20 |
| D | 2 | 2/15 = 0.133 | 0.14 |
| Total | 15 | 1 | 1 |
The slide prints 0.26, 0.40, 0.20, 0.14 so that the column adds up to exactly 1. The exact values are and (rounded to three decimals), which is why the third column is shown with three decimals.
- Sort the categories by frequency: B (6), A (4), C (3), D (2).
- Draw the bars in that order, tallest first.
5.2Lecture example: ordinal data
The T-shirt sizes (Small S, Medium M, Large L) of twenty students are L, M, M, S, L, S, S, M, L, M, M, S, S, L, M, S, M, S, L, M. Make the frequency table and the bar chart.
| Size | Frequency | Relative freq |
|---|---|---|
| Small | 7 | 7 ÷ 20 = 0.35 |
| Medium | 8 | 8 ÷ 20 = 0.40 |
| Large | 5 | 5 ÷ 20 = 0.25 |
| Total | 20 | 1 |
Check: . Size is ordinal (Small < Medium < Large), so the bars keep this order and are not sorted by height.
5.3Pareto or ordered bars?
- No natural order.
- Sort by frequency to get a Pareto chart.
- A natural order exists.
- Keep that order along the horizontal axis.
- Ask first: is the variable nominal or ordinal? That decides whether sorting is allowed.
- In a Pareto chart the heights fall from left to right.
- Sorting the S, M, L bars by height. This destroys the order of the sizes.
- Sorting from lowest to highest in a Pareto chart.
Practice questions (graded-assignment style)
Multiple Choice Question (MCQ): choose the one correct option.
A bar chart is drawn for the grades Poor, Fair, Good and Excellent (an ordinal variable). Should the bars be sorted by height?
Ordinal categories keep their natural order.
- Sorting by height would put the grades in a meaningless order.
- Answer: option 2.
Multiple Choice Question (MCQ): choose the one correct option.
A nominal variable has frequencies A = 3, B = 7, C = 5, D = 2. In its Pareto chart, which category gets the second bar from the left?
Sort from the highest frequency to the lowest.
- Sorted order: B (7), C (5), A (3), D (2).
- The second bar is C.
- Answer: option 3.
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Recall the definition.
- Options 1, 2 and 4 follow from the definition and the lecture.
- Option 3 is wrong: ordinal bars keep their natural order.
- Answer: options 1, 2 and 4.
Numerical Answer Type (NAT).
The frequencies of a nominal variable are A = 4, B = 6, C = 3, D = 2. In the Pareto chart, what is the height of the second bar from the left?
Sort first, then read the second value.
- Sorted: 6 (B), 4 (A), 3 (C), 2 (D).
- The second bar has height 4.
- Answer: 4
Best Practices and Misleading Graphs
6.1Know your purpose
Have a purpose for every table or graph you create, and choose the table or graph to serve that purpose.
- Best when you are trying to compare parts of a whole.
- Used to compare things between different groups.
6.2Label your data
- Label your chart to show the categories and indicate whether some have been combined or omitted.
- Name the bars in a bar chart.
- Name the slices in a pie chart.
- If you have omitted some of the cases, make sure the label of the plot defines the collection that is summarised.
Example: the same grades, grade A = 7, B = 3, C = 7, D = 2 (19 students), drawn both ways with a title, named slices or bars, and labelled axes. The relative frequencies are , , and .
6.3Many categories
A bar chart or pie chart with too many categories might conceal the more important categories. In some cases, grouping the other categories together helps.
Example: a variable has 26 categories A to Z with counts A = 11, B = 6, C = 9, D = 4 and one case in each of E to Z. The 22 single-case categories are drawn as 22 tiny bars that crowd the chart and hide the four categories that matter. Grouping E to Z gives cases, so the new category Others has count 22 and the chart has five clear bars.
6.4The area principle and decorated graphs
Decorated graphics. Charts decorated to attract attention often violate the area principle. Example: total U.S. wine exports (millions of dollars): United Kingdom 150.3, Canada 146.8, Japan 82.8, Italy 42.5, Netherlands 34.4. A decorated graphic with bottles on top of boxes of various sizes and shapes and no baseline breaks the principle, because the size of a box does not correspond to its value.
6.5Truncated graphs
Another common violation is when the baseline of a bar chart is not at zero. Example: regionwise counts South 146, West 97, North 146, East 111. If the vertical axis starts at 75, the visible bar heights are , , and . The South bar then looks about times the West bar, but the true ratio is only .
6.6Round-off errors
When table entries are percentages or proportions, the total may sum to a value slightly different from 100% or 1. This might result in a pie chart where the total does not add up. Example: Samsung 20%, Apple 15%, Nokia 14%, HTC 11%, RIM 10%, Others 31%. Then , so the labels total 101% instead of 100%.
Each share was rounded to a whole percent, so the total drifted from 100%.
6.7Going deeper: a checklist before you trust a graph
- Purpose: parts of a whole (pie) or groups against each other (bar)?
- Labels: title, named slices or bars, labelled axes, and a note on anything combined or omitted.
- Categories: too many? Group the small ones into Others.
- Area principle: no decoration that changes sizes, and the baseline at zero (or a break mark).
- Round-off: do the labels add to 100% (or 1)?
- Judging bar sizes by eye on a truncated axis.
- Using a pie chart for many tiny categories.
- Forgetting that rounded percentages may not add to exactly 100%.
Practice questions (graded-assignment style)
Numerical Answer Type (NAT).
A bar chart has its vertical axis starting at 75 and shows counts 146 and 97 for two regions. What is the true ratio of the two counts, , to one decimal place?
Use the real counts, not the visible heights.
- To one decimal place: . The truncated chart makes it look like .
- Answer: 1.5
Numerical Answer Type (NAT).
A pie chart has three slices each labelled 33%. What do the labels add up to, in percent?
Add the labels.
- .
- Each slice is really ; rounding makes the total 99%, not 100%.
- Answer: 99
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Recall the area principle.
- Options 1, 2 and 4 are stated in the lecture.
- Option 3 is wrong: decorated graphics often violate the area principle.
- Answer: options 1, 2 and 4.
Numerical Answer Type (NAT).
A variable has 11 categories with counts A = 14, B = 9, C = 6 and 8 further categories with one case each. If the 8 single-case categories are grouped as Others, what is the count of Others?
Add the single-case categories.
- .
- The chart then has four bars: A, B, C and Others.
- Answer: 8
Mode
Bar charts and pie charts are graphical summaries of categorical data. Sometimes we want a single label that sums up the data set. Numbers used to describe data sets are called descriptive measures; those that indicate where the center or most typical value lies are called measures of central tendency.
7.1Where the mode shows up in a chart
- It labels the longest bar in a bar chart.
- It labels the widest slice in a pie chart.
- In a Pareto chart, the mode is the first category shown.
7.2Lecture example: finding the mode
Find the mode of A, A, B, C, A, D, A, B, C, C, A, B, C, D, A.
- Count each category: (total ).
- The highest frequency is 6, for A.
The most common category is A, so the mode is A. This is the longest bar in the figure above.
7.3Bimodal and multimodal data
Example: A, A, B, C, A, C, A, B, C, C, A, C, C, D, A, A, C, D, B. The counts are (total ). The highest frequency, 7, is shared by A and C, so the data are bimodal.
7.4Going deeper: what the mode can and cannot do
- The mode works for any categorical data, ordinal or not. It only needs counts.
- The mode is a category, not a number. The answer is “A”, not “6”. The 6 is the frequency of the mode.
- A data set can have more than one mode (bimodal or multimodal) when categories tie.
- Write the category, then its frequency in brackets: “mode is A (6 times)”.
- If the top two frequencies are equal, say bimodal and name both categories.
- Answering with the frequency (6) instead of the category (A).
- Naming only one category when two tie.
Practice questions (graded-assignment style)
Multiple Choice Question (MCQ): choose the one correct option.
The observations are R, G, B, G, G, R, B, G. What is the mode?
Count each category.
- R = 2, G = 4, B = 2 (total 8).
- G has the highest frequency, 4.
- Answer: option 2.
Multiple Choice Question (MCQ): choose the one correct option.
The frequencies of four categories are A = 5, B = 7, C = 7, D = 3. The data are
Look for a tie at the top.
- The highest frequency, 7, belongs to both B and C.
- Answer: option 3.
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
Recall the definition and the chart links.
- Options 1, 2 and 3 are correct.
- Option 4 is wrong: ties give bimodal or multimodal data.
- Answer: options 1, 2 and 3.
Numerical Answer Type (NAT).
The frequencies are A = 8, B = 11, C = 11, D = 9. How many modes does the data set have?
Count the categories that share the highest frequency.
- The highest frequency is 11, shared by B and C.
- Answer: 2
Median for Ordinal Data
Ordinal data offer another summary, the median, that is not available unless the data can be put into order.
8.1Three steps to the median
- Put in order. Sort the observations by their natural order.
- Find the middle. Odd count: one middle value. Even count: two middle values.
- Read its category. The category there is the median. Either side is fine when the count is even.
For 15 observations the middle is the 8th. For 14 observations the two middle observations are the 7th and the 8th.
8.2Lecture examples
15 grades: the median is the 8th observation
Grades: A, B, B, C, A, D, B, B, A, C, B, B, C, D, A. In grade order A, B, C, D the sorted data are A,A,A,A,B,B,B,B,B,B,C,C,C,D,D.
The most common grade is B (6 times), so the mode is also B. In this example the mode and the median are the same.
14 grades: two middle observations
Grades: A, B, B, C, A, D, B, B, A, C, B, B, C, D. Sorted: A,A,A,B,B,B,B,B,B,C,C,C,D,D. With 14 observations the two middle ones are the 7th and the 8th. Both are B, so the median grade is B.
15 grades where the mode and the median differ
Grades: A, B, B, C, A, D, A, B, A, C, B, A, C, D, A. Sorted: A,A,A,A,A,A,B,B,B,B,C,C,C,D,D. The first six are A and the next four are B, so the 8th observation is B and the median is B. The most common grade is A (6 times), so the mode is A.
8.3Going deeper: why only ordinal data?
- Sorting needs a natural order. Nominal categories (colours, cities) have none, so “the middle one” has no meaning.
- Always sort first. Reading the 8th item of the unsorted list is the commonest slip.
- Mode and median answer different questions. The mode is the most common category; the median is the category of the middle observation. They can be the same or different.
- Write the sorted list as a run of letters and count to the middle position.
- Check that your sorted list has the same number of letters as observations.
- Taking the middle of the unsorted list.
- Sorting in the wrong order (the order must be the natural order of the grades).
- Computing a median for a nominal variable.
Practice questions (graded-assignment style)
Numerical Answer Type (NAT).
A sorted ordinal data set has 21 observations. At which position is the median observation?
Use .
- .
- Answer: 11
Multiple Choice Question (MCQ): choose the one correct option.
An ordinal data set has 14 observations. The median is the category at
With an even count there are two middle observations.
- The two middle observations are the 7th and the 8th; the lecture allows either side.
- Answer: option 2.
Multiple Choice Question (MCQ): choose the one correct option.
Grades of 15 students, in the order A < B < C < D: there are 2 A's, 3 B's, 5 C's and 5 D's. What is the median grade?
Sort, then find the 8th observation.
- Sorted: A at 1 to 2, B at 3 to 5, C at 6 to 10, D at 11 to 15.
- The 8th observation falls in the C block (positions 6 to 10).
- Answer: option 3.
Multiple Select Question (MSQ): select all that apply.
Choose the correct statements.
The median needs sorting.
- Options 1, 2 and 3 are correct.
- Option 4 is wrong: nominal categories have no natural order.
- Answer: options 1, 2 and 3.
Week 2 Summary Sheet
Everything in Week 2 on one sheet, topic by topic, for a last-minute revision.
What each tool is for
| Tool | What it shows | Works for |
|---|---|---|
| Frequency table | Counts of each category | Any categorical variable |
| Relative frequency table | Proportion of each category; compare data sets | Any categorical variable |
| Pie chart | Parts of a whole; shows if one category is over half | Any categorical variable |
| Bar chart | Compare groups; bars separated; either orientation | Any; keep the order if ordinal |
| Pareto chart | Bar chart sorted by frequency (quality control) | Nominal categories |
| Mode | Most common category | Any categorical variable |
| Median | Category of the middle observation after sorting | Ordinal only |
Formulas and rules
- relative frequency = frequency ÷ total
- All relative frequencies add to 1.
- angle = relative frequency × 360°
- All angles add to 360°.
- Position = .
- 15 observations: the 8th. 14 observations: the 7th or 8th.
- Baseline at zero (or a break mark).
- Labels add up (round-off).
- Area matches the amount of data.
Topic by topic
- Frequency table: list, tally, count.
- Relative frequency = frequency / total.
- Pie chart: slices from relative frequency.
- Bar chart and Pareto chart (sorted).
- Ordinal data keep their order.
- Know your purpose, label your data.
- Group many small categories.
- Area principle; avoid decorated and truncated graphs; check round-off.
- Mode: most common category; bimodal or multimodal when tied.
- Median: ordinal data only; middle observation of the sorted data.
Relative frequency = frequency / total
Bar chart and Pareto chart (sorted)
Ordinal data keep their order
Group many small categories
Area principle
Truncated axis (use a break mark)
Round-off errors
Bimodal or multimodal when tied
Middle observation of the sorted data