Types of data: categorical, numerical, discrete, continuous
A notebook of data comes back with some columns of words and some of numbers. Which columns can you add up, which can you only count, and how can you tell before doing any arithmetic?
Where you are 8 in Data and variables
Why this exists
Olavi runs a fruit stand and writes one line in his notebook for each customer. Some columns hold words (apples, card, cash), some hold numbers (6, 1.2). Adding the pieces of fruit customers bought tells him how many he sold. Suppose he also wrote down each customer’s loyalty card number, say 417 and 856. Adding those gives 1{,}273, which is not a number of anything.
Both columns hold numbers, yet only one takes arithmetic. The difference is what a value is: an amount, or a name for a group. That decides which summaries and graphs can be used at all.
Definition
Here a variable is one feature recorded about each individual, in the sense of Individuals, variables and units. A column that only names each row, such as a customer number, is a tag; Individuals, variables and units does not count it as a variable. Books that do count it call it categorical, a group of one per row. A tag is never numerical.
A variable is categorical when each value names a group, or category, that the individual belongs to. The values are usually words (plum, cash, collie), but they may be letters or numbers used as labels.
A variable is numerical when each value is a number that counts or measures an amount, in a unit. Adding, subtracting and averaging the values give answers that mean something.
The test. Ask: does an average of these values make sense? The average here is the mean: add the values and share the total out equally. If the result is an amount of the same thing, the variable is numerical. If it is meaningless, the variable is categorical.
A numerical variable is one of two kinds.
- Discrete: the values come from counting. The possible values have gaps between them: a count can be 3 or 4, never 3.5.
- Continuous: the values come from measuring a length, mass, time or other amount. Any value in a range is possible, and a recorded value is always rounded to what the measuring tool can show.
Some categorical variables have a natural order, such as small, medium and large, or first, second and third place. They are still categorical: the order says which comes before which, but not by how much.
Intuition
The first split asks what a value is: a name for a group, or an amount. The second split asks how an amount was found: by counting separate things, or by measuring something that can be cut ever finer.
A count sits on separate points with gaps between: nobody buys 2.5 plums. A mass sits anywhere on an unbroken stretch: 1.2 kg, 1.25 kg, 1.253 kg. Writing 1.2 only means the scale showed tenths.
Results
Numbers that are labels are categorical. A number counts as numerical only if it counts or measures an amount. Jersey numbers, postcodes, phone numbers, card numbers and survey codes are names written with digits: their average and their differences are not amounts of anything.
Counts are discrete; measurements are continuous. A measurement stays continuous after it is rounded for recording, even though the recorded values then have gaps.
The type decides the summary.
For categorical data: count each category, name the most common one (the mode), and give each count as a fraction of the whole. These go in Data tables, tallies and frequency tables, Relative frequency tables and Bar graphs and pictographs.
For numerical data: order the values, add, subtract, average and describe the spread. These go in Dot plots and Histograms.
A discrete variable with few possible values suits a dot plot. A continuous variable, where almost every value differs, is usually grouped into intervals first, as in a histogram (Reading a histogram).
Why it is true
Why labels fail the test. A label can be swapped for any other label without changing the data. If a survey codes bike as 2, give the bike riders code 5 instead and every rider is the same rider, yet the average code changes. A summary that changes when nothing about the individuals changed cannot be describing the individuals. An amount cannot be swapped like this: a bag of 1.2 kg is heavier than a bag of 0.8 kg whatever anyone calls it.
Why counts have gaps. A count answers “how many?”, and each thing counted is whole. So a count is a whole number, 0, 1, 2 and so on, and between two neighboring whole numbers there is no count.
Why measurements have none. If two masses a and b are possible, so is the mass halfway between, (a + b) \div 2: add a little fruit to the lighter bag. Halfway between that and a is possible too, and so on without end, so no gap is ever reached. A tool can only show so many decimal places, which is why every recorded measurement is rounded (Measurement is approximate: precision of a tool).
Worked examples
Sorting the fruit stand’s columns
Olavi’s notebook for the first five customers on Saturday, one row each, in order:
| Fruit | Pieces | Mass (kg) | Paid |
|---|---|---|---|
| apples | 6 | 1.2 | card |
| plums | 10 | 0.8 | cash |
| pears | 8 | 2.5 | card |
| apples | 7 | 1.5 | card |
| cherries | 40 | 0.5 | cash |
(a) Sort each variable as categorical or numerical, and each numerical one as discrete or continuous. (b) Find the average mass of a bag and the average number of pieces, and say what each means.
Solution(a) Fruit and how the customer paid name groups: categorical. Pieces counts fruit: numerical and discrete. The mass of the bag is measured on a scale: numerical and continuous. A customer number, if added, would only name each row, so it would be a tag.
(b) The masses share one unit, so they add:
If the fruit were shared equally into five bags, each would hold 1.3 kg. For pieces, 6 + 10 + 8 + 7 + 40 = 71 and 71 \div 5 = 14.2 pieces. No customer can buy 14.2 pieces, but the average still means something: 71 pieces shared equally among five customers. An average of a discrete variable need not be a possible value. An “average fruit” or “average way of paying” has no meaning at all.
Jersey numbers and goals
Ruben coaches a junior hockey team. Five players have jersey numbers 7, 12, 23, 31 and 4, and this season they scored 3, 8, 0, 0 and 5 goals, in that order. Find the average of each list. Which average means something?
SolutionJerseys: 7 + 12 + 23 + 31 + 4 = 77, and 77 \div 5 = 15.4. Goals: 3 + 8 + 0 + 0 + 5 = 16, and 16 \div 5 = 3.2.
The goals average is an amount: 16 goals shared equally would give each player 3.2. The jersey average is not. If the player in 31 switched to shirt 99, the team would play exactly the same, yet the total would be 145 and the average 145 \div 5 = 29. Likewise 31 - 7 = 24 is not 24 of anything. A jersey number names a player, so it is categorical; goals are a count, so numerical and discrete.
The dog show results board
Winnie stewards the agility class at a dog show. Dogs are placed by fewest faults, then by fastest time.
| Dog | Faults | Time (s) | Place |
|---|---|---|---|
| Bramble | 0 | 34.2 | 1st |
| Pip | 1 | 31.8 | 2nd |
| Juno | 1 | 36 | 3rd |
| Taffy | 3 | 29.9 | 4th |
(a) Sort each variable. (b) Why can a time be 31.85 s when faults cannot be 1.5? (c) Find the average placing, and explain why it says nothing about this class.
Solution(a) Faults: a count, so numerical and discrete. Time: measured, so numerical and continuous. Placing: categorical with an order.
(b) Each fault is one whole knocked pole or missed obstacle, so faults are counted. A time is measured; the stopwatch rounds to tenths.
(c) Four dogs with no ties always take places 1 to 4, so the average placing is always
A summary that is the same for every possible class describes none of them. Placings also hide amounts: Pip ran 34.2 - 31.8 = 2.4 s faster than Bramble and still placed behind, because of a fault. The places give the order, not the size of any gap.
Rounded measurements
Vesa weighs apples at the fruit stand on a scale that shows mass to the nearest 10 g. Five apples read 170, 190, 190, 210 and 180 g. (a) The readings jump in steps of 10 g. Does that make mass discrete? (b) What could the true mass of an apple reading 190 g be? (c) Must the two 190 g apples weigh the same?
Solution(a) No. Mass is measured, so it is continuous; the steps come from the scale, not from the apples. A finer scale would show values between.
(b) A mass rounds to 190 g when it is at least 190 - 5 = 185 g and less than 190 + 5 = 195 g: from 185 g up to, but not including, 195 g.
(c) No. One could be 186 g and the other 194 g, which differ by 194 - 186 = 8 g, and both read 190 g. Equal readings mean “equal to the nearest 10 g”, nothing finer.
One feature, two ways to record it
Yngve sorts entries at the dog show into weight classes: small (under 10 kg), medium (10 kg up to 25 kg) and large (25 kg and over). Six dogs weigh 7.5, 19.5, 28, 12, 22 and 19 kg. (a) Which type is mass, and which type is weight class? (b) Count each class. (c) Find the average mass. Could it be found from the class counts alone?
Solution(a) Mass is numerical and continuous. Weight class names a group, so it is categorical, with an order.
(b) Small: 7.5, so 1. Medium: 19.5, 12, 22, 19, so 4. Large: 28, so 1.
(c) 7.5 + 19.5 + 28 + 12 + 22 + 19 = 108 kg, and 108 \div 6 = 18 kg. From “1 small, 4 medium, 1 large” alone, no: the four medium dogs could each weigh 10 kg or nearly 25 kg, and the total would change by almost 60 kg. Sorting a numerical variable into classes makes a categorical one, and the arithmetic is lost with the exact values.
Survey codes
Ruben asks eight players how they get to practice, coded 1 walk, 2 bike, 3 car, 4 bus. The answers are 3, 1, 3, 2, 4, 3, 1, 3. (a) Find the average code and say why it is meaningless. (b) Give a summary that does mean something. (c) He then asks “Did you walk?”, coded 1 yes and 0 no. Find the average code and say what it means.
Solution(a) 3 + 1 + 3 + 2 + 4 + 3 + 1 + 3 = 20 and 20 \div 8 = 2.5: halfway between bike and car, which is no way to travel. Recode car as 1 and walk as 3 and the same answers read 1, 3, 1, 2, 4, 1, 3, 1, with sum 16 and average 16 \div 8 = 2. Same players, different average, so the average describes the codes, not the players. The variable is categorical.
(b) Count each category: walk 2, bike 1, car 4, bus 1. Car is the most common, and 4 of 8, or \displaystyle \frac{4}{8} = \frac{1}{2}, of the players come by car.
(c) The answers are 0, 1, 0, 0, 0, 0, 1, 0. Adding zeros and ones counts the ones, so the sum 2 is the number who walk, and \displaystyle 2 \div 8 = \frac{1}{4} is the fraction who walk. The variable is still categorical (walked or did not); this average is a count of one category in disguise, and it works only because the codes are exactly 0 and 1.
Boundaries
Money is counted in the smallest coin. Prices go up in whole cents, so strictly they are discrete, but they are usually handled like a continuous variable because the steps are so small.
Age depends on what is recorded. Age as time lived is measured, so continuous. Age in whole years counts birthdays passed, and many books call it discrete. Say which is meant.
A large count is often treated as continuous. The number of people in a town has gaps of 1 that are too small to matter, so it is often grouped like a measurement in a histogram.
Ordered categories are not amounts. Small, medium and large can be put in order, and first beats second, but the gap between neighboring categories is not an amount and need not be the same each time.
Where this goes next
The type of a variable is the first thing to settle in Choosing a display for a question. Categorical data go to Counting each group and ordering groups by how many, Data tables, tallies and frequency tables, Relative frequency tables and Bar graphs and pictographs. Numerical data go to Dot plots and Histograms, and then to center and spread, starting with the mean. Whether a question has answers that vary at all is settled in Statistical questions and variability.
Exercises
Categorical or numerical
- Olavi’s fruit stand records, for each customer: (a) the kind of fruit bought, (b) the number of pieces bought, (c) the length of the longest banana bought, in centimeters, (d) whether the customer brought a bag, (e) the receipt number. Sort each as categorical or numerical.
- Winnie’s dog show records, for each dog: (a) breed, (b) height at the shoulder in centimeters, (c) the number of shows entered this year, (d) the number on the owner’s armband, (e) coat color. Sort each.
- Ruben’s hockey team records, for each player: (a) position, (b) games played, (c) home postcode, (d) stick length in centimeters, (e) minutes on the ice in the last game. Sort each.
Discrete or continuous
- Say whether each is discrete or continuous: (a) the number of apples in a crate, (b) the mass of a crate, (c) the time a customer waits to be served, (d) the number of customers in an hour, (e) the length of a cucumber.
- Say whether each is discrete or continuous: (a) the number of puppies in a litter, (b) the height of the highest jump a dog clears, (c) the number of rosettes a dog has won, (d) the length of a dog’s tail.
- A customer buys from 2 to 5 melons. How many different values can the number of melons take? How many can the total mass take if it lies from 2 kg to 5 kg?
Does an average make sense?
- Five hockey players wear jerseys 9, 14, 3, 27 and 22 and have scored 2, 6, 1, 0 and 4 goals. Find the average of each list and say which one means something.
- Five watermelons weigh 4.5, 6, 5.5, 7 and 3.5 kg. Find their total mass and their average mass.
- Two dogs at the show wear armbands 214 and 274. Work out 274 - 214. Does the answer say anything about the dogs?
- Three dogs run the agility course with no faults in 31.4, 31.6 and 38.2 seconds, placing 1st, 2nd and 3rd. Find the time gap between 1st and 2nd and between 2nd and 3rd. What do the placings hide?
Recorded values
- A scale shows mass to the nearest 10 g, and a pear reads 160 g. What could its true mass be?
- A dog’s height is recorded to the nearest centimeter as 47 cm. What could its true height be?
- Watermelons are recorded to the nearest half kilogram. List the recorded values possible from 4 kg to 6 kg. Is mass recorded this way discrete?
Choosing a summary
- Ten customers buy: apple, plum, apple, pear, plum, apple, cherry, pear, apple, plum. (a) Count each fruit. (b) Which is most common? (c) What fraction of the customers bought apples?
- For ten dogs a steward records “Did it finish the course?”, coded 1 yes and 0 no: 1, 1, 0, 1, 1, 1, 0, 1, 1, 1. Find the average code and say what it means.
- Name a display that suits each variable from Exercise 2: (a) breed, (b) number of shows entered, (c) height at the shoulder.
Explaining
- Explain why phone numbers are categorical even though they are written with digits.
- A punnet label reads “24 strawberries, 250 g”. Explain why the first number is discrete and the second continuous, though both are whole numbers.
- Explain why a mass recorded to the nearest whole kilogram is still continuous.
- Bananas can be recorded by length in centimeters or sorted as short, medium or long. Explain what the first record allows that the second does not.
- Explain why the average of codes 1 for yes and 0 for no means something, when the average of jersey numbers does not, and why the yes-or-no variable is still categorical.
Answers
- (a) Categorical. (b) Numerical: it counts. (c) Numerical: it measures. (d) Categorical: yes or no. (e) Categorical, if counted at all: a tag naming one sale; an average receipt number is not an amount.
- (a) Categorical. (b) Numerical. (c) Numerical. (d) Categorical: a tag naming one entry. (e) Categorical.
- (a) Categorical. (b) Numerical. (c) Categorical: a label for an area. (d) Numerical. (e) Numerical.
- (a) Discrete. (b) Continuous. (c) Continuous. (d) Discrete. (e) Continuous.
- (a) Discrete. (b) Continuous. (c) Discrete. (d) Continuous: a length is measured.
- The count can be 2, 3, 4 or 5: 5 - 2 + 1 = 4 values. The mass can take any value from 2 kg to 5 kg, so there is no end to the possible values.
- Jerseys: 9 + 14 + 3 + 27 + 22 = 75 and 75 \div 5 = 15, which is meaningless. Goals: 2 + 6 + 1 + 0 + 4 = 13 and 13 \div 5 = 2.6 goals a player, which means something.
- 4.5 + 6 + 5.5 + 7 + 3.5 = 26.5 kg in total, and 26.5 \div 5 = 5.3 kg on average.
- 274 - 214 = 60, but 60 is not 60 of anything: not kilograms, not years, not points. An armband number names an entry, so the difference says nothing about the dogs.
- 31.6 - 31.4 = 0.2 s and 38.2 - 31.6 = 6.6 s. The places are one step apart each time, but the gaps in time are very different.
- At least 160 - 5 = 155 g and less than 160 + 5 = 165 g.
- At least 47 - 0.5 = 46.5 cm and less than 47 + 0.5 = 47.5 cm.
- 4, 4.5, 5, 5.5, 6: five values. No: mass is still continuous; only the records have gaps.
- (a) Apple 4, plum 3, pear 2, cherry 1, total 10. (b) Apple. (c) \displaystyle \frac{4}{10} = \frac{2}{5}.
- The sum is 8, so the average is \displaystyle 8 \div 10 = \frac{4}{5}: four fifths of the dogs finished.
- (a) A bar graph. (b) A dot plot. (c) A dot plot, or a histogram for many dogs.
- A phone number picks out one phone; it counts and measures nothing. Adding two or averaging many gives no amount, so it names a group of one and is categorical.
- 24 counts whole strawberries, so it can only be a whole number. 250 g is a mass rounded for the label; the true mass could be 250.3 g or any value near it.
- The true mass can be any amount; the record only rounds it. Two masses that both read 3 kg can still differ, so the variable has no gaps.
- Lengths can be ordered exactly, added and averaged. Groups can only be counted, and two bananas in one group may differ by several centimeters that the record no longer shows.
- Adding zeros and ones counts the ones, so the average is the fraction who said yes. Jersey numbers are arbitrary, so their sum counts nothing. The variable still names a group, yes or no; only these codes make its average a fraction of the whole.