Counting, Probabilities, Random Variables
Counting
Riker, W. H. (1962). The Theory of Political Coalitions.
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}
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)!} |
m \times n
Example: 5! = 5\times4\times3\times2\times1 = \ ?
5! = 120
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
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
A committee-selection example, combining both tools from this block:
C(8,3) = \binom{8}{3} = \frac{8!}{3!\,5!} = 56
56 \times 6 = 336 \text{ possible committee-and-speaking-order outcomes}
Practice Time!
Probability
U = (P \times B) - C
Probability measures the likelihood of an event, a number between 0 and 1:
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}
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).
P(A|B) = \frac{P(A \cap B)}{P(B)}, \qquad P(B) > 0
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
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(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%)
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)}
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)}
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
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?
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
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.
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.
A content-moderation example, combining both tools from this block:
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
Practice Time!
Measurement and Random Variables
Data is classified into four levels:
Example: tossing a coin, X=0 for tails, X=1 for heads: P(X=0)=0.5, P(X=1)=0.5
E(Y) = \text{weighted average of all possible values of } Y
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
\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)}
You’ve already worked through this — the exact same walkthrough from R Session 2, using real UK road-accident data.
Ideology scores (0–100, left–right) for three candidates: 50, 60, 70. Mean \mathbb{E}[Y]=60.
\text{Var}(Y) = \frac{1}{3}(100+0+100) = \frac{200}{3} \approx 66.67
\sigma = \sqrt{\frac{200}{3}} \approx 8.16
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.
A get-out-the-vote (GOTV) example, putting mean and variance to work together:
E[A] = E[B] = 4\%
\text{Var}(A) = 2.67 \qquad \text{Var}(B) = 10.67
Ad spending (X, $10k) and vote share (Y, %) for three candidates: (1,45), (2,55), (3,50). Means: \bar{X}=2, \bar{Y}=50.
\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
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)
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).
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
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
Practice Time!
Thank You!
Maths Boot Camp