Design, probability and Bayes

Lecture 3 (statistical inference, probability rules, conditional probability, Bayes) and the second half of Lecture 4 (slides 18–47, which revisit conditional probability and Bayes with tree diagrams), rebuilt as one storyline: from sample to population, then the rules for reasoning about chance, then how new evidence updates a probability.

How to read this page. It builds on Describing data and feeds the distributions on Discrete random variables. Every card says which slides it came from, what to read first, and what uses it later.

Teal = explanation added by Claude, not on the slides. Amber = watch out. Dropdowns hide worked examples, practice questions, and their answers.

The road through the lectures

Side stops: correlation (needed later for regression), the symbol table, and Warner's randomised-response survey.

Lecture map: which slides each card covers

Part 1

From sample to population

The vocabulary of inference and study design. Mostly definition questions in the exam.

Statistical science: population, sample, parameter, statistic

Statistics uses a sample you can see to learn about a population you cannot. A parameter is a number describing the whole population; a statistic is the same recipe applied to the sample, and it is our estimate of the parameter.

Statistical science develops and applies methods for collecting, analysing and interpreting data. 1. Design: planning how to gather relevant data. 2. Description: summarising the data. 3. Inference: making evaluations, such as estimations and predictions, based on the data.

The population is the total set of subjects of interest. A sample is the set of subjects from the population for which data are available.

Example: what percentage of voters approve of the French President? There are over 40 million voters, but randomly sampling 1,000 of them gives an approval percentage that estimates the percentage among all voters.

Population: the entire group (all French voters). Parameter: the characteristic of the population we want (approval among all voters). Sample: the subset we collect data from (1,000 voters). Statistic (estimate): the measure derived from the sample (approval among the sampled voters). Key point: even a relatively small sample (100 or 1,000) can closely approximate the parameter of a population of 40 million.

Ideally the sample is chosen by simple random, stratified, systematic or cluster sampling, not convenience sampling (s20).

\(\mu,\ \sigma,\ p\)
population mean, SD, proportion: parameters, fixed and usually unknown
\(\bar x,\ s,\ \hat p\)
sample mean, SD, proportion: statistics, vary from sample to sample

Ask "whose number is it?" If it describes every subject of interest, it is a parameter. If it was computed from the subjects actually measured, it is a statistic. The same word "mean" can be either.

A company samples 50 employees per department. The 50 marketing scores represent a…

(a) population, (b) sample, (c) parameter, (d) statistic.

(b) sample: a subset of all marketing employees. Their average would be a statistic; the average over all marketing employees would be the parameter.

Explain parameter vs statistic with an example; is 62% in a poll of 1,200 a parameter?

A parameter is a fixed numerical summary of the whole population; a statistic is computed from a sample and changes from sample to sample. For the ten days of campus traffic (page 1): the mean traffic over all days of the year is a parameter \(\mu\); the sample mean of the ten recorded days, \(\bar x = 481\), is a statistic that estimates it. In the poll, 62% is \(\hat p\), a statistic; the share of all residents, \(p\), is the unknown parameter.

Study design: observe or intervene?

In an observational study you only watch what happens; in an experiment you assign the treatment yourself. Only the experiment can show cause and effect, because random assignment removes the other explanations.

Designs are fundamentally distinguished as nonexperimental or experimental.

Nonexperimental design: no treatments are administered. Descriptive when little is known about a phenomenon; explorative or explanatory when relationships between factors are explored or explained.

Experimental design: treatments are administered. Predictive when the study tests predictive questions to address effectiveness or possible cause-and-effect.

Examples: descriptive, a university surveys every engineering student about daily screen time, just to report the average. Explorative, researchers check existing records to see whether sleep hours seem related to GPA. Explanatory, analysts use hospital records to examine whether smoking history helps explain lung-cancer rates. Experimental, students are randomly assigned to spaced repetition vs cramming and their scores compared.

Random assignment fixes causation (the groups differ only by the treatment). Random sampling fixes generalisation (the sample looks like the population). One does not buy you the other: a perfectly randomised experiment on volunteers still only tells you about people like the volunteers.

Experiment or observational study? Office hours and grades; new fertiliser; two checkout designs; parks and obesity
  1. (a) Observational: you cannot assign students to attend office hours; use existing attendance and grade data (explorative).
  2. (b) Experiment: assign plots to the new or the standard fertiliser and compare yield; this is the only way to attribute the difference to the fertiliser.
  3. (c) Experiment: an A/B test randomly shows each visitor design A or B and compares completion rates.
  4. (d) Observational: cities already have their parks; compare obesity rates across them (explanatory), remembering other city differences could explain the pattern.
Students randomly assigned to Method A or B and compared: what kind of study?

(b) Experiment. The researcher assigns the treatment (the method).

App users score 8 points higher: why can't you conclude the app "increases" scores?

A university emails all students; of those who reply, 60 use a study app and 40 do not. Users average 8 points more.

  1. Observational: students chose whether to use the app. A plausible alternative: more motivated students both adopt the app and score higher.
  2. Problem 1, causation: the groups may differ in motivation, ability or study time. Fix: randomly assign app access to comparable groups.
  3. Problem 2, generalisation: voluntary repliers need not represent all students. Fix: a representative random sample with effort to reduce non-response.

Explanatory, response, independent, dependent, control

The response is the outcome you are trying to explain, and the explanatory variables are the ones you use to explain it. These are roles chosen by your question, not labels stuck to the variables.

Response variable (dependent, outcome): the variable whose value we are trying to predict or explain. Explanatory variable (independent, predictor): a variable used to explain or predict changes in the response. It is a role, not a fixed label: on a scatterplot the explanatory variable sits on the x-axis, the response on the y-axis, but the same variable can be a response in one study and explanatory in another.

Independent variable: deliberately changed or manipulated by the researcher to observe its effect (the study method, in the spaced-repetition experiment). Spot it by asking "what is the researcher changing or assigning?" That control over assignment makes cause-and-effect conclusions possible.

