Skip to content

0.2 Choosing Summaries & Visuals

Julio Toboso edited this page Oct 21, 2025 · 3 revisions

Statistical hygiene

Once you’ve declared a variable’s measurement scale (nominal, ordinal, interval, ratio), the next step is: only use statistic or plot types valid for that scale. Below is a compact guide.

Scale Allowed summaries / metrics Allowed visualizations Not allowed / misuse to avoid
Nominal counts, proportions, mode bar chart, pie (small categories) mean, standard deviation, histogram (meaningless)
Ordinal median, rank correlations (e.g. Spearman) bar chart (ordered), boxplot of ranks arithmetic mean (unless evenly spaced), variance with caution
Interval mean, standard deviation, differences histogram, density plot, boxplot true “zero‑based” ratios (only differences meaningful)
Ratio all interval metrics + meaningful ratios same as interval + log scales if needed none in the standard sense (all metrics valid)

Procedure:

  1. For each variable, annotate its scale (in data dictionary or schema).
  2. When choosing a summary or statistic, refer back to this table.
  3. For visualizations, match type to permissible plots above.
  4. If you ever see code taking a mean of a nominal code (e.g. 0/1 categories), flag for correction.
# Example: binary treatment (nominal) → use proportion & bar, not mean code:
import pandas as pd
df = pd.DataFrame({"group": ["A","B","A","B","A","A","B"], "outcome": [0,1,0,1,0,1,1]})
counts = df.groupby("group")["outcome"].value_counts(normalize=True).unstack(fill_value=0)
print(counts)
counts.plot(kind="bar", stacked=True)

You can also encode nominal codes as pd.Categorical (unordered) so that accidental numeric ops error out.

3) Where it goes

Page: 0.1 Measurement Scales & Variable Types
Section: After the definitions / examples of nominal, ordinal, interval, ratio — insert a new subheading “0.2 From Scales → Choosing Summaries & Visuals (Statistical hygiene)”


4) Micro‑exercises (with brief answers)

  1. Variable “color of car” (red/blue/green) → what summary metric and plot do you choose?
    Answer: counts / proportions; bar chart (categorical); not mean or histogram.

  2. Variable “customer satisfaction” rated 1–5, with ordinal scale → is taking the mean valid?
    Answer: only if you assume equal spacing; safer to use median, rank correlation, or treat it as ordinal in box/rank plots.

  3. You see code df["gender_code"].mean() where gender_code is encoded 0 = male, 1 = female. What’s wrong and what to replace?
    Answer: Taking a mean of nominal binary is meaningless — instead compute proportion df["gender_code"].mean() is okay but only if clearly documented and interpreted as proportion; better: treat as nominal and show counts/proportions with bar chart.


5) Expand Path (optional)

Next pages / sections to build:

  • 1. Probability → as earlier patch suggested: events, conditional, Bayes, total probability.
  • 2. Descriptive Statistics → deeper: variance, covariance, quantiles; tie to scale table above.
  • 3. Visualization → mapping plot types to data shapes and objectives (e.g. scatter, line, faceting).
  • 4. Data Cleaning / Type Enforcement → enforcing categorical dtype, safe coercion, missingness policies.
  • 5. Inference / Hypothesis Testing → building on probability + descriptive foundations.

That single inserted “scale → summary/plot” guide will reduce many future misapplications, and anchor all downstream choices to sound foundations.

Micro‑exercises:

  • Q1: A variable “browser type” (Chrome, Firefox, Safari) — what summary metric and plot should you use?
    A1: counts or proportions; bar chart. (Not mean or histogram of codes.)
  • Q2: A satisfaction rating 1‑5 (ordinal) — is it always valid to compute the mean?
    A2: No — only if spacing is truly equal and you treat it as interval; safer: median or percentiles.
  • Q3: A variable “time since signup (in days)” (ratio) — what summaries/plots are valid?
    A3: mean, sd, ratios (e.g., twice as long), histogram, density plot; log scale if heavy tail.

Data

Legend:

  • 🔰 Start here
  • 🏵️ Important Insight
  • ⚙️ Technical and applications
  • 💻 Some Code
  • ⚜️ Advanced Topics

Start

01 · Ω — What could happen

02 · X, 𝒳 — What we observe

03 · p(x) — What we expected

04 · I(x), H(X) — What an observation tells us

05 · Data — What is consistent

06 · Statistics — What we can learn.

07 · Databases - How to store data

08 · μ(x) — Fuzzy - When data is flexible

  • 08.1 Fuzzy Logic (planned)
  • 08.2 Fuzzy Numbers (planned)
  • 08.3 Possibility vs Probability (planned)

09 · x(t) — Signals and systems - Where patterns live

  • 09.1 Signals (stub)
  • 09.2 Sampling and Aliasing (planned)
  • 09.3 Convolution (planned)
  • 09.4 Frequency (planned)

10 · f_θ — Modelling and linear algebra

  • 10.1 🔰 Vectors and Matrices (planned)
  • 10.2 Mathematical Modelling (planned)

11 · min L(θ) — Optimisation

  • 11.1 🔰 Derivatives (planned)
  • 11.2 Convex Optimisation (planned)

12 · Learning from data

13 · Cause, design, capstone

  • 13.1 Cause and Effect (planned)
  • 13.2 Capstone Guide (planned)

Appendix

Clone this wiki locally