Lesson 2 - Variables and Measurement Scales

Welcome to Variables and Measurement Scales

Before you compute a single average, you have to answer a quieter question: what kind of data is this? A column of species names and a column of body masses are both just values in a table, but only one of them has a meaningful mean. Knowing the difference is what keeps you from calculating the “average island” — a number that looks fine and means nothing.

In this lesson you will classify every column of the penguins dataset by hand and in Python, learn the four measurement scales that statisticians use to sort variables, and see exactly which summaries and operations each scale allows.

By the end of this lesson, you will be able to:

  • Separate quantitative from qualitative variables, and discrete from continuous ones
  • Define the four measurement scales — nominal, ordinal, interval, and ratio
  • Classify every column in a real dataset by its scale
  • Choose the statistics and operations that a given scale actually permits

You only need a little Python and pandas. Let’s begin.


Quantitative and Qualitative Variables

A variable is any characteristic you can measure or record that varies from one observation to the next — a penguin’s species, its body mass, the island it lives on. The first cut you make is between two broad families.

A quantitative variable records a numeric amount you can do arithmetic on: body mass in grams, flipper length in millimetres. A qualitative variable (also called categorical) records a label or category: species, island, sex. You can count how often each label appears, but adding or averaging them is meaningless.

A tree: Variable branches into Quantitative (numbers), which splits into Discrete (counts) and Continuous (body_mass_g), and Qualitative/Categorical, which splits into Nominal (species) and Ordinal (light<med<heavy).
Every variable is quantitative or qualitative; quantitative splits into discrete and continuous, qualitative into nominal and ordinal.

Load the dataset and let pandas tell you how it read each column:

import pandas as pd

penguins = pd.read_csv("https://datatweets.com/datasets/penguins.csv")
print(penguins.dtypes)
species                  str
island                   str
bill_length_mm       float64
bill_depth_mm        float64
flipper_length_mm    float64
body_mass_g          float64
sex                      str
dtype: object

The data types line up with the split: species, island, and sex came in as text (str) — those are qualitative. The four measurement columns came in as numbers (float64) — those are quantitative. The dtype is a useful first hint, but it is only a hint. A column of postal codes is stored as numbers yet is purely categorical, so you still have to think about what the values mean, not just how they are stored.

Discrete and continuous

Quantitative variables split again. A discrete variable can only take separated values you can count — the number of eggs in a nest, the number of penguins on an island. A continuous variable can take any value in a range, limited only by how precisely you measure — body mass, bill length.

All four numeric columns here are continuous: a penguin could in principle weigh 3750.0 g or 3750.4 g, with no gaps in between. We only see whole-gram values because that is the precision the field team recorded, not because mass jumps in steps.


The Four Measurement Scales

Quantitative-vs-qualitative is a useful first pass, but it is too coarse. Two qualitative columns can behave very differently — species has no natural order, while a column of T-shirt sizes clearly does. To capture this, statisticians use four measurement scales, from least to most informative: nominal, ordinal, interval, and ratio. Each scale adds something the one before it could not do, and each unlocks a few more valid operations.

A four-step ascending staircase: Nominal (labels only), Ordinal (+ order), Interval (+ equal gaps, no true zero), Ratio (+ true zero), each with a short example.
The four scales form a ladder: each step keeps everything below it and adds one new permission — order, then equal gaps, then a true zero.

Nominal: labels with no order

A nominal scale holds named categories with no inherent order. You can check whether two values are equal or different, count how often each appears, and find the mode (the most common value) — and that is all. Averaging or ranking nominal values is undefined.

In the penguins data, species, island, and sex are all nominal. Adelie is not “more” or “less” than Gentoo; they are simply different. The right summary is a count of each category:

print(penguins["species"].value_counts())
species
Adelie       152
Gentoo       124
Chinstrap     68
Name: count, dtype: int64

That tells you the dataset is mostly Adelie, with Chinstrap the rarest. The mode is Adelie. Notice what you cannot sensibly ask: there is no “average species” and no “second-largest minus smallest,” because the categories have no numeric value and no order.

Ordinal: ordered categories, uneven gaps

An ordinal scale holds categories that do have a meaningful order, but where the distance between them is not defined or not uniform. Think of survey answers like “poor < fair < good < excellent.” You know good ranks above fair, but you cannot say it is exactly one unit better, or twice as good. Because order is meaningful, ordinal data permits the median and percentiles, not just the mode — but still not the mean.