Dependent variable: the outcome measured to see whether it responds to the independent variable (the exam score). Ask "what result am I measuring?"

Control variable: held constant across all groups so it cannot distort the relationship (same exam, same study time, same room and time of day). An uncontrolled variable can become a confounding variable, an alternative explanation: if the cramming group got an easier exam, we could not tell whether the score difference came from the method or the exam.

Worked example (s10): a survey records exercise frequency, sleep, stress, diet, age and academic performance. Way 1: "what affects academic performance?" Response: performance; explanatory: the other five. Way 2: "what influences stress?" Response: stress; explanatory: the others, now including academic performance.

Describe two ways to pick a response variable among exercise, sleep, stress, diet, age, performance

Question 1: "what lifestyle factors affect academic performance?" Response: academic performance; explanatory: exercise, sleep, stress, diet, age. Question 2: "what influences stress?" Response: stress; explanatory: exercise, sleep, diet, age and academic performance. The research question decides the roles: whatever you want to predict is the response.

Experiment on whether fertiliser increases plant height: what is the response variable?

(b) Plant height: the outcome measured. Fertiliser amount is explanatory (independent); plant type and soil would be control variables.

Association vs correlation, and Pearson's r

Association means any kind of relationship between two variables. Correlation is one specific number, between −1 and +1, that measures how close two quantitative variables are to a straight line.

Association: any relationship (positive, negative or none) between two variables, regardless of type. Measured by chi-square, Cramér's V or odds ratios for categorical data, by correlation, regression or scatterplots for quantitative data. Examples: smoking and lung cancer; car colour and being stopped by police; ice-cream sales and temperature.

Correlation: a numerical measure (usually Pearson's \(r\)) of the strength and direction of a linear relationship between two quantitative variables. Range −1 to +1: +1 perfect positive, −1 perfect negative, 0 no linear correlation. Height and weight about +0.8; study hours and exam score about +0.6; temperature and hot-chocolate sales about −0.7.

\[ r = \frac{\sum (x_i - \bar x)(y_i - \bar y)}{\sqrt{\sum (x_i - \bar x)^2 \cdot \sum (y_i - \bar y)^2}} \]

The numerator captures how \(x\) and \(y\) move together; the denominator rescales it to fall between −1 and +1.

All correlations are associations, but not all associations are correlations.

\(\sum (x_i - \bar x)(y_i - \bar y)\)
positive when \(x\) and \(y\) are above (or below) their means together
\(\sum (x_i - \bar x)^2\)
sum of squares of \(x\); its square root scales the numerator

\(r\) measures straight-line association only. A perfect U-shaped relationship can have \(r = 0\). And a strong \(r\) is not causation: a lurking variable can drive both (review p22 ex5).

Recipe

  1. Means \(\bar x\), \(\bar y\).
  2. Deviations of each \(x\) and each \(y\).
  3. \[ S_{xy} = \sum (x_i - \bar x)(y_i - \bar y) \]
  4. \[ S_{xx} = \sum (x_i - \bar x)^2,\qquad S_{yy} = \sum (y_i - \bar y)^2 \]
  5. \[ r = \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}} \]
Hours studied vs exam score for 7 students
  1. \(x = 1, 2, \dots, 7\); \(y = 50, 55, 60, 65, 70, 75, 85\).
  2. \[ \bar x = 4,\qquad \bar y = \frac{460}{7} = 65.71 \]
  3. \[ S_{xy} = 155,\qquad S_{xx} = 28,\qquad S_{yy} = 871.43 \]
  4. \[ r = \frac{155}{\sqrt{28 \times 871.43}} = 0.99 \]
  5. An almost perfect positive linear relationship: the points sit close to the trend line.
Compute \(r\) for \(x = 1,2,3,4,5\), \(y = 2,4,5,4,5\); then interpret \(r = -0.85\) between TV hours and GPA
  1. \[ \bar x = 3,\qquad \bar y = 4 \]
  2. Products of deviations: \((-2)(-2), (-1)(0), (0)(1), (1)(0), (2)(1)\) sum to 6.
  3. \[ S_{xx} = 10,\qquad S_{yy} = 6 \]
  4. \[ r = \frac{6}{\sqrt{60}} = 0.77 \]
  5. \(r = -0.85\): a strong negative linear association. It does not prove TV lowers GPA; a lurking variable (less study time, say) could drive both.

Symbol clarification

Roman letters are for the sample you measured, Greek letters for the population or the theoretical model. Same idea, different data.

SymbolMeaningKind
\(S\) or \(s\)sample standard deviation, divided by \(n - 1\)sample statistic
\(\sigma\)standard deviation of the entire population, or of a theoretical distributionpopulation parameter
\(\bar X\)sample meansample statistic
\(\mu\)population or theoretical meanpopulation parameter

Putting it all together (s20): design → description → inference; a parameter describes the population and a statistic estimates it from a sample; nonexperimental studies observe, experimental studies assign; association is any relationship, correlation the specific linear measure; \(\bar x\) estimates \(\mu\) and \(s\) (divided by \(n - 1\)) estimates \(\sigma\).

Part 2

The rules of probability

Sample spaces, three axioms, and the complement, addition and multiplication rules every later formula is built from.

Two meanings of probability, and why statisticians need it

A probability is the fraction of times an outcome would happen if you repeated the experiment endlessly. People also use it for a degree of belief, the Bayesian reading, but this course mostly uses the first.

Frequentist definition: the probability of an outcome is the proportion of times it would occur in an indefinitely long sequence of like observations under the same conditions. A forecast of 0.20 means rain occurs on 20% of days with identical atmospheric conditions.

Subjective definition: the degree of belief that the outcome will occur, based on all the available information. Useful when no long run of identical trials exists (intelligent life elsewhere, a new business succeeding). This is the foundation of Bayesian statistics. With enough data the two usually converge.

