Contents/ Part I · Foundations/ Chapter 7

Math Refresher for Statistics

You don't need to be a mathematician to do statistics, but a handful of ideas show up again and again. This chapter refreshes exactly that handful and ties each one straight to what's ahead. No fear required.

⏱️ ~13 min read
🐍 Notebook included
📊 Chapter 7

Statistics is built on a small, friendly set of math tools. Master this handful and every formula in this book becomes readable. Treat this chapter as a cheat sheet with explanations: skim what you know, lean on what you don't.

🧰
The toolkit: summation, sets, counting, logarithms, a little calculus, and the linear algebra of data. Each one quietly powers a major part of statistics and machine learning.
1

Summation: the Σ Symbol

That big Greek Σ (sigma) scares people, but it just means "add them all up." Σxᵢ says: take every value x₁, x₂, …, xₙ and sum them.

x̄ = (1/n) · Σ xᵢ   ←   the mean is just "add them up, divide by how many"

Once you read Σ as a loop that adds, the scariest-looking formulas, mean, variance, regression, turn out to be simple bookkeeping. Its cousin Π (pi) means "multiply them all" and appears in probability.

🧮
The one Σ pitfall everyone hits

Σxᵢ² (square each value, then add) is not the same as (Σxᵢ)² (add first, then square). For [1, 2, 3]: Σxᵢ² = 1+4+9 = 14, but (Σxᵢ)² = 6² = 36. This exact distinction lives inside the variance formula. Two handy rules: Σ(c·xᵢ) = c·Σxᵢ and Σ(xᵢ + yᵢ) = Σxᵢ + Σyᵢ.

2

Order of Operations & Factorials

Two small things that cause most arithmetic slips in statistics formulas:

🔢

Order of operations (PEMDAS)

Parentheses → Exponents → Multiply/Divide → Add/Subtract. A formula like (x − μ)² / n only works if you do the parentheses and the square first.

Factorials

n! means n × (n−1) × … × 1, so 4! = 24. By definition 0! = 1. Factorials are the engine inside permutations and combinations.

3

Sets & Venn Diagrams

A set is just a collection of distinct things. In probability, an event is a set of outcomes, so these operations become the rules of probability:

A only A ∩ B "A and B" B only A B

Union ∪

A ∪ B = everything in A or B (or both).

Intersection ∩

A ∩ B = only what's in both A and B.

Complement Aᶜ

Everything not in A, the basis of "P(not A) = 1 − P(A)".

4

Counting: Permutations & Combinations

Probability often comes down to counting possibilities. The one question to ask: does order matter?

PPermutations

Order matters. Arrangements, 1st/2nd/3rd place, passwords, seating.

  • Formula: P(n,r) = n! / (n−r)!
  • "How many ways to arrange r of n?"
CCombinations

Order doesn't matter. Selections, teams, lottery numbers, committees.

  • Formula: C(n,r) = n! / (r!·(n−r)!)
  • "How many ways to choose r of n?"
🎰
Why your lottery ticket rarely wins

Choosing 6 numbers from 49 gives C(49,6) = 13,983,816 combinations, so the odds are about 1 in 14 million. Counting makes the (un)likelihood concrete.

5

Logarithms & Exponents

A logarithm answers "what power do I raise the base to?" Since 2¹⁰ = 1024, we have log₂(1024) = 10. Two superpowers make logs essential in statistics:

✖️➡️➕

Products become sums

log(a·b) = log(a) + log(b). This is why we maximize log-likelihood, turning a huge product of probabilities into a friendly sum.

📉

Huge ranges become readable

A log scale squeezes 1, 10, 1,000, 1,000,000 into even steps, taming exponential growth on a chart.

🔢
Which "log"? Watch the base

"log" is ambiguous: log₁₀ (pH, decibels, log-axis charts), ln = base e (growth and likelihoods, and what most stats software means by "log"), and log₂ (information and entropy, measured in bits). Logs are only defined for positive numbers.

6

A Pinch of Calculus

You won't be solving integrals by hand here, but two ideas matter enormously:

dThe derivative = slope

How fast something changes. A slope of zero marks a peak or valley.

  • Models "learn" by following slopes downhill (gradient descent)
  • Minimizing error = finding where the slope is zero
The integral = area

The area under a curve.

  • Probability = area under a continuous distribution's curve
  • (For discrete data it's a sum, not an integral)
  • The total area (or sum) over all outcomes is exactly 1
🔑
The one to remember

Derivatives power optimization (how every machine-learning model trains), and integrals power probability (areas under curves). That's calculus's whole job in this book.

7

Linear Algebra: the Math of Data

Open any dataset and you'll see a grid of numbers, rows and columns. That grid is a matrix, and a single row or column is a vector:

rows = records columns = features height weight 17070 16055 18082 X =

Why bother? Because linear algebra lets the computer operate on a whole table at once, averaging a column, combining features, or running a regression, without slow loops. Every model in this book ultimately speaks in matrices.

Bonus vocabulary you'll meet later: eigenvalues and eigenvectors capture a matrix's "main directions", the engine behind PCA and dimensionality reduction (see Unsupervised Learning).

🐍

Bring it to life in Python

The companion notebook runs all six tools, summation vs. NumPy, set operations with a Venn, lottery odds, log scales, a baby gradient descent, and data as a matrix.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, matplotlib and launch jupyter notebook.

🎓 Key Takeaways

  • Σ (summation) means "add them all up", the heart of the mean, variance, and beyond.
  • Sets (∪ "or", ∩ "and", complement) are the language of probability events.
  • Permutations vs. combinations: order matters vs. order doesn't.
  • Logarithms turn products into sums and tame huge ranges.
  • Calculus: derivatives drive optimization (model training); integrals give probability (area under curves).
  • Linear algebra: your data is a matrix, so the computer can crunch it all at once.
8

Practice Challenges

Five short challenges, one per math area. Beginner-to-intermediate; try them on paper or in Python.

1

Summation · Add and average

For x = [3, 7, 2, 8], compute Σxᵢ and then the mean (1/n)·Σxᵢ.

Hint: sum first, then divide by how many values there are.
2

Sets · Union & intersection

Let A = {1,2,3,4} and B = {3,4,5,6}. Find A∪B, A∩B, and the size of the union.

Hint: ∪ is "everything in either"; ∩ is "only what's in both".
3

Counting · Permutation or combination?

(a) How many ways can 4 runners finish 1st/2nd/3rd? (b) How many 3-person teams can you form from 4 people?

Hint: podium order matters (permutation); a team doesn't (combination).
4

Logarithms · Products into sums

Show that log(8 × 32) = log(8) + log(32). Then find log₂(1024).

Hint: for log₂, ask "2 to what power equals 1024?"
5

Calculus & matrices · Slope & column mean

(a) For f(x) = (x−5)² with derivative 2(x−5), find the slope at x=2 and say which way is downhill. (b) Find the mean of each column of [[2,10],[4,20],[6,30]].

Hint: a negative slope means downhill is to the right.
Check your work

A fully-worked solutions notebook walks through all five challenges in the same visual style, try them yourself first, then compare.

📓 View Solutions ▶ Open Solutions in Colab ⬇ View / Download on GitHub
9

Quiz: Test Yourself

Eight quick questions across the math toolkit. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.