01-01: Statistics Basics and Data Types¶
Statistics is the science of collecting, organizing, summarizing, analyzing, and drawing conclusions from data. Before any formula appears, you have to know what kind of thing you are measuring — because the type of data decides which summary and which test is even legal.
Population vs. Sample¶
| Term | Meaning | Example |
|---|---|---|
| Population | The entire collection of individuals or objects of interest | All 2.1 million registered voters in a country |
| Sample | A subset of the population actually observed | The 1,200 voters called in a poll |
| Census | A study that measures the whole population | The national population count |
| Parameter | A numerical summary of a population — usually unknown | True mean income μ of all households |
| Statistic | A numerical summary of a sample — computed from data | Sample mean income x̄ of 500 households |
Tip
Remember the mnemonic: Population → Parameter, Sample → Statistic.
Standard notation — you will see these symbols for the rest of the course:
| Quantity | Population (parameter) | Sample (statistic) |
|---|---|---|
| Size | N |
n |
| Mean | μ (mu) |
x̄ (x-bar) |
| Standard deviation | σ (sigma) |
s |
| Variance | σ² |
s² |
| Proportion | p |
p̂ (p-hat) |
| Correlation | ρ (rho) |
r |
Descriptive vs. Inferential Statistics¶
Descriptive statistics organize and summarize the data you actually have — tables, graphs, averages, spreads. No claim beyond the data set.
"The 40 students in this class averaged 78.5 on the midterm."
Inferential statistics use a sample to make a statement about the wider population, always with a stated level of uncertainty — confidence intervals and hypothesis tests.
"Based on 40 students, we are 95% confident the mean score for all sections is between 75.1 and 81.9."
Chapters 01–04 of this course are descriptive. Chapters 05–07 build the probability machinery. Chapters 08–13 are inferential.
Qualitative vs. Quantitative Data¶
Data
├── Qualitative (categorical) — labels / categories, no arithmetic meaning
│ e.g. eye color, blood type, zip code, "yes / no", brand
└── Quantitative (numerical) — counts or measurements, arithmetic is meaningful
├── Discrete — countable, gaps between values (0, 1, 2, …)
│ e.g. number of children, cars sold, defects per batch
└── Continuous — any value in an interval, limited only by the instrument
e.g. height, weight, time, temperature
Trap: a number is not automatically quantitative. Zip codes, jersey numbers, and "1 = male, 2 = female" codes are qualitative data stored as numbers. Averaging them is meaningless.
Discrete or continuous? Ask "can it, in principle, take a value halfway between two neighboring outcomes?" Number of phone calls: no → discrete. Call duration: yes → continuous.
The Four Levels of Measurement¶
Each level supports everything the levels above it support, plus one more operation.
| Level | Categories? | Ordered? | Meaningful differences? | True zero? | Examples | Valid center |
|---|---|---|---|---|---|---|
| Nominal | ✅ | ❌ | ❌ | ❌ | Gender, blood type, city, marital status | Mode only |
| Ordinal | ✅ | ✅ | ❌ | ❌ | Letter grades, satisfaction (poor→excellent), military rank | Mode, median |
| Interval | ✅ | ✅ | ✅ | ❌ | Temperature °C/°F, calendar years, IQ score | Mode, median, mean |
| Ratio | ✅ | ✅ | ✅ | ✅ | Height, weight, income, age, time, counts | All, plus ratios |
The "true zero" test: 0 °C does not mean "no temperature", so 40 °C is not twice as hot as 20 °C — that is interval. $0 income does mean "no income", so $40,000 is twice $20,000 — that is ratio.
Note
Level of measurement is the gatekeeper for the whole course. A chi-square test needs nominal/ordinal counts (Chapter 12). A t-test needs interval or ratio data (Chapter 11). Pearson correlation needs two interval/ratio variables (Chapter 13). Match the tool to the level and half the "which test do I use?" problem disappears.
Worked Example¶
A hospital records the following for each patient admitted.
| Variable | Qualitative / Quantitative | Discrete / Continuous | Level |
|---|---|---|---|
| Patient ID | Qualitative | — | Nominal |
| Blood type (A, B, AB, O) | Qualitative | — | Nominal |
| Pain rating (1–10 scale) | Qualitative (ordered) | — | Ordinal |
| Body temperature (°F) | Quantitative | Continuous | Interval |
| Number of prior admissions | Quantitative | Discrete | Ratio |
| Weight (kg) | Quantitative | Continuous | Ratio |
| Length of stay (days) | Quantitative | Continuous | Ratio |
Excel¶
Excel does not "know" a variable's level — you enforce it by how you store and validate the column.
' Force a nominal column to accept only valid categories:
' Data ▸ Data Validation ▸ Allow: List ▸ Source: A,B,AB,O
' Count categories (works for qualitative data)
=COUNTIF($B$2:$B$101, "O") ' how many O blood types
=COUNTA($B$2:$B$101) ' non-empty count
' Distinct category list (Excel 365)
=UNIQUE($B$2:$B$101)
=COUNTA(UNIQUE($B$2:$B$101)) ' number of distinct categories
' Quantitative summaries — only legal for interval/ratio columns
=COUNT($E$2:$E$101) ' counts numbers only
=AVERAGE($E$2:$E$101)
' Guard: is this column numeric?
=SUMPRODUCT(--ISNUMBER($E$2:$E$101)) ' how many cells are truly numeric
R¶
R encodes measurement level directly in the data type — this is one of the reasons R is the reference tool for statistics.
# Nominal -> unordered factor
blood <- factor(c("O", "A", "AB", "O", "B"),
levels = c("A", "B", "AB", "O"))
levels(blood) # "A" "B" "AB" "O"
table(blood) # frequency of each category
# Ordinal -> ordered factor (comparisons become legal)
pain <- factor(c("low", "high", "medium", "low"),
levels = c("low", "medium", "high"),
ordered = TRUE)
pain > "low" # TRUE for medium and high
# Discrete quantitative -> integer
admissions <- c(0L, 2L, 1L, 5L)
# Continuous quantitative -> numeric (double)
weight <- c(72.4, 88.1, 65.0, 91.7)
class(blood) # "factor"
class(pain) # "ordered" "factor"
class(weight) # "numeric"
str(data.frame(blood, pain = pain[c(1,2,3,4)], weight))
R refuses to average a factor — a built-in guard against the most common beginner mistake:
Python¶
import pandas as pd
df = pd.DataFrame({
"patient_id": ["P01", "P02", "P03", "P04"],
"blood": ["O", "A", "AB", "O"],
"pain": ["low", "high", "medium", "low"],
"admissions": [0, 2, 1, 5],
"weight": [72.4, 88.1, 65.0, 91.7],
})
# Nominal -> unordered category
df["blood"] = df["blood"].astype("category")
# Ordinal -> ordered category
df["pain"] = pd.Categorical(df["pain"],
categories=["low", "medium", "high"],
ordered=True)
print(df.dtypes)
# patient_id object
# blood category
# pain category
# admissions int64
# weight float64
df["blood"].value_counts() # frequency of each category
df["pain"] > "low" # legal because the category is ordered
df[["admissions", "weight"]].mean() # only on quantitative columns
Quick Reference¶
| Task | Excel | R | Python |
|---|---|---|---|
| Category counts | COUNTIF / PivotTable |
table(x) |
s.value_counts() |
| Distinct categories | UNIQUE(range) |
levels(f) / unique(x) |
s.unique() |
| Declare nominal | Data Validation list | factor(x) |
astype("category") |
| Declare ordinal | — (convention only) | factor(x, ordered = TRUE) |
pd.Categorical(..., ordered=True) |
| Count numeric values | COUNT(range) |
sum(!is.na(x)) |
s.count() |
| Inspect structure | — | str(df) |
df.dtypes / df.info() |
Common Mistakes¶
- Averaging a nominal code (zip codes, "1 = male, 2 = female"). Compute a mode instead.
- Treating an ordinal scale as ratio ("satisfaction of 4 is twice as good as 2"). Spacing is not guaranteed equal.
- Calling temperature in °C ratio — it is interval, because 0 is an arbitrary reference point.
- Confusing a parameter with a statistic. You almost never observe a parameter directly; that is the whole reason Chapters 08–13 exist.
Exercises: 01-01: Exercises — Statistics Basics and Data Types