A fair coin: \(P(\text{Heads}) = 0.5\), \(P(\text{Tails}) = 0.5\). Three heads in a row does not mean the coin always comes up heads. Kerrich, interned in Denmark in the 1940s, got 5,067 heads in 10,000 flips.

Why statisticians need probability: descriptive statistics summarise data we have; inferential statistics draw conclusions about a population from a sample, and every such conclusion carries uncertainty. Probability is the language for that uncertainty: it estimates how far a statistic is likely to fall from the true value, quantifies risk, and is the machinery behind hypothesis tests, confidence intervals and regression.

Sample space, events, complement, intersection, union

The sample space is the list of everything that could happen. An event is any part of that list, and "not A", "A and B", "A or B" are just ways of picking out other parts.

The sample space \(S\) is the set of all possible outcomes of a random experiment. An event \(A\) is any subset of the sample space.

One fair coin: \(S = \{H, T\}\), event "heads" \(= \{H\}\). One die: \(S = \{1, 2, 3, 4, 5, 6\}\), event "even" \(= \{2, 4, 6\}\).

Ask three people whether they support a government action (yes/no): \(S\) has 8 outcomes, from (yes, yes, yes) to (no, no, no). Event \(A\) = "all three give the same response" \(= \{(\text{yes,yes,yes}), (\text{no,no,no})\}\). Event \(B\) = "the first person says yes" has 4 outcomes.

The complement \(A^c\) (also \(\neg A\)) is every point of \(S\) not in \(A\). The intersection \(A \cap B\) (also \(AB\)) is the points in both; here \(A \cap B = \{(\text{yes,yes,yes})\}\). The union \(A \cup B\) is the points in \(A\) or in \(B\) or both; here 5 of the 8 outcomes.

\[ P(A \cup B) = \frac{2}{8} + \frac{4}{8} - \frac{1}{8} = \frac{5}{8} \]

Subtract the overlap, or YYY gets counted twice.

Venn diagram of the eight three-voter outcomes: circle B with YYN YNY YNN and YYY, circle A with YYY and NNN, and NYY NYN NNY outside both
L4 s21: union, intersection and complement drawn on the three-voter sample space.
\(A^c,\ \neg A\)
not \(A\)
\(A \cap B,\ AB,\ A \text{ and } B\)
both happen
\(A \cup B,\ A \text{ or } B\)
at least one happens

Equally likely outcomes and the three axioms

When every outcome is equally likely, a probability is just counting: favourable outcomes over all outcomes. The three axioms say probabilities are never negative, the whole sample space has probability one, and probabilities of non-overlapping events add.

Rule for equally likely outcomes: if a chance experiment has \(n\) equally likely outcomes,

\[ P(A) = \frac{\text{number of outcomes in } A}{n} \]

Coin: \(P(H) = 1/2\). Die: \(P(\text{even}) = 3/6 = 0.50\). This only works when outcomes are equally likely: 48.8% of newborns being girls is not an equally-likely situation, so broader rules are needed.

The three axioms (Kolmogorov, 1933). Every rule of probability follows from these:

\[ \text{1. Non-negativity:}\quad P(A) \ge 0 \] \[ \text{2. Normalisation:}\quad P(S) = 1 \] \[ \text{3. Additivity for disjoint events:}\quad P(A \cup B) = P(A) + P(B) \text{ if } A \cap B = \varnothing \]

Sanity check: every probability lies in \([0, 1]\), and a complete distribution sums to exactly 1.

P(head) on one fair toss; P(defective) when 10 of 1,000 items are defective
  1. \[ P(H) = \frac{1}{2} \]
  2. \[ P(\text{defective}) = \frac{10}{1000} = 0.01 \] (not 0.001, and "0.1%" would be 0.001).

The complement rule and "at least one"

The chance that something does not happen is one minus the chance that it does. The trick to remember: "at least one" is the opposite of "none", so compute "none" and subtract from one.

\[ P(A^c) = 1 - P(A) \]

Since \(P(S) = 1\) and \(A\), \(A^c\) split \(S\) with no overlap, their probabilities add to 1. In 2020 about 50,000 babies were born in Qatar and 48.8% were girls:

\[ P(\text{boy}) = 1 - 0.488 = 0.512 \]

Loaded coins: a coin that always comes up heads has \(P(H) = 1\), \(P(T) = 0\). With \(P(H) = 0.75\), \(P(T) = 1 - 0.75 = 0.25\). Probability law for coins: \(P(H) + P(T) = 1\).

Construction workers (s68): of 12,942 injured, Houston 219, Miami 112, Denver 140. Probability of a city other than those three:

\[ 1 - \frac{219 + 112 + 140}{12{,}942} = 1 - 0.0364 = 0.9636 \]

"At least one": find \(P(\text{none})\) first, then subtract from 1 (review catch-up).

At least one six in four rolls
  1. \[ P(\text{no six in 4 rolls}) = \left(\tfrac{5}{6}\right)^4 = 0.482 \]
  2. \[ P(\text{at least one six}) = 1 - 0.482 = 0.518 \]
One die: P(at least 4), P(more than 4), P(at most 4), P(fewer than 4), and the complement check
  1. At least 4: faces 4, 5, 6, so \(3/6 = 1/2\).
  2. More than 4: faces 5, 6, so \(2/6 = 1/3\).
  3. At most 4: faces 1 to 4, so \(4/6 = 2/3\).
  4. Fewer than 4: faces 1, 2, 3, so \(1/2\).
  5. The opposite of "at least 4" is "fewer than 4": \(1 - 3/6 = 1/2\) ✓. "At least 4" and "at most 4" are not opposites; both include 4.

Mutually exclusive events and the addition rule

To get the chance of "A or B", add the two chances, then take away the overlap so it is not counted twice. If the two events cannot happen together, there is no overlap to remove.

Two events are mutually exclusive if they cannot occur at the same time: they share no outcomes. Rolling a die, \(A = \{1, 6\}\) and \(B = \{2, 3\}\) can never both happen on one roll.

