Statistics and probability
Mean, median and deviation, counting and classical probability — what a figure in a report really says, and how likely something actually is.
Topics in this branch
Why this branch is worth learning
Every topic here settles a real situation. One example from each lesson:
- Planning the commuteTen timed runs to the office: 25, 26, 26, 27, 28, 28, 29, 30, 31 and 90 minutes, the last one thanks to a crash on the ring road. The mean is 340 : 10 = 34 minutes, the median (28 + 28) : 2 = 28. The median says what an ordinary morning costs; the mean smears one accident thinly across nine normal days. You leave by the median and keep a separate margin for the day that goes wrong, instead of budgeting six extra minutes every morning for something that happened once.
- Choosing a courierTwo firms deliver a parcel in 3 days on average. The first: 2, 3, 3, 3, 4 days — variance (1 + 0 + 0 + 0 + 1) : 5 = 0.4, deviation 0.63 of a day. The second: 1, 1, 3, 5, 5 days — variance 16 : 5 = 3.2, deviation 1.79. A present that has to arrive on a given day goes with the first, even though the price list and the advert quote the very same average for both.
- A chart in the newspaperA story about a poll shows two bars, 42 and 46 per cent, on a vertical axis starting at 40. The drawn heights are 2 and 6 units, so the leader’s bar is three times taller. The true ratio is 46 : 42, a lead of 9.5 per cent of the value — the drawing overstates it more than thirtyfold. One glance at the number at the bottom of the axis settles whether the picture can be trusted.
- How strong a password isA four-digit PIN is 10⁴ = 10,000 possibilities — a phone locks after three attempts, but a stolen database of such codes falls in a fraction of a second. Eight lower-case letters give 26⁸ ≈ 209 billion combinations, and eight characters drawn from 62 (lower case, upper case, digits) give 62⁸ ≈ 218 trillion, over a thousand times as many. Every character you add multiplies that count by the size of the alphabet rather than adding to it.
- A lottery ticketSix numbers out of 49 make C(49, 6) = 13,983,816 equally possible tickets, so P(jackpot) = 1 : 13,983,816 ≈ 0.0000072%. One ticket a week for 50 years is 2,600 draws, and the chance of ever hitting it — taken through the opposite event, 1 minus the probability of 2,600 misses — comes to about 0.019%, fewer than two chances in ten thousand. That number is nowhere on the slip.
- Reading a screening resultA test detects the disease in 99 of every 100 patients who have it and misfires on 2 of every 100 who do not, while 1 person in 100 is actually ill. A positive result reaches 0.01 · 0.99 = 0.0099 of the ill and 0.99 · 0.02 = 0.0198 of the healthy, so 2.97 per cent of everyone tested. The probability of being ill after a positive result is 0.0099 / 0.0297 — exactly one third, not 99 per cent. That is why a positive screening result is always repeated with a confirmatory test.
- Inspecting a batch of goodsFrom a batch in which 5 per cent of units are faulty, a storekeeper pulls 10 for inspection. The probability that none of them turns out faulty is 0.95 to the tenth power, that is 0.599 — so almost 40 per cent of such inspections catch at least one defect. Had 20 per cent been faulty, a sample of ten would pass the batch only 11 per cent of the time, and that is the whole mathematics behind choosing a sample size.
- A lottery ticketA ticket costs 5. The top prize of 1000 comes up with probability 1/2000 and a consolation 50 with probability 1/200. The expected payout is 1000/2000 + 50/200 = 0.50 + 0.25 = 0.75, so the player’s expected result is 0.75 − 5 = −4.25 per ticket. A hundred tickets a year means an expected loss of 425, and no run of luck changes that — it only changes when it shows.
- Overbooking a flightAn airline sells 210 tickets for 200 seats because a passenger shows up with probability 0.95. The number who show up is binomial with E(X) = 210 · 0.95 = 199.5 and variance 210 · 0.95 · 0.05 = 9.975, that is a standard deviation of 3.16 passengers. On average half a seat stays free, but a spread of three passengers means overbooking happens on a sizeable share of flights — and that is the number the airline is knowingly buying.
- Manufacturing toleranceA filling machine puts an average of 500 g into a packet with a standard deviation of 2 g. The three-sigma rule says 99.7 per cent of packets fall between 494 and 506 g. If the standard allows a 5 g deviation, that is 2.5 sigmas, then 1.24 per cent of production falls outside tolerance — at 20,000 packets a day that is 248 units to reject, and that is the number a decision to recalibrate rests on.
- A poll with a margin of errorA pollster surveys 1067 people and reports 34 per cent support "with a margin of error of 3 percentage points". That number is not a convention: at the worst possible spread of answers the standard error is √(0.25/1067) ≈ 0.0153, and the margin at a 95 per cent confidence level is 1.96 · 0.0153 ≈ 0.030, i.e. 3.0 points. The confidence interval therefore runs from 31 to 37 per cent — and it is the interval, not the single number, that is the result of the poll.
- An A/B testVariant A converts at 4.0 per cent. Variant B gets 2500 views and converts 120 times, that is 4.8 per cent. Under the hypothesis that nothing changed, the standard error is √(0.04 · 0.96 / 2500) ≈ 0.0039, so z = (0.048 − 0.040)/0.0039 ≈ 2.04. That clears 1.96, so at α = 0.05 the null hypothesis is rejected — but only just, and the rollout decision should say so.
- Flat price against floor areaSixty transactions in one district give the line ŷ = 9.2x + 45, where x is the floor area in square metres and ŷ the price in thousands. The model values a 50-square-metre flat at 9.2 · 50 + 45 = 505 thousand. The coefficient of determination is 0.78, so floor area explains 78 per cent of the variation in price — the other 22 per cent is the floor, the condition, the aspect, and how much of a hurry the seller was in.
Branch formulas
Branch: Statistics and probability
Mean, median and mode
Arithmetic mean
the sum of all the data divided by how many there are
Total from the mean
this is how a missing value is recovered when the mean is known
Median — an odd sample
once sorted, it is exactly the middle number
Median — an even sample
the mean of the two middle values
Mode
the number that occurs most often — there may be none at all
Weighted mean
every value counts as many times as its weight says
Variance and deviation
Range
the simplest measure of spread — it looks only at the two extremes
Deviation from the mean
the deviations always sum to zero, which is why they cannot be averaged as they are
Variance
the mean of the squared deviations from the mean
Standard deviation
the square root of the variance — back in the units of the data
Shortcut formula
the mean of the squares minus the square of the mean — quicker to compute
Sample variance
divisor n − 1, when the data is a sample drawn from a larger population
Presenting data
Total of the frequencies
the table check: class counts must add up to the sample size
Relative frequency
the class's share; times 100 it is a percentage
Angle of a pie slice
a full circle is 360°, so the angle is the share in degrees
Histogram class width
k — the number of classes; the range of the variance lesson cut into equal pieces
Frequency density
the bar height for UNEQUAL classes — not the count itself
Apparent ratio on a truncated axis
c — where the axis starts; at c = 0 it collapses to x_B / x_A
Combinatorics
Rule of product
a choice made in several independent steps — multiply the counts
Factorial
the product of the first n naturals; 0! equals 1 by definition
Permutations
the number of orderings of all n items
Arrangements without repetition
choose k out of n, order matters, nothing repeats
Arrangements with repetition
k times over, we choose from the same n options
Combinations
choose k out of n, order does NOT matter
Symmetry of combinations
choosing k items is the same as discarding the other n − k
Pascal's rule
every entry of the triangle is the sum of the two above it
The binomial theorem
the coefficients of the expansion are row n of Pascal's triangle
Classical probability
Classical probability
favourable outcomes over the number of all possible ones
Range of a probability
never below 0 and never above 1
Impossible and certain events
edge cases of the definition, not results of a computation
Complementary event
counting "not A" is often easier than counting A
As a percentage
the same probability expressed in percent
Independent events
multiply the probabilities — only when one does not affect the other
Conditional probability
Conditional probability
defined only for P(B) > 0
Multiplication rule
the definition times P(B)
Counting form
when the outcomes are equally likely
Law of total probability
A₁, …, Aₙ split Ω into disjoint cases
Bayes’ theorem
reverses the condition: P(B|A) into P(A|B)
Independence
the condition changes nothing about A
Trees and the Bernoulli scheme
Multiplying along a branch
the probability of one path of the tree
Adding across paths
an event is a set of paths, so they add
Union of events
the overlap is counted twice, so subtracted once
Disjoint events
nothing to subtract
Bernoulli scheme
k successes in n independent trials
At least one success
through the complement, with no summing
Random variables
Random variable
a function attaching a number to an outcome
Distribution
a table of values and their probabilities
Expected value
a mean weighted by probabilities
Variance of a variable
mean squared deviation from E(X)
Computational form
one pass over the table instead of two
Standard deviation
in the same unit as X
Distribution function
non-decreasing, from 0 to 1
Linear transformation
a shift does not change the spread
Binomial and Poisson
Binomial distribution
the formula derived in the Bernoulli lesson
Expected value
trials times the chance of success
Variance
largest at p = 1/2
At least one success
through the complement
Poisson distribution
rare events in a fixed window
Poisson parameters
one number describes the whole distribution
The limiting passage
n large, p small, the product fixed
The normal distribution
The normal density
the area under the whole curve is 1
Notation
μ shifts the curve, σ widens it
Standardisation
how many deviations x lies from the mean
The standard distribution
one distribution instead of an infinite family
The one-sigma rule
two thirds of the population
The three-sigma rule
beyond three sigmas lie 3 cases in 1000
Central limit theorem
a sample mean tends to a normal distribution
Normal approximation
usable once np(1 − p) ≥ 10
Estimation and confidence intervals
Point estimator of the mean
one number computed from the sample
An unbiased estimator
it does not err systematically — it errs at random
Sample variance
the n − 1 divisor is the correction for unbiasedness
Standard error of the mean
the spread of the MEAN, not of the data
Confidence interval for a mean
z = 1.64 · 1.96 · 2.58 for 90 · 95 · 99 per cent
Margin of error
half the width of the interval
Required sample size
the same formula read from the d end
Hypothesis testing
Null and alternative hypothesis
H₀ always carries the equality — that is the computable one
Test statistic for a mean
how many standard errors the sample sits from the hypothesis
Decision rule (two-sided test)
z_{α/2} = 1.96 for α = 0.05
The p-value
the probability of SUCH DATA given H₀ — not of H₀ given the data
Type I error
a false alarm; fixed in advance
Type II error
missing an effect that is really there
Power of a test
the chance of detecting an effect that exists
Correlation and regression
Sum of products of deviations
positive when the deviations lean the same way
Pearson correlation coefficient
always between −1 and 1; no units
Least-squares line
the line always passes through the point (x̄, ȳ)
Fitted value
the model’s prediction at a given x
Residuals
it is their squares the method minimises
Coefficient of determination
the fraction of the variation in y the model explains
Significance test for a correlation
t distribution with n − 2 degrees of freedom
