Skip to main content
Back to module
Statistics Fundamentals · Describing Data

Types of data and variables

Reading16mLesson 1 of 3 in this module

What you'll learn

  • Classify variables and choose summaries
  • Tell nominal and ordinal categorical variables apart
  • Tell discrete and continuous numerical variables apart
  • Recognise numbers used as codes and avoid averaging them

Classify variables as categorical or numerical and choose the summary that fits each type.

Why this matters

Every statistical question starts with the same step: look at a column of data and decide what kind of thing it holds. That decision controls everything after it. You can average a column of temperatures, but you cannot average a column of blood types. A chart that works for counts of product categories looks wrong for weights. Analysts, lab technicians and engineers make this call dozens of times a day, usually without noticing. This lesson makes it explicit so you make it correctly.

Observations and variables

A dataset is usually a table. Each row is one observation (one patient, one sample, one bridge inspection, one website visit). Each column is a variable: something you measured or recorded about every observation.

sample_idmaterialbatch_gradetensile_mpadefects
S-01steelA412.50
S-02aluminiumB276.02
S-03steelA405.11

sample_id is a label, not something to analyse. The other four columns are four different kinds of variable.

Categorical variables

A categorical (qualitative) variable puts each observation in a group.

  • Nominal: groups with no natural order. material (steel, aluminium), blood type, country, browser name.
  • Ordinal: groups with a meaningful order but no fixed distance between them. batch_grade (A better than B better than C), survey answers from "strongly disagree" to "strongly agree", pain on a 1 to 5 scale.

Useful summaries for categorical data are counts, proportions (percent of the total) and the mode (the most common group). For ordinal data the median also makes sense, because you can line the answers up in order and find the middle one.

A common trap: numbers used as codes. A ZIP code, a phone number, an employee ID or a "region 1, 2, 3" column is categorical even though it is written with digits. The test is simple: would an average mean anything? The average ZIP code is nonsense, so ZIP code is categorical.

Numerical variables

A numerical (quantitative) variable is a measured or counted amount, where arithmetic makes sense.

  • Discrete: counts that come in whole steps. defects (0, 1, 2...), number of support tickets, number of colonies on a plate.
  • Continuous: measurements that can take any value in a range, limited only by the instrument. tensile_mpa, temperature, time, concentration, mass.

For numerical data you can use the mean, median, standard deviation, range and percentiles, and charts like histograms and box plots. The next lesson covers those in detail.

Interval and ratio (a finer split)

Some textbooks split numerical data again:

  • Interval: differences are meaningful but zero is arbitrary. Temperature in Celsius: 20 °C is not "twice as hot" as 10 °C.
  • Ratio: there is a true zero, so ratios make sense. Mass, length, Kelvin temperature, money. 20 kg really is twice 10 kg.

You rarely need this distinction in day-to-day work, but it explains why "percent increase" is fine for revenue and misleading for Celsius.

Choosing a summary: a quick table

variable typeexamplecentrespreadchart
nominalmaterialmodecounts per groupbar chart
ordinalbatch grademedian, moderange of gradesordered bar chart
discretedefectsmean, medianstandard deviation, rangebar chart or histogram
continuoustensile strengthmean, medianstandard deviation, IQRhistogram, box plot

Worked example: a clinic visit log

A clinic records visit_reason (checkup, injury, illness), satisfaction (1 to 5 stars), wait_minutes and prescriptions (how many were written).

  • visit_reason is nominal: report "45% checkups, 30% illness, 25% injury".
  • satisfaction is ordinal: report the median (say 4 stars) and the share of 1 and 2 star ratings. A mean of 3.7 stars is often reported anyway, but be aware it assumes the gap between 1 and 2 stars equals the gap between 4 and 5.
  • wait_minutes is continuous: report the median wait and the spread.
  • prescriptions is discrete: the mean (1.4 per visit) is fine, even though no single visit had 1.4.

How software sees types

Spreadsheets and Python do not know what your data means. A column of ZIP codes is stored as numbers, so the software will happily average it. In Python's statistics module, mean works on any list of numbers, and mode works on any list of hashable values, including text:

Python
import statistics

materials = ["steel", "aluminium", "steel", "steel"]
print(statistics.mode(materials))   # steel

defects = [0, 2, 1, 0, 3]
print(statistics.mean(defects))     # 1.2

The software runs whatever you ask. Choosing the right summary is your job.

Common mistakes

  • Averaging codes (IDs, ZIP codes, category numbers).
  • Treating ordinal scales as if the steps were equal without saying so.
  • Turning a continuous variable into categories ("old" vs "young") too early, which throws information away.
  • Forgetting that the same quantity can be recorded at different levels: age in years is numerical, age group "18 to 24" is ordinal.

Quick recap

  • Rows are observations; columns are variables.
  • Categorical: nominal (no order) or ordinal (ordered). Summarise with counts, proportions, mode (and median for ordinal).
  • Numerical: discrete (counts) or continuous (measurements). Summarise with mean, median, standard deviation and percentiles.
  • Ask "would an average mean anything?" before you compute one.

Try it

Open the Do tab and classify the variables in the quiz.

Key terms (6)

variable
A column in a dataset: something measured or recorded about every observation.
Nominal
A categorical variable whose groups have no natural order, such as material or blood type.
Ordinal
A categorical variable whose groups have a meaningful order but no fixed distance between them, such as a 1 to 5 rating.
Discrete
A numerical variable made of counts that come in whole steps, such as the number of defects.
Continuous
A numerical variable that can take any value in a range, limited only by the instrument, such as mass or time.
mode
The most common value or group in a dataset.

Recap

  • Rows are observations and columns are variables.
  • Categorical variables are nominal (no order) or ordinal (ordered); summarise them with counts, proportions and the mode, plus the median for ordinal.
  • Numerical variables are discrete (counts) or continuous (measurements); summarise them with mean, median, standard deviation and percentiles.
  • Numbers used as codes, such as ZIP codes, are categorical.
  • Ask "would an average mean anything?" before computing one.
Also in this lesson: