Maths Boot Camp: Session 4

Counting, Probabilities, Random Variables

Session 4 Topics

  • Counting Principles and Techniques
  • Probability
  • Level of Measurement, Random Variables, Distributions

Block 1

Counting

Application 1 — Riker (1962)

Riker, W. H. (1962). The Theory of Political Coalitions.

  • Counting possible coalitions in a legislature
  • Size principle: coalitions form at the smallest size needed
  • Minimum winning coalition

Application 1 — Riker (1962)

  • Parliament with N political parties
  • Total number of possible coalitions: 2^N - 1
    • Why? Each party has two choices — in or out — giving 2^N
    • Subtract 1 to exclude the empty coalition (no party at all can’t govern)

Example: with N=3 parties (A, B, C): 2^3-1 = 7 possible non-empty coalitions — {A}, {B}, {C}, {A,B}, {A,C}, {B,C}, {A,B,C}

Block 1 — Key Formulas at a Glance

Four building blocks, all we need for the rest of this block:

Concept Formula
Fundamental Theorem of Counting m \times n
Factorial n! = n\times(n-1)\times\dots\times1
Permutations (n objects, r at a time) P(n,r) = \frac{n!}{(n-r)!}
Combinations (n objects, r at a time) C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!}

Fundamental Theorem of Counting

  • Two independent events: A can occur in m ways, B can occur in n ways
  • Total number of ways both can occur:

m \times n

  • Example 1: 3 shirts and 2 pairs of pants — how many outfits?
  • Example 2: a 3-character password: letter (26), digit (10), symbol (5) — how many passwords?
  • 3 \times 2 = 6 outfits
  • 26 \times 10 \times 5 = 1300 passwords

Factorials

  • Arrangements of n distinct objects
  • n! = n \times (n-1) \times (n-2) \times \dots \times 1
  • Example: with 3 objects A, B, C, there are 3!=6 arrangements: ABC, ACB, BAC, BCA, CAB, CBA

Example: 5! = 5\times4\times3\times2\times1 = \ ?

5! = 120

Permutations

  • Arrangement of objects where order matters
  • P(n) = n! — permutations of n objects
  • Taken r at a time: P(n,r) = \frac{n!}{(n-r)!}

Example: a campaign has 5 possible messages and shows each respondent 3 of them in sequence. It believes the order of exposure matters — an earlier message can change how a later one lands. How many distinct 3-message sequences are possible?

P(5,3) = \frac{5!}{(5-3)!} = \frac{5!}{2!} = \frac{120}{2} = 60

Combinations

  • Selection of objects where order does not matter
  • Taken r at a time: C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!}

Example: same campaign, same 5 messages, same 3 shown per respondent — but now the campaign believes only exposure matters, not order: anyone shown the same 3 messages counts as having received the same treatment, whatever sequence they saw them in. How many distinct 3-message treatments are possible?

C(5,3) = \binom{5}{3} = \frac{5!}{3!\,2!} = \frac{120}{6\times2} = 10

Block 1 — Bringing It Together

A committee-selection example, combining both tools from this block:

  • A legislative committee needs 3 members chosen from 8 eligible MPs, then those 3 must be ranked as first, second, and third speaker in a debate
  • Step 1 — Combinations: how many distinct groups of 3 MPs can be chosen?

C(8,3) = \binom{8}{3} = \frac{8!}{3!\,5!} = 56

  • Step 2 — Permutations: each chosen group of 3 can be ranked in 3! = 6 ways

56 \times 6 = 336 \text{ possible committee-and-speaking-order outcomes}

Towards the End of Block 1

Practice Time!

Block 2

Probability

The Paradox of Voting

  • Rational-choice logic: vote only if the expected utility of voting is positive

U = (P \times B) - C

  • P = probability your vote is decisive; B = benefit if your candidate wins; C = cost of voting
  • Utility of voting rests on the probability that your vote is the one that decides the outcome
  • In large elections, P \approx \frac{1}{n} — probability of being decisive diminishes rapidly as the electorate n grows
  • Larger pool of voters → smaller individual probability of being pivotal → individual participation looks non-rational
  • Yet people vote anyway: the paradox