Addition rule, special case (valid only when mutually exclusive):

\[ P(A \text{ or } B) = P(A) + P(B) \] \[ P(1 \text{ or } 6) = \tfrac{1}{6} + \tfrac{1}{6} = \tfrac{1}{3} \]

General addition rule (any two events):

\[ P(A \text{ or } B) = P(A) + P(B) - P(A \text{ and } B) \]

Adding \(P(A)\) and \(P(B)\) counts the overlap twice, so subtract it once. One card from 52: \(A\) = King (4 cards), \(B\) = Heart (13 cards), the King of Hearts is in both:

\[ P(\text{King or Heart}) = \tfrac{4}{52} + \tfrac{13}{52} - \tfrac{1}{52} = \tfrac{16}{52} = 0.308 \]

Recipe: "A or B" from a table

  1. Make a two-way table and fill in the totals.
  2. \[ P(A) + P(B) \]
  3. Subtract the cell that is in both.
Parent or female at a school-board meeting
  1. 9 parents (5 female, 4 male) and 5 teachers (2 female, 3 male): 14 people, 7 female.
  2. \[ P(\text{parent}) + P(\text{female}) = \tfrac{9}{14} + \tfrac{7}{14} = \tfrac{16}{14} \]
  3. \[ \tfrac{16}{14} - \tfrac{5}{14} = \tfrac{11}{14} \] Without the subtraction the 5 female parents are counted twice (and the answer exceeds 1).
Neither red nor blond hair; three or more children
  1. 43 students: brown 15, black 10, blond 16, red 2. "Neither red nor blond" means brown or black:
  2. \[ \tfrac{15}{43} + \tfrac{10}{43} = \tfrac{25}{43} = 0.581 \]
  3. Families: 4% have three children, 2% four or more. Three or more:
  4. \[ 0.04 + 0.02 = 0.06 \]
100 students: 30 in maths, 70 in physics, 20 in neither. P(maths), P(physics), P(either), P(both)? And 60% maths, 40% physics, 25% both.
  1. \[ P(M) = 0.30,\qquad P(Ph) = 0.70 \]
  2. \[ P(M \cup Ph) = 1 - P(\text{neither}) = 1 - 0.20 = 0.80 \]
  3. \[ P(M \cap Ph) = P(M) + P(Ph) - P(M \cup Ph) = 0.30 + 0.70 - 0.80 = 0.20 \]
  4. Review version: \(P(M \cup P) = 0.60 + 0.40 - 0.25 = 0.75\); \(P(\text{neither}) = 0.25\).

Independent events and the multiplication rule

Two events are independent when knowing one happened tells you nothing about the other. Then the chance of both is simply the product of the two chances.

Two events are independent if knowing one occurs does not change the probability of the other. Multiplication rule (valid only when independent):

\[ P(A \text{ and } B) = P(A) \times P(B) \] \[ P(HH) = \tfrac{1}{2} \times \tfrac{1}{2} = \tfrac{1}{4} \]

Two dice: \(P(\text{both even}) = \tfrac{1}{2} \times \tfrac{1}{2} = \tfrac{1}{4}\).

Truth tables: two fair flips give HH, HT, TH, TT each with probability 0.25. A loaded coin with \(P(H) = 0.6\): HH 0.36, HT 0.24, TH 0.24, TT 0.16. All outcomes always add up to 1, so you can check your work.

Exactly one head in two fair flips: HT or TH, \(0.25 + 0.25 = 0.5\). Exactly one head in three fair flips: 8 cases each \(1/8\); only HTT, THT, TTH qualify, so \(3 \times 0.125 = 0.375\).

Across multiple flips, the probability of \(n\) heads is \(P(H)^n\), because the events are independent. For dependent events (rain tomorrow given rain today) these rules do not apply.

Mutually exclusive vs independent (s39): mutually exclusive is a question about outcomes (can \(A\) and \(B\) happen on the same trial? then \(P(A \cap B) = 0\)). Independent is a question about information (does knowing \(A\) change the chance of \(B\)? then \(P(A \cap B) = P(A)P(B)\)).

Drawing two balls from 5 red and 5 blue (L4 s26): with replacement the draws are independent, \(0.5 \times 0.5 = 0.25\); without replacement the second draw depends on the first, \(0.5 \times \tfrac{4}{9} = 0.22\).

If \(A\) and \(B\) cannot happen together and both have positive probability, then knowing \(A\) happened tells you \(B\) did not. That is maximal information, so they are dependent. Review p31 Q5: \(P(A) = 0.3\), \(P(B) = 0.4\), mutually exclusive, so \(P(A \cap B) = 0 \ne 0.12 = P(A)P(B)\): not independent.

Recipe: test independence from numbers

  1. Find \(P(A)\), \(P(B)\) and \(P(A \cap B)\) (from a table, a tree, or the question).
  2. \[ \text{Independent exactly when } P(A \cap B) = P(A)\,P(B) \]
  3. Equivalently, compare \(P(B \mid A)\) with \(P(B)\) (next card).
Traits A (0.3) and B (0.5) are inherited independently: P(both)?

\(0.3 \times 0.5 = 0.15\).

Two dice: A = "sum is 7", B = "first roll is 4". Independent?
  1. 36 equally likely pairs. Sum 7: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1), so \(P(A) = 6/36 = 1/6\).
  2. \[ P(B) = \tfrac{1}{6} \]
  3. \(A \cap B\) is the single pair (4, 3): \(P(A \cap B) = 1/36\).
  4. \[ P(A)\,P(B) = \tfrac{1}{6} \times \tfrac{1}{6} = \tfrac{1}{36} = P(A \cap B) \] Independent. (Knowing the first roll is 4 leaves exactly one way to reach 7, still a 1-in-6 chance.)
P(A) = 0.5, P(B) = 0.4, P(A ∩ B) = 0.2: independent? And can mutually exclusive A (0.3), B (0.4) be independent?
  1. \[ 0.5 \times 0.4 = 0.2 = P(A \cap B) \] Independent.
  2. Mutually exclusive gives \(P(A \cap B) = 0\), but independence would need \(0.3 \times 0.4 = 0.12\). Not independent.