None of the penguin columns is ordinal as it stands, so let’s create one by binning body mass into ordered size classes. We cut at the lower and upper quartiles (3550 g and 4750 g), so the lightest quarter becomes light, the middle half medium, and the heaviest quarter heavy:

penguins["mass_class"] = pd.cut(
    penguins["body_mass_g"],
    bins=[0, 3550, 4750, 7000],
    labels=["light", "medium", "heavy"],
)
print(penguins[["body_mass_g", "mass_class"]].head())
   body_mass_g mass_class
0       3750.0     medium
1       3800.0     medium
2       3250.0      light
3          NaN        NaN
4       3450.0      light

Because we passed ordered labels, pandas records the ranking, and you can compare classes directly:

print(penguins["mass_class"].cat.ordered)
print(penguins["mass_class"].value_counts(sort=False))
True
mass_class
light      89
medium    168
heavy      85
Name: count, dtype: int64

heavy outranks light — that comparison is valid, which is exactly what makes the variable ordinal. But the gaps are not uniform: light spans every mass from 2700 g up to 3550 g, while heavy covers 4750 g all the way to 6300 g. The category labels carry order, yet they have thrown away the real distances, so “heavy minus light” is not a number you can compute. That missing, uniform distance is the line between ordinal and the next scale up.

Interval: even gaps, no true zero

An interval scale has ordered values with equal, meaningful distances between them — but its zero point is arbitrary, chosen by convention rather than marking “none of the thing.” The classic example is temperature in degrees Celsius. The gap from 10 °C to 20 °C is the same size as the gap from 20 °C to 30 °C, so differences are meaningful and you can take the mean. But 0 °C does not mean “no temperature”; it is just the freezing point of water. Because the zero is arbitrary, ratios break: 20 °C is not “twice as hot” as 10 °C.

No penguin column is on an interval scale — all the measurements have a true zero. We use the temperature example precisely because it isolates the one feature interval scales lack.

Ratio: even gaps and a true zero

A ratio scale has everything interval has — order and equal intervals — plus a true, meaningful zero that marks the genuine absence of the quantity. That true zero is what makes ratios valid: you can say one value is twice or half another.

All four penguin measurements are ratio variables. A body mass of 0 g would mean no mass at all, so the zero is real, and ratios make sense:

print(penguins["body_mass_g"].describe())
count     342.000000
mean     4201.754386
std       801.954536
min      2700.000000
25%      3550.000000
50%      4050.000000
75%      4750.000000
max      6300.000000
Name: body_mass_g, dtype: float64

describe() happily reports the mean, standard deviation, and quartiles, because every one of those is valid on a ratio scale. (Note that count is 342, not 344 — describe() ignores the two penguins with no recorded mass.) The heaviest penguin weighs 6300 g and the lightest 2700 g; on a ratio scale you can also say a 6300 g bird is exactly twice as heavy as a 3150 g one, because 6300/3150=2 6300 / 3150 = 2 and the zero is real. Try that with Celsius and you get nonsense — which is the whole point of keeping interval and ratio apart.

Interval vs. ratio in one line

Both scales let you compute a mean, because both have equal intervals. Only ratio lets you form ratios (“twice as heavy”), because only ratio has a true zero. Temperature in °C is interval; body mass, length, and counts are ratio.


Classifying Every Column

With the four scales in hand, you can label every column in the dataset. The rule of thumb: ask whether the values have order, whether the gaps are equal, and whether zero means “none.”

ColumnTypeScaleWhy
speciesqualitativenominalNamed categories, no order
islandqualitativenominalNamed categories, no order
sexqualitativenominalTwo unordered categories
bill_length_mmquantitative, continuousratio0 mm = no length; true zero
bill_depth_mmquantitative, continuousratio0 mm = no depth; true zero
flipper_length_mmquantitative, continuousratio0 mm = no length; true zero
body_mass_gquantitative, continuousratio0 g = no mass; true zero

Every qualitative column here is nominal, and every quantitative column is ratio, because each measures a physical amount with a genuine zero. The mass_class column we built earlier is the one ordinal variable in play, created on purpose to show the middle of the scale ladder.

The figure below shows that ordinal column. Notice the bars sit in a fixed, meaningful order — light, then medium, then heavy — even though we never used their numeric values to draw them:

Bar chart of penguin counts in three ordered body-mass classes: light 89, medium 168, heavy 85.
Penguins grouped into ordered mass classes. The order (light < medium < heavy) is meaningful, but the gaps behind the labels are not equal, which is what makes the variable ordinal rather than ratio.

What Each Scale Lets You Do

The reason any of this matters is practical: the scale tells you which statistics and operations are valid. Use one the scale forbids and you get a number that compiles but misleads.

  • Nominal — equality checks, counts, the mode. No order, no mean, no median.
  • Ordinal — everything nominal allows, plus order comparisons, the median, and percentiles. Still no mean, because gaps are uneven.
  • Interval — everything ordinal allows, plus addition, subtraction, and the mean and standard deviation. No ratios, because zero is arbitrary.
  • Ratio — everything interval allows, plus multiplication and division, so statements like “twice as heavy” are valid.

Each step up the ladder adds a permission; it never takes one away. So the safe move is always to summarize a variable at its own scale, never above it. The mean is perfect for body_mass_g and meaningless for species.

The ‘average island’ trap

If you encode island as 1, 2, 3 to feed it into a model and then average those codes, you will get a number like 1.7 — the “average island.” It is arithmetic on a nominal variable, and it means nothing. Always match the statistic to the scale, not to whatever happens to be stored as a number.


Practice Exercises

Exercise 1: Classify a new column

Suppose the dataset also recorded each penguin’s age in completed years (0, 1, 2, …). Is this variable quantitative or qualitative? Discrete or continuous? Which measurement scale does it sit on, and does a value of 0 carry a true-zero meaning?

Hint

Ask the three scale questions in order: do the values have order, are the gaps between consecutive ages equal, and does 0 mean “no age at all”? Counting whole years gives you a clue about discrete vs continuous.

Exercise 2: Summarize each column at its scale

For species (nominal) print the mode and the full value_counts. For flipper_length_mm (ratio) print the mean and median. Then explain why running .mean() on species would be invalid.

Hint

The mode is penguins["species"].mode()[0]. The mean and median of flipper length are penguins["flipper_length_mm"].mean() and .median(). A mean needs equal numeric intervals, which nominal categories do not have.

Exercise 3: Build your own ordinal variable

Bin flipper_length_mm into three ordered classes — short, medium, long — with pd.cut(..., labels=[...]). Confirm the result is ordered with .cat.ordered, then show its counts. Why can you take the median of these classes but not their mean?

Hint

Pick cut points that split flipper length sensibly, e.g. bins=[0, 190, 210, 250], and pass ordered labels=["short", "medium", "long"]. The median only needs order, which pd.cut preserves; the mean needs equal gaps, which the labels discard.


Summary

You learned to ask the first question of any analysis: what kind of variable is this? Variables are quantitative (numeric amounts) or qualitative (categories), and quantitative ones are further discrete (countable) or continuous (any value in a range). The sharper tool is the four measurement scalesnominal, ordinal, interval, ratio — each adding one new permission. In the penguins data, species, island, and sex are nominal, the four measurements are ratio, and binning body mass produced an ordinal variable whose order is real but whose gaps are not. The scale, not the storage type, decides which statistics and operations are valid.

Key Concepts

  • Variable — a characteristic that varies across observations.
  • Quantitative vs qualitative — numeric amount vs category label.
  • Discrete vs continuous — countable separated values vs any value in a range.
  • Nominal — unordered categories; only counts and the mode.
  • Ordinal — ordered categories with uneven gaps; adds the median and percentiles.
  • Interval — equal gaps but arbitrary zero; adds the mean, but no ratios.
  • Ratio — equal gaps and a true zero; adds multiplication, so “twice as much” is valid.

Why This Matters

Every analysis and every model you build rests on treating each column correctly. Average a set of category codes, fit a linear model to an ordinal survey answer, or claim one interval value is “twice” another, and the math will run without complaint while quietly producing a wrong conclusion. Reading a variable’s measurement scale first is the cheap habit that keeps the rest of your statistics honest.


Next Steps

Continue to Lesson 3 - Frequency Distributions

Turn raw columns into frequency tables and see how often each value or range actually occurs.

Back to Module Overview

Return to the Statistics Fundamentals module overview


Continue Building Your Skills

You can now look at any column and know what it is allowed to tell you — which summaries are honest and which are nonsense dressed as numbers. Next you will take that grounding and start describing a single variable in full, counting how its values are distributed so its shape comes into view.