Definition of Probability

Probability measures the likelihood of an event, a number between 0 and 1:

  • 0 means the event is impossible; 1 means the event is certain

For an event A in a sample space S: 0 \leq P(A) \leq 1. The sample space has total probability 1 (the sum of all probabilities).

Example: for a fair coin toss, P(\text{Heads}) = \frac{1}{2}

  • Rolling a fair die: 6 equally likely outcomes, each with probability \frac{1}{6}, summing to 1

Axioms of Probability

  • Three fundamental axioms:
    • Non-Negativity: P(A) \geq 0
    • Normalisation: P(S) = 1
    • Countable Additivity: for mutually exclusive E_1, E_2, \dots

P\left(\bigcup_{i=1}^{\infty} E_i\right) = \sum_{i=1}^{\infty} P(E_i)

Reading this formula: the “\dots” just means “as many mutually exclusive events as you like” — could be 3, could be infinitely many. \bigcup is just union — “E_1 or E_2 or E_3 or …” — stacked across however many events there are, and \sum adds up their probabilities in that same order. With only 3 events, this reads simply as P(E_1\cup E_2\cup E_3) = P(E_1)+P(E_2)+P(E_3).

Joint and Conditional Probability

  • Two ways of combining two events’ probabilities — building blocks for Bayes’ Theorem next
  • Joint: both happen, P(A \cap B)
    • Independent: P(A \cap B) = P(A)\cdot P(B)
    • Mutually exclusive: P(A \cap B) = 0
    • General union: P(A \cup B) = P(A)+P(B)-P(A \cap B)
  • Conditional: probability of A given B has occurred

P(A|B) = \frac{P(A \cap B)}{P(B)}, \qquad P(B) > 0

  • If independent, conditioning tells you nothing new: P(A|B) = P(A)

Conditional Probability — Worked Example

Example: 40% of elected officials are women; 15% are women who also hold a cabinet position. What is P(\text{cabinet} \mid \text{woman})?

P(A \cap B) = 0.15, \qquad P(B) = 0.40

P(A|B) = \frac{P(A \cap B)}{P(B)} = \frac{0.15}{0.40} = 0.375

Law of Total Probability

Calculates P(A) using a partition \{B_1,\dots,B_n\} of the sample space — mutually exclusive (B_i\cap B_j=\emptyset) and exhaustive (\bigcup_i B_i = S):

P(A) = \sum_{i=1}^n P(A|B_i)\,P(B_i)

Example: a campaign reaches voters via 3 methods — canvassing (B_1), mail (B_2), digital ads (B_3) — a partition of all contacted voters. Let A = “the voter turns out to vote.”

  • P(B_1)=0.4, P(B_2)=0.3, P(B_3)=0.3 (share reached by each method);   P(A|B_1)=0.9, P(A|B_2)=0.7, P(A|B_3)=0.8 (turnout given each method)

P(A) = (0.9)(0.4) + (0.7)(0.3) + (0.8)(0.3) = 0.36+0.21+0.24 = 0.81

The overall probability that a contacted voter turns out is P(A) = 0.81 (81%)

Bayes’ Theorem

In plain terms: start with what you believed before, then use new evidence to update it

Bayes’ Theorem updates the probability of an event given new evidence:

P(A|B) = \frac{P(B|A)\,P(A)}{P(B)}

Bayes’ Theorem — Derivation

Start from the definition of conditional probability, two ways:

P(A|B) = \frac{P(A \cap B)}{P(B)} \quad \Rightarrow \quad P(A \cap B) = P(A|B)\cdot P(B)

P(B|A) = \frac{P(A \cap B)}{P(A)} \quad \Rightarrow \quad P(A \cap B) = P(B|A)\cdot P(A)

Since both expressions equal P(A \cap B), set them equal and solve for P(A|B):