Three fair flips, X = number of heads: P(at most 1), P(at least 2), P(exactly 2), and a student's error
  1. Eight equally likely sequences: 0 heads TTT (1), 1 head (3), 2 heads (3), 3 heads HHH (1).
  2. \[ P(X \le 1) = \tfrac{1}{8} + \tfrac{3}{8} = \tfrac{1}{2} \]
  3. \[ P(X \ge 2) = \tfrac{3}{8} + \tfrac{1}{8} = \tfrac{1}{2} \]
  4. \[ P(X = 2) = \tfrac{3}{8} \]
  5. "Four possible counts, so exactly 2 has probability 1/4" is wrong: the sequences are equally likely, the counts are not (three sequences give two heads, one gives zero).
Four independent attempts, each succeeds with 0.20: P(at least one), P(at least two), P(at most one)
  1. \[ P(X \ge 1) = 1 - 0.8^4 = 1 - 0.4096 = 0.5904 \]
  2. \[ P(X = 1) = 4 \times 0.2 \times 0.8^3 = 0.4096 \] (the one success can be in any of 4 positions)
  3. \[ P(X \ge 2) = 1 - (0.4096 + 0.4096) = 0.1808 \]
  4. \[ P(X \le 1) = 0.8192 \] the complement of the previous line.
  5. \(1 - P(X = 2)\) describes "anything except exactly two": it wrongly includes 0 and 1 and excludes 2.

Counting arrangements: factorials and "n choose k"

To find the chance of exactly k heads in n flips you need to count how many sequences have k heads. Factorials do that counting, and the result is the first factor of the binomial formula.

A factorial is the product of every whole number from 1 to the number before the exclamation mark: \(2! = 2\), \(3! = 6\), \(4! = 24\), \(5! = 5 \cdot 4 \cdot 3 \cdot 2 \cdot 1 = 120\).

\[ n! = n(n-1)(n-2)\cdots 1 \]

Five flips, exactly 1 head: HTTTT, THTTT, TTHTT, TTTHT, TTTTH, 5 outcomes. Exactly 2 heads: the first head can be in 5 positions and the second in 4, but that double counts each pair, so \(5 \cdot 4 / 2 = 10\). Exactly 3 heads: \(5 \cdot 4 \cdot 3 = 60\) placements, divided by the \(3 \cdot 2 \cdot 1 = 6\) duplicate orderings, gives 10.

Ten flips, 4 heads: \(10 \cdot 9 \cdot 8 \cdot 7 = 5{,}040\), divided by \(4 \cdot 3 \cdot 2 \cdot 1 = 24\), gives 210. So 210 of the \(2^{10} = 1{,}024\) outcomes have exactly 4 heads and 6 tails.

Number of ways to get \(k\) heads in \(n\) flips:

\[ \binom{n}{k} = \frac{n!}{(n-k)!\,k!} \]

Probability of one particular sequence with \(k\) heads and \(n - k\) tails:

\[ p^k (1-p)^{n-k} \]

Truth-table size for \(n\) flips is \(2^n\). Probability of exactly 1 head in 5 fair flips: \(5/2^5 = 0.15625\); exactly 3 heads: \(10/32 = 0.3125\). Loaded coin \(P(H) = 0.8\), three flips, exactly 1 head: each qualifying sequence has probability \(0.8 \times 0.2 \times 0.2 = 0.032\), and there are 3, so \(0.096\).

\(\binom{n}{k}\), \(C(n, k)\)
"n choose k": number of ways to place \(k\) successes among \(n\) trials
\(0!\)
defined as 1, so \(\binom{n}{0} = \binom{n}{n} = 1\)

\(\binom{n}{2} = n(n-1)/2\) and \(\binom{n}{1} = n\). For larger \(k\), cancel the bigger factorial: \(\binom{10}{4} = \frac{10 \cdot 9 \cdot 8 \cdot 7}{4 \cdot 3 \cdot 2 \cdot 1} = 210\). Also \(\binom{n}{k} = \binom{n}{n-k}\), so \(\binom{10}{6} = \binom{10}{4} = 210\).

\(36! \,/\, [(12 - 10)! \times 6!]\)
  1. \[ (12 - 10)! = 2! = 2,\qquad 6! = 720 \]
  2. \[ \text{denominator} = 2 \times 720 = 1{,}440 \]
  3. \[ 36! = 3.72 \times 10^{41} \]
  4. \[ \frac{3.72 \times 10^{41}}{1{,}440} = 2.58 \times 10^{38} \]
P(exactly 1 head in 5 fair flips), P(exactly 3 heads), and 4!
  1. \[ P(1 \text{ head}) = \frac{\binom{5}{1}}{2^5} = \frac{5}{32} = 0.15625 \]
  2. \[ P(3 \text{ heads}) = \frac{\binom{5}{3}}{2^5} = \frac{10}{32} = 0.3125 \]
  3. \[ 4! = 24 \]

Part 3

Conditional probability and Bayes

"Given that" changes the denominator. Bayes turns P(evidence | cause) into P(cause | evidence).

Conditional probability: restrict to what you know

"The probability of A given B" means: among the cases where B happened, what fraction also have A? You shrink the world to B and recount.

In real life events often depend on each other: the outcome of the first event affects the second (an early bird running at 5 am vs a night owl). A probability of an event \(A\), given that an event \(B\) occurred, is a conditional probability, denoted \(P(A \mid B)\):

\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)},\qquad P(B) \gt 0 \]

Placing \(P(B)\) in the denominator corresponds to conditioning on (restricting to) the sample points in \(B\); the numerator is the fraction of \(B\) that is also in \(A\). The denominator is always the "given" event.

General multiplication rule (L4 s26): the second factor is always conditional; independence just makes it equal \(P(B)\):

