0.1 Measurement Scales & Variable Types - JulTob/Data GitHub Wiki

0.1 Measurement Scales & Variable Types

Purpose: choose the right summaries and charts by naming what your data is.

1) Variable families (what the thing is)

  • Categorical or Cualitative
    • Nominal (no order): color, country, user_id (identifier, not a “category” for averaging).
    • Ordinal (order, uneven steps): low/med/high, Likert 1–5.
  • Numeric
    • Interval (equal steps, no true zero): °C, dates.
    • Ratio (equal steps, true zero): length, income, counts.
    • Boolean: Logic (True/False)
  • Specials: datetime, text, geospatial, images.

2) What you may do (legitimate operations)

Scale Allowed ops (examples) Typical stats Typical visuals
Nominal =, ≠, mode, counts Mode, frequency % Bar chart, stacked bars
Ordinal order comparisons (<, >), median Median, percentiles Ordered bars, dot plot
Interval +/−, mean differences Mean, SD, z-scores Line (time), histogram
Ratio ×/÷, geometric mean, CV Mean, SD, ratios, rates Histogram, box plot, scatter

Heuristic: position > length > angle/area > color for quantitative precision.

3) Common pitfalls (and fixes)

  • IDs as categories: never average an identifier; use for joins/keys only.
  • Ordinal ≠ Interval: a 4 isn’t “twice” a 2 on a Likert scale; report medians/quantiles.
  • Unit traps: °C is interval (no true zero) → ratios like “30°C is 2× 15°C” are invalid; Kelvin is ratio.
  • Implicit missingness: “0” might mean “unknown”; encode NaN/NA explicitly.
  • Re-encoding danger: integer-coding categories does not make them numeric.

4) Mapping to pandas (practical handles)

Concept pandas dtype / tool Note
Nominal category / string Memory-friendly categories.
Ordinal CategoricalDtype(ordered=True) Define order explicitly.
Interval float64, datetime64[ns] Beware time zones.
Ratio int64 / float64 Keep units in column name.
Binary bool Encode missing as pd.BooleanDtype().
Datetime to_datetime, dt accessor Store as UTC internally.
Geo geopandas.GeoDataFrame (geometry) Track CRS; don’t mix.

5) Mini-checklist (before any analysis)

  1. Name each column’s scale (nominal/ordinal/interval/ratio).
  2. Set dtype accordingly (categories ordered where needed).
  3. Write the unit and missingness policy.
  4. Choose summaries & charts that the scale permits.

Scale → Valid Statistics & Plots: Decision Table

Scale Permitted comparisons / operations Safe descriptive stats Bad/misleading stats to avoid Recommended plots
Nominal equality / membership counts, proportions, mode mean, standard deviation, correlations bar charts (counts / proportions), mosaic
Ordinal order, ranking, percentiles median, percentiles, rank‑based mean on raw codes, linear regressions ordered bar, box / violin by group (on ranks)
Interval differences meaningful (no absolute zero) mean, standard deviation, z‑scores ratios (e.g. “twice as big”) histogram, KDE, line plot
Ratio full arithmetic ( + − × ÷ ) mean, geometric mean (if >0), CV (still avoid mixing types blindly) histogram (possibly log scale), scatter

Rule of thumb: If your data is non‑numeric or has arbitrary codes, treat as nominal/ordinal — don’t compute mean or Pearson correlations until it's truly interval/ratio.