P(A|B)\cdot P(B) = P(B|A)\cdot P(A) \quad \Rightarrow \quad P(A|B) = \frac{P(B|A)\cdot P(A)}{P(B)}

Bayes’ Theorem — Worked Example

Before any evidence, you hold a prior belief — new evidence updates it.

Example 1 — Medical Test: P(D)=0.01 (1% of people have the disease), P(+|D)=0.99 (true positive rate), P(+|\text{no }D)=0.05 (false positive rate)

P(+) = (0.99)(0.01)+(0.05)(0.99) = 0.0594, \qquad P(D|+) = \frac{0.0099}{0.0594} \approx 0.167

Only ≈16.7% chance of actually having the disease, even after a positive test — the disease is so rare that most positives are false alarms

Bayes’ Theorem — Worked Example

Let’s run the same recipe on a very different kind of evidence — a political exit poll.

Example 2 — Exit Poll: you already believe Candidate A is more likely to win, from polling. An exit poll comes in — how should it change your belief?

  • P(A) = 0.6, \quad P(E|A) = 0.85, \quad P(E|B) = 0.2 (so P(B)=0.4)

Bayes’ Theorem — Worked Example

Continuing the exit poll:

Step 1 — how likely is this exit poll result overall, across both candidates? P(E) = P(E|A)P(A) + P(E|B)P(B) = (0.85)(0.6)+(0.2)(0.4) = 0.51+0.08 = 0.59

Step 2 — apply Bayes’ Theorem to update the belief: P(A|E) = \frac{0.85 \times 0.6}{0.59} = \frac{0.51}{0.59} \approx 0.864

Updated probability Candidate A wins, after the exit poll: about 86.4% — up from 60% before we saw it

In one line: posterior = prior, corrected by how well the evidence fits — Prior P(A){=}0.6 · Likelihood P(E|A){=}0.85 · Marginal P(E){=}0.59 · Posterior P(A|E){\approx}0.864

Boole’s Inequality

An upper bound on the probability of the union of multiple events. For any events A_1, \dots, A_n:

P\left(\bigcup_{i=1}^{n} A_i\right) \leq \sum_{i=1}^{n} P(A_i)

The probability that at least one event occurs is at most the sum of the individual probabilities.

Boole’s Inequality — Worked Example

Three bills in Congress: \Pr(A_1)=0.3, \Pr(A_2)=0.4, \Pr(A_3)=0.5 (probabilities each bill passes)

\Pr(A_1 \cup A_2 \cup A_3) \leq 0.3+0.4+0.5 = 1.2

Note: the actual probability cannot exceed 1 — this overestimate happens because some bills may pass together, and Boole’s Inequality doesn’t subtract out that overlap.

Block 2 — Bringing It Together

A content-moderation example, combining both tools from this block:

  • 10% of viral posts are actually false; 90% are true
  • A flagging algorithm catches 90% of false posts, but also flags 8% of true posts
  • If a post gets flagged, what’s the probability it’s actually false?

Step 1 — Law of Total Probability: how likely is a flag at all, across both true and false posts? P(\text{Flag}) = (0.90)(0.10) + (0.08)(0.90) = 0.09+0.072 = 0.162

Step 2 — Bayes’ Theorem: of everything flagged, how much is actually false? P(\text{False}\mid\text{Flag}) = \frac{0.09}{0.162} \approx 0.556

Only about 56% of flagged posts are actually false — a flag alone isn’t proof

Towards the End of Block 2

Practice Time!

Block 3

Measurement and Random Variables

Levels of Measurement

Data is classified into four levels:

  • Nominal (Categorical): no meaningful order — e.g. political affiliation, gender
  • Ordinal: meaningful order, no consistent scale — e.g. party ID left-right, Likert responses
  • Interval: consistent differences, zero is arbitrary — e.g. dates, temperature (°C/°F)
  • Ratio: interval properties plus a true, meaningful zero — e.g. crime rates

Random Variables

  • Random Variable (RV): a numerical outcome of a random process
  • Assigns a real number to each possible outcome in a sample space
    • Discrete RV: values can be listed one by one — e.g. seats a party wins: 0, 1, 2, \dots
    • Continuous RV: any value within a range — e.g. a candidate’s vote share: 42.37\%, 42.371\%, \dots

Probability Mass Function (PMF)

  • In plain terms: a full list of every possible outcome, and how likely each one is
  • For a discrete RV, the PMF gives the probability of each specific value: P(X=x) = p(x)
  • Lets us read off any probability directly, and is what we’ll sum (next) to get the expectation
  • Properties: 0 \leq p(x) \leq 1, and \sum p(x) = 1

Example: tossing a coin, X=0 for tails, X=1 for heads: P(X=0)=0.5, P(X=1)=0.5

Probability Density Function (PDF)

  • In plain terms: like a PMF, but for outcomes that can take any value in a range, not just a fixed list
  • For a continuous RV, the PDF gives density at a point, not a probability directly: f(x) \geq 0, \int_{-\infty}^{\infty} f(x)\,dx = 1
  • Probability at any single point is zero (a point has no width)
  • To get an actual probability, integrate the PDF over an interval

Expectations

  • Expectation (or expected value, or mean): a weighted average of all possible values, weighted by their probability

E(Y) = \text{weighted average of all possible values of } Y

Expectation of a Discrete Random Variable

E(Y) = \sum_{y} y \cdot \Pr(Y=y) = \sum_y y \cdot p(y)

Example: expected value of a fair die roll:

E(Y) = \frac{1}{6}(1+2+3+4+5+6) = \frac{21}{6} = 3.5

Measures of Random Variables — Mean

  • The mean (\mathbb{E}[Y]): the central tendency of a distribution
  • Same idea, discrete or continuous:

\mathbb{E}[Y] = \sum_i y_i \cdot \Pr(Y=y_i) \quad \text{(discrete)}, \qquad \mathbb{E}[Y] = \int_{-\infty}^{\infty} y \cdot f_Y(y)\,dy \quad \text{(continuous)}

Variance and Standard Deviation

  • The mean tells us the centre of a distribution — but says nothing about its spread
  • Deviation from the mean: y - \mathbb{E}[Y] — squared, to stop positive and negative deviations cancelling out: (y-\mathbb{E}[Y])^2
  • Variance: the average squared deviation — \text{Var}(Y) = \mathbb{E}\left[(Y-\mathbb{E}[Y])^2\right]
  • Standard Deviation: \sigma_Y = \sqrt{\text{Var}(Y)} — same units as Y, unlike variance

Remember from the R Bootcamp

You’ve already worked through this — the exact same walkthrough from R Session 2, using real UK road-accident data.

Example Calculation — Variance and SD

Ideology scores (0–100, left–right) for three candidates: 50, 60, 70. Mean \mathbb{E}[Y]=60.

  • For 50: (50-60)^2=100; for 60: (60-60)^2=0; for 70: (70-60)^2=100

\text{Var}(Y) = \frac{1}{3}(100+0+100) = \frac{200}{3} \approx 66.67

\sigma = \sqrt{\frac{200}{3}} \approx 8.16

Example Calculation — Population or Sample?

Same three ideology scores — 50, 60, 70 — but does it matter whether they’re the whole population or just a sample?

Here, they’re the population: these three candidates are the entire race we care about, so we divide by n=3 — giving \sigma^2 \approx 66.67 and \sigma \approx 8.16, exactly as before.

If instead they were a sample — say, 3 candidates polled out of a much larger field — we’d divide by n-1=2 instead: s^2 = \frac{1}{2}(100+0+100) = 100, \qquad s = \sqrt{100} = 10

Same data, same deviations — a different, larger answer, because dividing by a smaller number (n-1 instead of n) always inflates the estimate slightly, to correct for the fact that a sample tends to underestimate the true population spread.

Example — Same Mean, Different Spread

A get-out-the-vote (GOTV) example, putting mean and variance to work together:

  • Two GOTV messages are tested; observed turnout lift (%) across 3 similar precincts:
    • Message A: 2, 4, 6
    • Message B: 0, 4, 8