\[ P(A \text{ and } B) = P(A) \times P(B \mid A) \]

Test for independence: \(A\) and \(B\) are independent exactly when \(P(B \mid A) = P(B)\).

Sports-car buyers (s79): of 100 buyers, 40 bought an alarm, 30 bucket seats, 20 both. Given an alarm, probability of bucket seats:

\[ P(B \mid A) = \frac{0.2}{0.4} = 0.5 \]

Contingency table (s80): P(male and car) = 0.41, P(car) = 0.86:

\[ P(M \mid CO) = \frac{0.41}{0.86} = 0.477 \]

Language models (L5 s2–4) do the same thing: \(P(\text{next token} \mid \text{previous tokens})\). The context narrows the plausible outcomes, the model picks a token, adds it to the context, and repeats.

L3 s80 step 4 writes \(P(M \cap CO)/P(M)\) but divides by 0.86, which is \(P(CO)\). The division is right; the label is a typo. Always divide by the probability of the given event.

Recipe: "given that" from a two-way table

  1. Find the row or column of the given event; its total is the denominator.
  2. The cell where both events meet is the numerator.
  3. \[ P(A \mid B) = \frac{\text{cell}}{\text{total of } B} \]
500 sensors from two machines: five questions from the table
Machine AMachine BTotal
Defective12820
Non-defective288192480
Total300200500

(a) \(P(A)\), \(P(D)\). (b) \(P(A \cap D)\) directly, then verify \(P(A)\,P(D \mid A)\). (c) \(P(D \mid B)\), interpret. (d) Are A and D independent? (e) \(P(A \cup D)\).

  1. \[ P(A) = \tfrac{300}{500} = 0.6,\qquad P(D) = \tfrac{20}{500} = 0.04 \]
  2. \[ P(A \cap D) = \tfrac{12}{500} = 0.024 \]
  3. \[ P(A)\,P(D \mid A) = 0.6 \times \tfrac{12}{300} = 0.6 \times 0.04 = 0.024 \quad\checkmark \]
  4. \[ P(D \mid B) = \tfrac{8}{200} = 0.04 \] Four percent of Machine B's output is defective.
  5. \(P(D \mid A) = 0.04 = P(D)\), so knowing the machine does not change the defect rate: independent. (Check: \(P(A)P(D) = 0.024 = P(A \cap D)\).)
  6. \[ P(A \cup D) = 0.6 + 0.04 - 0.024 = 0.616 \]
200 engineers, 80 women, 30 of whom code in Python daily: P(Python | woman)?

\(30/80 = 0.375\). The given event (woman) sets the denominator to 80, not 200.

6 red, 5 blue, 4 green pens, two drawn without replacement: P(both red), P(one red and one green)
  1. 15 pens; the second draw is from 14.
  2. \[ P(R_1 \cap R_2) = \tfrac{6}{15} \times \tfrac{5}{14} = \tfrac{30}{210} = \tfrac{1}{7} = 0.143 \]
  3. Two mutually exclusive orders: \[ P(R \text{ then } G) = \tfrac{6}{15} \times \tfrac{4}{14} = \tfrac{24}{210} \]
  4. \[ P(G \text{ then } R) = \tfrac{4}{15} \times \tfrac{6}{14} = \tfrac{24}{210} \]
  5. \[ P(\text{one R, one G}) = \tfrac{48}{210} = \tfrac{8}{35} = 0.229 \]
  6. Check with combinations: \(\binom{6}{2}/\binom{15}{2} = 15/105 = 1/7\) and \(6 \times 4 / 105 = 8/35\).
8 modules, 3 faulty, draw two without replacement: exactly one faulty; both faulty given at least one; independent? mutually exclusive?
  1. \[ P(\text{exactly one}) = \tfrac{3}{8}\cdot\tfrac{5}{7} + \tfrac{5}{8}\cdot\tfrac{3}{7} = \tfrac{15}{28} = 0.536 \]
  2. \[ P(\text{at least one}) = 1 - \tfrac{5}{8}\cdot\tfrac{4}{7} = \tfrac{9}{14} \]
  3. \[ P(\text{both}) = \tfrac{3}{8}\cdot\tfrac{2}{7} = \tfrac{3}{28} \]
  4. \[ P(\text{both} \mid \text{at least one}) = \frac{3/28}{9/14} = \tfrac{1}{6} \]
  5. \(A\) = first faulty, \(B\) = second faulty: \(P(B \mid A) = 2/7 \ne 3/8 = P(B)\), so dependent. Not mutually exclusive: both can occur (probability 3/28).

"At least one is faulty" is not "the first one is faulty". Different conditions, different denominators.

2 red and 3 blue, draw two without replacement: P(at least one red), P(exactly one red)
  1. \[ P(X \ge 1) = 1 - P(\text{both blue}) = 1 - \tfrac{3}{5}\cdot\tfrac{2}{4} = \tfrac{7}{10} \]
  2. \[ P(X = 1) = \tfrac{2}{5}\cdot\tfrac{3}{4} + \tfrac{3}{5}\cdot\tfrac{2}{4} = \tfrac{6}{10} \]
  3. The difference, \(\tfrac{1}{10}\), is \(P(\text{both red}) = \tfrac{2}{5}\cdot\tfrac{1}{4}\).

The law of total probability: count people, not percentages

If an outcome can happen in two ways, through A or through not-A, add the two routes: each route is "chance of the cause times chance of the outcome given that cause". A tree diagram with a thousand people makes it concrete.

Cancer screening (L3 s73–76, L4 s27–32): \(P(C) = 0.1\) (10% of the population has cancer, \(P_0\)); sensitivity \(P(\text{Pos} \mid C) = 0.9\) (\(P_1\)); specificity \(P(\text{Neg} \mid \neg C) = 0.8\) (\(P_2\)). Hence \(P(\neg C) = 0.9\), \(P(\text{Neg} \mid C) = 0.1\), \(P(\text{Pos} \mid \neg C) = 0.2\).

\[ P(\text{Pos}) = P(\text{Pos} \mid C)\,P(C) + P(\text{Pos} \mid \neg C)\,P(\neg C) \] \[ P(\text{Pos}) = 0.9 \times 0.1 + 0.2 \times 0.9 = 0.09 + 0.18 = 0.27 \] \[ P(\text{Neg}) = 0.1 \times 0.1 + 0.8 \times 0.9 = 0.01 + 0.72 = 0.73 \]

Check: \(P(\text{Pos}) + P(\text{Neg}) = 1\). Truth table of the four cases: cancer and positive 0.09, cancer and negative 0.01, no cancer and positive 0.18, no cancer and negative 0.72.

Counting people: start with 1,000. 100 have cancer, of whom 90 test positive and 10 negative. 900 do not, of whom 180 test positive and 720 negative. Positives: \(90 + 180 = 270\). Of those 270, only 90 really have cancer: \(90/270 = 33\%\). The test catches 90% of cancers, so a positive result feels like 90%; it is not, because the 900 healthy people produce 180 false positives, twice the 90 true ones. When a disease is rare, false positives outnumber true ones.

Tree: 1000 people split into 100 with cancer (90 positive, 10 negative) and 900 without (180 positive, 720 negative); 90 of 270 positives have cancer
L4 s29: the same calculation as counts. Every box is a probability times 1,000.
Really has it (D)Does not (¬D)Read across the row
Test positive (+)true positivefalse positivepositive predictive value \(P(D \mid +)\)
Test negative (−)false negativetrue negativenegative predictive value \(P(\neg D \mid -)\)
Read down the columnsensitivity \(P(+ \mid D)\)specificity \(P(- \mid \neg D)\)

Sensitivity reads down a column: given the person is ill, does the test catch it? Predictive value reads across a row: given a positive result, is the person ill? They can be 90% and 33% for the same test.

Recipe: P(evidence) through a tree

  1. Branch 1: \(P(H) \times P(E \mid H)\).
  2. Branch 2: \(P(\neg H) \times P(E \mid \neg H)\).
  3. \[ P(E) = \text{branch 1} + \text{branch 2} \]
New line makes 60% of boards (90% pass), old line 40% (80% pass): P(a board passes)?
  1. \[ P(N \cap P) = 0.60 \times 0.90 = 0.54 \]
  2. \[ P(O \cap P) = 0.40 \times 0.80 = 0.32 \]
  3. \[ P(P) = 0.54 + 0.32 = 0.86 \]
Fault 0.02, alarm on 95% of faulty cycles and 10% of clean ones: P(alarm)? And P(defective) for two machines (60% at 2%, 40% at 5%)
  1. \[ P(A) = 0.95 \times 0.02 + 0.10 \times 0.98 = 0.019 + 0.098 = 0.117 \]
  2. \[ P(D) = 0.6 \times 0.02 + 0.4 \times 0.05 = 0.012 + 0.020 = 0.032 \]

Bayes' rule: update a prior with evidence

Bayes' rule flips a conditional probability around: from "how likely is this evidence if the hypothesis is true" to "how likely is the hypothesis now that I have seen the evidence". The base rate does most of the work, so a positive test for a rare disease still usually means no disease.

\[ P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)} \]

\(P(H \mid E)\): posterior, the updated probability of the hypothesis after the evidence; the answer you want. \(P(E \mid H)\): likelihood, how likely the evidence is if the hypothesis is true; usually given. \(P(H)\): prior, what you believed before, often the base rate in the population. \(P(E)\): marginal likelihood or evidence, the total probability of the evidence across all hypotheses; the total on the bottom.

Cancer with 1% prevalence, 90% sensitive, 90% specific (L4 s35, s39–40):

\[ P(+) = 0.9 \times 0.01 + 0.1 \times 0.99 = 0.108 \] \[ P(C \mid +) = \frac{0.9 \times 0.01}{0.108} = 0.083 \]

Follow 1,000 people: 10 have cancer, 9 test positive; 990 are healthy, 99 test positive; \(9/108 = 8\%\). A positive result multiplies the odds by about eight, but eight times a very small number is still small. Screening programmes retest rather than diagnose on one result.

Swapping the condition changes the answer completely (L4 s41): \(P(\text{positive} \mid \text{cancer}) = 90\%\) counts inside the 10 people with cancer; \(P(\text{cancer} \mid \text{positive}) = 8\%\) counts inside the 108 who tested positive. Same 9 people in the numerator, different denominator. Courtrooms slip the same way: "the chance of this DNA match if he were innocent is one in a million" is \(P(\text{match} \mid \text{innocent})\), not \(P(\text{innocent} \mid \text{match})\).

Spam (L4 s42–43): \(P(\text{spam}) = 0.2\), \(P(\text{"win"} \mid \text{spam}) = 0.7\), \(P(\text{"win"}) = 0.18\):

\[ P(\text{spam} \mid \text{"win"}) = \frac{0.7 \times 0.2}{0.18} = 0.78 \]

Medical diagnostics (L3 s87): 1% have the disease, 95% of them test positive, overall 5% test positive: posterior \(0.95 \times 0.01 / 0.05 = 0.19\). Fraud (L4 s44): \(P(F) = 0.01\), \(P(\text{unusual} \mid F) = 0.8\), \(P(\text{unusual}) = 0.05\): \(0.8 \times 0.01 / 0.05 = 0.16\).

Three steps whether diagnosing, filtering email or reading an A/B test: prior (what you believed), likelihood (how likely the evidence would be if true), posterior (what you believe now).

L3 s86 says the word "win" appears in 10% of all emails, and L4 s42 repeats "0.1" in the Evidence line but uses 18% in the bullet and divides by 0.18. The 0.1 is impossible: it would give a posterior of \(0.14/0.1 = 1.4\). Since 20% of mail is spam and 70% of spam says "win", \(P(\text{"win"})\) must be at least 0.14; the 0.18 (with 5% of legitimate mail saying "win") is the consistent value. Posterior 78%.