E[A] = E[B] = 4\%

  • Same average effect — but the underlying spread is very different

\text{Var}(A) = 2.67 \qquad \text{Var}(B) = 10.67

  • Message B is riskier: same expected lift, much less predictable across precincts

Covariance and Correlation

  • In plain terms: do two things tend to move together, and how strongly?
  • Covariance: how two random variables vary together — \text{Cov}(X,Y) = \mathbb{E}[(X-\mathbb{E}(X))(Y-\mathbb{E}(Y))]
    • >0: tend to increase together; <0: move in opposite directions
  • Correlation: covariance normalised by both SDs — \rho_{XY} = \frac{\text{Cov}(X,Y)}{\sigma_X \sigma_Y}
    • Always between -1 and +1; closer to either end means a stronger linear relationship

Example Calculation — Covariance and Correlation

Ad spending (X, $10k) and vote share (Y, %) for three candidates: (1,45), (2,55), (3,50). Means: \bar{X}=2, \bar{Y}=50.

  • Deviations: X-\bar{X} = -1, 0, 1; \quad Y-\bar{Y} = -5, 5, 0

\text{Cov}(X,Y) = \frac{1}{3}\big[(-1)(-5)+(0)(5)+(1)(0)\big] = \frac{5}{3} \approx 1.67

\sigma_X = \sqrt{\tfrac{2}{3}} \approx 0.82, \qquad \sigma_Y = \sqrt{\tfrac{50}{3}} \approx 4.08

\rho_{XY} = \frac{1.67}{(0.82)(4.08)} \approx 0.5

Normal Distribution

  • Describes data clustering around a mean; mean, median, and mode are all equal
  • Symmetric and bell-shaped
  • The 68-95-99.7 Rule:
    • ~68% of data falls within one standard deviation of the mean
    • ~95% within two standard deviations
    • ~99.7% within three standard deviations

Normal Distribution — Example

For a normal distribution with mean \mu=0 and variance \sigma^2=1 (the standard normal), the density is:

f_Y(y) = \frac{1}{\sqrt{2\pi}} \exp\left(-\frac{y^2}{2}\right)

Quick Check — Random Variables

For X \sim \text{Binomial}(n=4, p=0.7), find E[X] and, for X \sim \text{Binomial}(n=6, p=0.4), find \text{Var}(X).

What’s a Binomial? X\sim\text{Binomial}(n,p) counts the number of “successes” in n independent trials, each with the same success probability p — e.g. the number of heads in n=4 coin flips, or the number of “yes” voters out of n people surveyed.

Reminder: n = number of trials, p = probability of “success” on each one. E[X]=np: expected number of successes = trials × chance per trial. \text{Var}(X)=np(1-p): spread is largest when p=0.5 (most uncertain outcome each trial) and shrinks toward 0 as p\to0 or p\to1 (a near-certain outcome either way).

Quick Check — Random Variables (cont.)

For X \sim \text{Binomial}(n=4, p=0.7), find E[X] and, for X \sim \text{Binomial}(n=6, p=0.4), find \text{Var}(X).

E[X] = np = 4 \times 0.7 = 2.8

\text{Var}(X) = np(1-p) = 6\times0.4\times0.6 = 1.44

Block 3 — Bringing It Together

A GOTV campaign wants to know: does spending more actually buy a bigger turnout lift? Spending ($1,000s) and observed lift (%) across 3 precincts: (1,3), (2,6), (3,6).

E[\text{Spend}] = 2, \qquad E[\text{Lift}] = 5, \qquad \text{Var}(\text{Lift}) = 2

\text{Cov}(\text{Spend},\text{Lift}) = 1, \qquad \rho \approx 0.87

  • A strong positive relationship: more spending tends to come with a bigger lift — but \text{Var}(\text{Lift})=2 says that lift is still not perfectly predictable from spending alone

Towards the End of Block 3

Practice Time!

End of Session

Thank You!