Recipe

  1. Name \(H\) (the cause you are asked about) and \(E\) (what was observed).
  2. Write down \(P(H)\), \(P(E \mid H)\), \(P(E \mid \neg H)\).
  3. \[ P(E) = P(E \mid H)\,P(H) + P(E \mid \neg H)\,P(\neg H) \] (skip if \(P(E)\) is given)
  4. \[ P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)} \]
  5. Check it lies in \([0, 1]\) and that \(P(H \mid E) + P(\neg H \mid E) = 1\).
1% have the disease, 95% sensitivity, 2% false positives: P(disease | positive)
  1. \[ P(+) = 0.95 \times 0.01 + 0.02 \times 0.99 = 0.0095 + 0.0198 = 0.0293 \]
  2. \[ P(D \mid +) = \frac{0.0095}{0.0293} = 0.324 \]
  3. About 32%: better than the 8% with a 10% false-positive rate, still far from the 95% people expect.
10% of components defective; test says "Fail" for 90% of defective and 10% of good ones. P(D | Fail)?
  1. \[ P(D) = 0.10,\qquad P(F \mid D) = 0.90,\qquad P(F \mid D') = 0.10 \]
  2. \[ P(F) = 0.90 \times 0.10 + 0.10 \times 0.90 = 0.09 + 0.09 = 0.18 \]
  3. \[ P(D \mid F) = \frac{0.90 \times 0.10}{0.18} = 0.5 \]
  4. A "Fail" is a coin toss: the component is equally likely to be defective or good, because the 10% false-fail rate on the 90% of good parts produces as many fails as the true defectives.
Given that a board passed inspection, P(it came from the new line)?
  1. From the previous card, \(P(N \cap P) = 0.54\) and \(P(P) = 0.86\).
  2. \[ P(N \mid P) = \frac{0.54}{0.86} = 0.628 \]
  3. Check: \(P(O \mid P) = 0.32/0.86 = 0.372\); the two add to 1.
P(F) = 1%, P(unusual | F) = 80%, P(unusual) = 5%: P(fraud | unusual pattern)?

\(0.8 \times 0.01 / 0.05 = 0.16\). An unusual pattern raises the fraud probability from 1% to 16%.

P(fault | alarm), why it is not 0.95, and what happens on a less reliable machine
  1. \[ P(D \mid A) = \frac{0.95 \times 0.02}{0.117} = \frac{19}{117} = 0.162 \]
  2. 0.95 is \(P(A \mid D)\), the reverse conditional. Per 1,000 cycles: 19 genuine-fault alarms and 98 false alarms; only 19 of 117 alarms are faults.
  3. More frequent faults with the same alarm rates: \(P(D \mid A)\) increases, because a larger share of alarms now comes from faulty cycles.
Machine A 60% of parts at 2% defective, B 40% at 5%: P(B | defective)?

\(P(D) = 0.032\) (previous card), \(P(B \cap D) = 0.4 \times 0.05 = 0.020\), so \(P(B \mid D) = 0.020/0.032 = 0.625\).

Case study: Warner's randomised response

To ask an embarrassing question honestly, let a coin decide whether each student answers the real question or a harmless one. No single "yes" can be pinned on anyone, yet the class total still reveals the true proportion.

What percentage of students have cheated in an exam? Students may be too embarrassed to answer truthfully. Each student tosses a coin twice. Tails on the first toss: answer Q1 "have you ever cheated on an exam in college?" Heads: answer Q2 "did you get tails on the second toss?" A "yes" can come from a cheater answering Q1 or from an honest student whose second toss was tails; the lecturer cannot tell which, so there is no reason to lie.

With \(\pi\) the proportion of cheaters:

\[ P(\text{yes}) = \tfrac{1}{2}\pi + \tfrac{1}{4} \] \[ \pi = 2\,P(\text{yes}) - \tfrac{1}{2} \]

In one survey 27 said yes and 30 said no:

\[ \hat\pi = 2 \times \frac{27}{57} - 0.5 = 2(0.474) - 0.5 = 0.45 \]

About 45% of the class had cheated, a number no direct question would have produced. Adding known randomness to each answer costs nothing at the group level, because you know exactly how much noise you added.

Total probability over the first toss: half the students answer Q1 and say yes with probability \(\pi\); half answer Q2 and say yes with probability \(\tfrac{1}{2}\). So \(P(\text{yes}) = \tfrac{1}{2}\pi + \tfrac{1}{2}\cdot\tfrac{1}{2}\).

Part 4

Exam toolkit

Match the wording to the rule, then check the arithmetic.

Which probability rule fits the wording?

The question says…UseCard
equally likely outcomes, "a fair …"count favourable / count allAxioms
"not A", "other than"\(1 - P(A)\)Complement
"at least one"\(1 - P(\text{none})\)Complement
"A or B"\(P(A) + P(B) - P(A \cap B)\); drop the last term if mutually exclusiveAddition
"A and B", independent\(P(A)\,P(B)\)Independence
"A and B", without replacement\(P(A)\,P(B \mid A)\)Conditional
"given that", "of those who"\(P(A \mid B) = P(A \cap B)/P(B)\)Conditional
are they independent?compare \(P(A \cap B)\) with \(P(A)P(B)\), or \(P(B \mid A)\) with \(P(B)\)Independence
exactly \(k\) of \(n\) in some order\(\binom{n}{k}\) waysCounting
overall probability of the evidence\(\sum P(E \mid H_i)\,P(H_i)\)Total probability
you know \(P(E \mid H)\) but want \(P(H \mid E)\)\(P(E \mid H)P(H)/P(E)\)Bayes

Subtract the overlap in the addition rule. Mutually exclusive is not independent. \(P(A \mid B) \ne P(B \mid A)\): always write the denominator. Every probability must lie in \([0, 1]\) and a complete distribution must sum to 1; if yours does not, you added when you should have multiplied, or forgot an overlap.