Statistics 2Week 0 · Probability Foundations and Random Variables
Week 0 Revision Notes
Statistics for Data Science 2
Week 0 · Foundations: probability basics, distributions and random variables. Every topic in short points with worked examples, so you walk into Week 1 with the groundwork already solid.
11 chapters29 worked examples~56 min read
Probability basicsConditioning and BayesDistributionsRandom variables
How data, probability and statistics fit together, and the first objects of probability: the experiment, its outcomes and the sample space.
1.1Statistical study of phenomena
Data comes from the real world.
Probability is the theory: it builds models for that data.
Statistics is the application: it draws inferences from data, using analysis built on probability theory.
Figure 1. How data, probability and statistics fit together
Dataset in the course. The sample dataset used in the course is the IPL dataset from cricsheet.org, supplied as .yaml files.
1.2Experiment, outcome, sample space
Definitions
Experiment: a process or phenomenon we wish to study statistically. Outcome: the result of the experiment. Sample space: the set containing all outcomes of an experiment, typically denoted S.
Experiment
Sample space
Size
Tossing a coin
S={Head,Tail}
2
Throwing a die
S={1,2,3,4,5,6}
6
Throwing two dice
36 ordered pairs (i,j)
36
Figure 2. Sample spaces of a coin and a die, and how many events each has
Example 1Write the sample space
Write the sample space for: (a) tossing a coin twice, (b) choosing a month of the year, (c) the number of heads in 3 tosses.
Solution
(a) S={HH,HT,TH,TT}: 4 outcomes (order matters, so HT and TH are different).
(b) S={Jan,Feb,…,Dec}: 12 outcomes.
(c) S={0,1,2,3}: the outcome here is the count, not the sequence of tosses.
Revision overview
DataComes from the real world Sample: IPL data (cricsheet.org, .yaml)
ProbabilityThe theory Builds models for the data
StatisticsThe application Draws inferences using probability
Statistical StudyWeek 0 · Part 1
ExperimentA process we study statistically
OutcomeThe result of the experiment
Sample space SSet of all outcomes Coin: {H, T} · Die: {1, …, 6}
Events are the central objects of probability. They are just sets, so everything from set theory carries over: containment, complement, union, intersection, and De Morgan's laws.
2.1Events
Definition: event
An event is a subset of the sample space. (There is a technical restriction on which subsets can be events; for a finite sample space every subset is an event.) An event has occurred if the actual outcome belongs to that event.
Events are sets, so all set-theory notions apply to them.
Events are the central objects in probability theory.
Counting events
Toss a coin: S={H,T}, events are ∅,{H},{T},{H,T}: 4 events (that is 22).
Throw a die: S has 6 outcomes, so 64=26 events, from ∅ up to the whole S.
Some are easy to describe in words: "getting an even number", "getting a multiple of 3".
Figure 3. The four events of one coin toss
Links to Week 1 of Maths. A set with n elements has 2n subsets (the power set), which is exactly why a sample space with n outcomes has 2n events.
Containment and complement
One event can be contained in another: A⊆B. Throw a die, A={2,6}, B = even numbers. If A occurred, B has also occurred. If B occurred, A may or may not have occurred.
Complement of A, written Ac = outcomes of S not in A = S∖A. Die: A={2,4,6} (even) gives Ac={1,3,5} (odd). If A occurred, Ac did not, and vice versa.
Figure 4. Containment (left) and complement (right) on a die
2.2Combining events
Since events are subsets, you can take complements, unions and intersections:
Operation
In English
Symbol
Occurs when
Union
"or"
A∪B
at least one of A, B occurs
Intersection
"and"
A∩B
both A and B occur
Complement
"not"
Ac
A does not occur
Difference
"A but not B"
A∖B=A∩Bc
A occurs and B does not
Figure 5. The four basic combinations as shaded regions
2.3Disjoint events and Venn diagrams
Definition: disjoint
Two events with an empty intersection are disjoint. If A and B are disjoint: if A occurred, B did not, and if B occurred, A did not.
An event and its complement
A and Ac are always disjoint.
A∩Ac=∅A∪Ac=S
Multiple events
E1,E2,E3,… are disjoint if for any i=j, Ei∩Ej=∅.
Large sample space? Partition it into disjoint events for easier study.
Figure 6. Reading events off a Venn diagram
De Morgan's laws
(A∪B)c=Ac∩Bc(A∩B)c=Ac∪Bc
In words: "not (A or B)" means "not A and not B"; "not (A and B)" means "not A or not B".
Figure 7. De Morgan's law: the outside of A ∪ B is the same region as Aᶜ ∩ Bᶜ
Example 2Describe the events
Throw a die. A={1,2,3}, B={2,4,6}. Find A∪B, A∩B, A∖B, Bc and (A∪B)c. Are A and B disjoint?
Solution
Event
Set
In words
A∪B
{1,2,3,4,6}
1, 2, 3 or even
A∩B
{2}
small and even
A∖B
{1,3}
in A, not even
Bc
{1,3,5}
odd
(A∪B)c
{5}=Ac∩Bc
De Morgan ✓
A∩B={2}=∅, so A and B are not disjoint.
Revision overview
EventA subset of S Occurred if the outcome is in it n outcomes → 2ⁿ events
ContainmentA ⊆ B: A occurred ⇒ B occurred Not the other way
ComplementAᶜ = S \ A A and Aᶜ never both occur
EventsWeek 0 · Part 2
CombiningUnion ∪ = "or" Intersection ∩ = "and" A \ B = A ∩ Bᶜ
DisjointEmpty intersection Partition a big S into disjoint events
Probability is a function that assigns a number between 0 and 1 to every event. Two simple axioms are enough to derive everything else, including the properties we use all the time.
3.1Probability and the axioms
Probability is a function P that assigns to each event a real number between 0 and 1. The value represents the chance of that event occurring.
Higher value → higher chance. 0 means the event cannot occur; 1 means it always occurs. Probability is often quoted as a percentage.
Probability space = sample space + events + probability function, taken together.
Figure 8. Probability lies between 0 and 1
The two axioms
Axiom 1:P(S)=1. The whole sample space has probability 1.
Axiom 2: if E1,E2,E3,… are disjoint events, then P(E1∪E2∪E3∪⋯)=P(E1)+P(E2)+P(E3)+⋯
Figure 9. The two axioms
There may be infinitely many events in Axiom 2.
The axioms are intuitive and restrict which functions can be probability functions.
They lead to several useful deductions about combinations and subsets of events.
3.2Basic properties of probability
Property
Statement
1 · Empty set
P(∅)=0
2 · Complement
P(Ec)=1−P(E)
3 · Subset
If E⊆F: P(F)=P(E)+P(F∖E), which implies P(E)≤P(F)
4 · Difference and intersection
P(E)=P(E∩F)+P(E∖F)⋅P(F)=P(E∩F)+P(F∖E)
5 · Union and intersection
P(E∪F)=P(E)+P(F)−P(E∩F)
Figure 10. If E ⊆ F then P(F) = P(E) + P(F \ E), so P(E) ≤ P(F)
Useful difference formulas
P(A∖B)=P(A∪B)−P(B)P(A∖B)=P(A)−P(A∩B)
If A and B are disjoint, P(A∖B)=P(A).
Why property 5 is true. Adding P(E)+P(F) counts the overlap E∩F twice. Subtract it once. The same idea gave n(P∪B)=n(P)+n(B)−n(P∩B) in Maths Week 1.
3.3Working with probability spaces
Example: restaurant hiring
A waiter and a cashier are hired from 4 applicants: David and Megha from Delhi, Rajesh and Veronica from Mumbai. One person is hired at random as waiter, another from the remaining as cashier.
Figure 11. The 12 outcomes (waiter, cashier) and the events A, B, C
Sample space (ordered pairs, waiter first): S={(D,M),(D,R),(D,V),(M,D),(M,R),(M,V),(R,D),(R,M),(R,V),(V,D),(V,M),(V,R)}: 12 outcomes.
Event A: cashier is from Delhi: A={(D,M),(R,M),(V,M),(M,D),(R,D),(V,D)} (6 outcomes).
Event B: exactly one position filled by a Delhiite: B={(D,R),(D,V),(M,R),(M,V),(R,D),(V,D),(R,M),(V,M)} (8 outcomes).
Event C: neither position filled by a Delhiite: C={(V,R),(R,V)} (2 outcomes).
Example: fishing town
The chance of catching more than 400 kg of fish in a day is 35%; the chance of more than 500 kg is 10%. What is the chance of catching between 400 and 500 kg?
Figure 12. B ⊆ A: anything over 500 kg is also over 400 kg
A = catch >400 kg, P(A)=0.35. B = catch >500 kg, P(B)=0.10.
Key observation:B⊆A.
P(>400 and ≤500)=P(A∖B)=P(A)−P(B)=0.35−0.10=0.25.
Example: weather forecast
Chance of rain = 60%. Chance of max temperature above 30° = 70%. Chance of both = 40%. What is the chance of no rain and temperature below 30°?
Figure 13. All four regions of the Venn diagram add up to 1
A = rain, P(A)=0.6; B = temperature >30∘, P(B)=0.7; P(A∩B)=0.4.
We want P(Ac∩Bc). By De Morgan: P(Ac∩Bc)=P((A∪B)c)=1−P(A∪B).
=1−(0.6+0.7−0.4)=1−0.9=0.1.
Example 3Using the properties
P(A)=0.5, P(B)=0.4, P(A∩B)=0.2. Find P(A∪B), P(A∖B), P(Ac) and P(Ac∩Bc).
Solution
P(A∪B)=0.5+0.4−0.2=0.7.
P(A∖B)=P(A)−P(A∩B)=0.5−0.2=0.3.
P(Ac)=1−0.5=0.5.
P(Ac∩Bc)=1−P(A∪B)=1−0.7=0.3.
Example 4Can this be a probability?
A student claims P(A)=0.7, P(B)=0.5 and P(A∪B)=0.6. Is that possible?
Solution
No. A⊆A∪B, so P(A)≤P(A∪B) by property 3. But 0.7>0.6. (Equivalently, P(A∩B)=0.7+0.5−0.6=0.6 would exceed P(B)=0.5, which is impossible since A∩B⊆B.)
3.4Inclusion–exclusion for three events, "at least one", and the birthday problem
A. Three events
For two events P(A∪B)=P(A)+P(B)−P(A∩B). For three, add the singles, subtract the pairs, add back the triple:
Why. An outcome in all three events is counted 3 times in the singles, subtracted 3 times in the pairs, so it needs to be added back once to be counted exactly once. An outcome in exactly two events is counted twice and subtracted once, so it is counted once.
Example.P(A)=0.5, P(B)=0.4, P(C)=0.3, P(A∩B)=0.2, P(A∩C)=0.1, P(B∩C)=0.1, P(A∩B∩C)=0.05. Then
P(A∪B∪C)=1.2−0.4+0.05=0.85,P(none of the three)=1−0.85=0.15
Union bound (Boole). Without any other information, P(A1∪⋯∪An)≤P(A1)+⋯+P(An). In the example 1.2≥0.85. Equality holds exactly when the events are disjoint.
B. "At least one" is a complement
Computing "at least one" directly means adding many cases. Take the complement instead: P(at least one)=1−P(none), and "none" is usually a single product when the trials are independent.
Three fair coin tosses, at least one head: 1−(21)3=87.
A fair die thrown 4 times, at least one six: 1−(65)4=1−1296625=1296671≈0.518. (This is the same idea as the geometric cumulative formula P(G≤k)=1−(1−p)k.)
C. The birthday problem
In a group of n people (365 equally likely birthdays, ignoring 29 February), what is the probability that at least two share a birthday? Use the complement. The first person can have any birthday, the second must avoid 1 date, the third must avoid 2 dates, and so on:
With only 23 people the probability of a shared birthday already passes one half. It feels too small because we compare one person against 365 days, but the number of pairs is (223)=253, and any pair can match.
D. Counting equally likely outcomes
When all outcomes are equally likely, P(E)=∣S∣∣E∣, and the counts come from combinations. A committee of 3 is chosen at random from 5 boys and 4 girls. P(exactly 2 girls)=(39)(24)(15)=846⋅5=145≈0.357.
A fair die is thrown 4 times. What is the probability of at least one six? (Give a decimal rounded to 3 places.)
Solution
Idea
Complement: no six in four throws.
P(no six)=(5/6)4=625/1296≈0.4823.
P(at least one six)=1−0.4823=0.5177≈0.518.
Answer: 0.518
Q3Birthdays
Multiple Select Question (MSQ): select all that apply.
Assume 365 equally likely birthdays. Choose the correct statements.
1
In a group of 23 people, the probability that at least two share a birthday is more than 21.
2
In a group of 23 people, the probability that at least two share a birthday is 36523.
3
P(no shared birthday among n)=365365⋅365364⋯365365−n+1.
4
With 366 or more people a shared birthday is certain (ignoring 29 February).
Solution
Idea
Use the complement and the pigeonhole principle.
1 ✓ for n=23 the probability is ≈0.507. 2 ✗ 23/365≈0.063 counts only comparisons with one person. 3 ✓ the product formula. 4 ✓ 366 people cannot fit in 365 distinct dates.
Answer: options 1, 3 and 4.
Q4A random committee
Numerical Answer Type (NAT).
A committee of 3 is chosen at random from 5 boys and 4 girls. What is the probability that it has exactly 2 girls? (Give a decimal rounded to 3 places.)
Solution
Idea
Favourable committees: 2 of the 4 girls and 1 of the 5 boys. Total: any 3 of the 9.
(24)(15)=6×5=30 and (39)=84.
30/84=5/14≈0.357.
Answer: 0.357
Revision overview
Probability PFunction: event → number in [0, 1] 0 impossible, 1 certain
Distributions, Uniform Distribution and Derangements
A distribution gives probabilities to individual outcomes. The simplest one makes every outcome equally likely. A famous uniform example, the mixed-up hats, leads to derangements and the number 1/e.
4.1Distributions and the uniform distribution
Definition: distribution
A distribution assigns probabilities to individual outcomes. This is possible when the outcomes can be enumerated as first, second, third and so on (a countable sample space), or when the sample space is finite.
Uniform distribution on a finite sample space
All outcomes are equally likely: assign the same probability to each.
P(one outcome)=∣S∣1P(event)=number of outcomes in Snumber of outcomes in the event
Example 1: marbles in an urn
5 red and 8 blue marbles; pick one at random. ∣S∣=13, so P(red)=135 and P(blue)=138.
Figure 14. Uniform: count the favourable outcomes and divide by all
Example 2: sum of two dice
Throw 2 dice; ∣S∣=36 equally likely ordered pairs. Event E = sum is 8 = {(2,6),(6,2),(3,5),(5,3),(4,4)}, 5 outcomes, so P(E)=365.
Figure 15. Five of the 36 equally likely pairs sum to 8
Example 3: mixed-up hats
3 people\'s identical hats get mixed up; each picks one at random. What is the probability that nobody gets their own hat? ∣S∣=3!=6 arrangements, and only 2 of them leave nobody with their own hat, so P(E)=62=31.
Figure 16. The six arrangements; two of them are derangements
What if there were 30 people? The answer approaches e1≈37%.
4.2Derangements
Definition: derangement
A derangement is an arrangement of objects into positions such that no object goes to its own specified position. In permutation language: a permutation σ of n elements with no fixed point, i.e. σ(i)=i for all i∈{1,…,n}.
Dn=n!k=0∑nk!(−1)kD(n)=n⋅D(n−1)+(−1)n
n
1
2
3
4
5
6
7
8
D(n)
0
1
2
9
44
265
1854
14833
The sum tends to n!/e for larger n: Dn≈en!.
Probability of a derangement:P(n)=n!D(n)≈e1. This is exactly why the mixed-up-hats answer settles near 37% no matter how many people there are.
Figure 17. P(derangement) for n = 1 … 9 people
Check the recursion.D(3)=3⋅D(2)+(−1)3=3⋅1−1=2, D(4)=4⋅2+1=9, D(5)=5⋅9−1=44. (Here D(1)=0, D(2)=1.)
Example 5Uniform probabilities
A fair die is thrown once. Find the probability of (a) a number greater than 4, (b) a prime, (c) an even number or a multiple of 3.
Solution
(a) {5,6}: 62=31.
(b) {2,3,5}: 63=21.
(c) even {2,4,6} or multiple of 3 {3,6} gives {2,3,4,6}: 64=32. (Check: 63+62−61=64.)
Example 6Two dice
Two fair dice are thrown. Find the probability that (a) the sum is 7, (b) both show the same number, (c) the sum is at most 3.
Conditional Probability, Total Probability and Bayes' Theorem
New information changes probabilities. Conditional probability formalises this; the law of total probability combines several cases; and Bayes' theorem reverses a conditional.
5.1Conditional probability
Start with a probability space (S,events,P). Let B be an event with P(B)>0. Knowing that B occurred changes the space we work in:
Sample space:B.
Events:A∩B, for every event A in the original space.
Probability function:P(A∩B)÷P(B).
Definition: conditional probability
P(A∣B)=P(B)P(A∩B)
Rearranged, this is the multiplication rule: P(A∩B)=P(B)⋅P(A∣B).
Example 1: throw a die, given an even number
Figure 18. Once we know an even number came up, the space shrinks to {2, 4, 6}
S={1,…,6}, uniform, so each outcome has probability 61. E={2,4,6}, P(E)=21.
P({2}∣E)=1/21/6=31, P({4}∣E)=31.
P({1}∣E)=P(E)P(∅)=0; P({3}∣E)=P({5}∣E)=0.
P({2,5}∣E)=1/21/6=31; P({2,3,4}∣E)=1/22/6=32.
Notice. Odd numbers get probability 0 once you know an even number came up: the conditional space has shrunk to B.
Example 2: students from three states
15 students: 4 from State 1, 8 from State 2, 3 from State 3. Three students are chosen one after another. Probability they come from State 1, State 3, State 1 in that order? Chain the conditionals; the pool shrinks after each pick:
A family has two children. Probability that both are girls, given that at least one is a girl? S={BB,BG,GG,GB}. Event E1 (at least one girl) ={BG,GG,GB}, so P(E1)=43, and P({GG}∣E1)=3/41/4=31.
Figure 20. Conditioning removes only BB, leaving three equally likely outcomes
Classic trap
The intuitive answer 21 is wrong: conditioning removes only BB, leaving three equally likely outcomes, not two.
5.2Law of total probability
P(A)=P(A∩B)+P(A∩Bc)=P(A∣B)P(B)+P(A∣Bc)P(Bc)
Proof idea:A is the disjoint union of A∩B and A∩Bc. Axiom 2 splits P(A) into the two pieces, then conditional probability rewrites each one.
If interest rates rise, there is a 60% chance unemployment increases; if they do not rise, only a 30% chance. There is a 40% chance rates rise. What is the chance unemployment increases?
Figure 21. Tree diagram: add the branches that end in "unemployment up"
A = rates rise, P(A)=0.4, P(Ac)=0.6. B = unemployment increases, P(B∣A)=0.6, P(B∣Ac)=0.3.
P(B)=(0.6×0.4)+(0.3×0.6)=0.24+0.18=0.42: a 42% chance.
Example 2: five coins
A man has 5 coins: 2 double-headed, 1 double-tailed, 2 normal. He picks one at random and tosses it. Probability of a head? The three coin types partition the sample space.
Figure 22. Weighted by how many coins of each type exist
P(head)=1⋅52+0⋅51+21⋅52=52+51=53
5.3Bayes' theorem
The setup: two events A and B; P(A) and P(B) are known; P(A∣B) and P(A∣Bc) are known or easy to find. The question: find P(B∣A), the reverse conditional.
Use the law of total probability to compute P(A) in the denominator, then plug it into Bayes\' formula.
Example 1: swine flu test
1% of people in a city have swine flu. 95% of people with the disease test positive; 2% of people without it also test positive. A random person tests positive. What is the chance they actually have swine flu?
A = tests positive, B = has swine flu. P(B)=0.01, P(Bc)=0.99, P(A∣B)=0.95, P(A∣Bc)=0.02.
Figure 23. The same answer by counting 10,000 people
Why only 32%?
A positive test is far from a certainty when the disease is rare: there are far more healthy people, so even a 2% false-positive rate produces more false alarms (198) than true cases (95).
Example 2: MCQ guessing
A student answering a 4-choice MCQ knows the answer with probability 43; otherwise she guesses at random. Given the question was answered correctly, what is the chance she knew it?
A = answer correct, B = knows. P(A∣B)=1, P(A∣Bc)=41, P(B)=43, P(Bc)=41.
Total:P(A)=(1×43)+(41×41)=1613.
Bayes:P(B∣A)=13/1643×1=1312.
Example 3: die then coins
Roll a fair die, then toss as many fair coins as the number shown. Given 5 heads were obtained, what is the probability the die showed 5?
P(5 heads∣die i)=0 for i=1,2,3,4: you cannot get 5 heads from fewer than 5 tosses.
P(5 heads∣5)=321; P(5 heads∣6)=646=323.
Total:P(5 heads)=321⋅61+323⋅61=481.
Bayes:P(5∣5 heads)=1/4861×321=41.
Example 8Conditional probability from a table
In a class of 50, 30 are boys. 12 boys and 8 girls wear glasses. A student is picked at random and wears glasses. What is the probability the student is a boy?
Solution
P(glasses)=5012+8=5020.
P(boy∩glasses)=5012.
P(boy∣glasses)=20/5012/50=2012=53.
Example 9Two factories
Factory 1 makes 60% of the bulbs, 2% of them defective. Factory 2 makes 40%, 5% defective. A bulb is defective. What is the probability it came from Factory 2?
Solution
P(D)=0.6×0.02+0.4×0.05=0.012+0.020=0.032.
P(F2∣D)=0.0320.4×0.05=0.0320.020=0.625.
So a defective bulb is more likely (62.5%) to be from the smaller factory, because of its higher defect rate.
5.4Bayes in practice: base rates, false positives and natural frequencies
The most common exam use of Bayes' theorem is a test for something rare: a medical screen, a spam filter, a defect detector. The surprising lesson is that even an accurate test can give a mostly wrong positive result when the thing it looks for is rare.
A. The vocabulary
Prevalence (base rate, prior):P(D), the fraction who really have the condition.
Sensitivity (true positive rate):P(+∣D).
Specificity (true negative rate):P(−∣Dc). Its complement, P(+∣Dc)=1−specificity, is the false positive rate.
Posterior:P(D∣+), the probability that a person who tested positive really has it. This is what Bayes' theorem delivers.
B. A worked example
A condition has prevalence 1%. A test has sensitivity 95% and specificity 90% (false positive rate 10%). A person tests positive. How likely is it that they have the condition?
Only about 8.8%, even though the test is 95% sensitive.
Natural frequencies make the same point without formulas. Take 10,000 people:
Test +
Test −
Total
Have the condition
95
5
100
Do not have it
990
8,910
9,900
Total
1,085
8,915
10,000
Of the 1,085 positives only 95 are real: 95/1085≈0.0876. The 990 false alarms come from the huge healthy group, and 10% of 9,900 is more than 95% of 100.
C. What changes the answer
Prevalence. If the prevalence is 10% instead, P(+)=0.95(0.1)+0.1(0.9)=0.185 and P(D∣+)=0.095/0.185=19/37≈0.514. The same test now gives a posterior above one half.
A negative result. With the original numbers, P(D∣−)=0.0005+0.8910.05×0.01≈0.00056: a negative result is very reassuring.
Repeating the test. If two tests are independent given the person's true status, then two positives give P(D∣++)=0.952(0.01)+0.102(0.99)0.952(0.01)=0.0189250.009025≈0.477. The posterior after the first positive becomes the prior for the second.
Q1The posterior after a positive test
Numerical Answer Type (NAT).
A condition has prevalence 1%; the test has sensitivity 95% and false positive rate 10%. Find P(D∣+) as a percentage rounded to 2 decimals.
Solution
Idea
Total probability for P(+), then Bayes.
P(+)=0.95⋅0.01+0.10⋅0.99=0.1085.
P(D∣+)=0.0095/0.1085=19/217≈0.08756, i.e. 8.76%.
Answer: 8.76
Q2Counting the positives
Numerical Answer Type (NAT).
With the same numbers, out of 10,000 people, how many are expected to test positive?
Two events are independent when knowing one tells you nothing about the other. This part defines it, separates it from "disjoint", and extends it to three or more events.
6.1Independence of events
Definition: independent events
A and B are independent⟺P(A∩B)=P(A)⋅P(B)
If P(B)>0 and A,B are independent, then P(A∣B)=P(A): the probability of A is unaffected by whether B occurred.
Points to remember
Disjoint events (each with positive probability) are never independent. If A and B are disjoint and B occurs, A definitely did not occur, so B\'s occurrence definitely affects A\'s conditional probability.
For events (of positive probability) to be independent, they must have a non-empty intersection.
The fine print. The notes say disjoint events are never independent. That is true whenever both have positive probability. The only exception is an event of probability 0: if P(A)=0 then P(A∩B)=0=P(A)P(B) for any B, so such an A is independent of everything (including events disjoint from it).
Example 1: even vs odd (not independent)
Throw a die. A = even = {2,4,6}, B = odd = {1,3,5}. A∩B=∅. P(A∩B)=0, but P(A)P(B)=41, so they are not independent.
Example 2: even vs multiple of 3 (independent)
A = even = {2,4,6}, B = multiple of 3 = {3,6}. A∩B={6}. P(A∩B)=61 and P(A)P(B)=63×62=61: independent ✓.
Figure 24. Independent although they overlap: the intersection has exactly the right size
Example 3: a card from a pack
A = card is a spade, B = card is a king, A∩B = king of spades. P(A∩B)=521=5213×524=P(A)P(B): independent ✓.
Figure 25. One full row (spades) times one full column (kings) meet in exactly one card
Typical points of confusion
"A and B have an intersection, so how can they be independent?" They must, in fact, intersect (when both have positive probability).
"There is only one throw of the die / one card drawn, so how can two events be independent?" Independence is about probabilities, not about repeated trials.
The last condition on A∩B∩C is an additional, important requirement. Pairwise independence alone is not mutual independence.
n events
P(Ai1∩Ai2∩⋯∩Aik)=P(Ai1)P(Ai2)⋯P(Aik)
This is a constraint for every subset of the events: the probability of the intersection of any subset equals the product of their probabilities. Counting subsets of size at least 2, there are 2n−n−1 constraints (the notes say "almost 2n").
Results that follow
If A,B are independent, so are A and Bc: P(A∩Bc)=P(A)−P(A∩B)=P(A)(1−P(B))=P(A)P(Bc).
Also A,B independent ⇒Ac,Bc independent.
If n events are mutually independent, any subset of them, with or without complementing, is independent too.
Example: roads between towns
Two roads connect A→B and two connect B→C. Each of the 4 roads is blocked with probability p, independently. Find the probability there is an open route A→B, given there is no open route A→C.
Figure 26. A→B has two roads, B→C has two roads
No open route A→B means both blocked: p2. So P(F)=1−p2, where F = open route A→B. Let E = no open route A→C.
Split E over F and Fc: P(E)=P(E∣F)P(F)+P(E∣Fc)P(Fc)=p2(1−p2)+1⋅p2=2p2−p4.
P(F∣E)=P(E)P(E∣F)P(F)=2p2−p4p2(1−p2)=2−p21−p2.
Check with p=31.2−1/91−1/9=17/98/9=178≈0.47. Given that A→C is blocked, an open A→B is slightly less than even odds. As p→0 the answer tends to 21; as p→1 it tends to 0.
Example 10Test for independence
Two fair coins are tossed. A = first is a head, B = second is a head, C = both are the same. Are A,B independent? A,C? Are A,B,C mutually independent?
So the events are pairwise independent but not mutually independent: the extra condition really matters.
Example 11Independent trials
A shooter hits a target with probability 0.8 on each of 3 independent shots. Find the probability that (a) all 3 hit, (b) none hit, (c) at least one hits.
Solution
(a) 0.83=0.512.
(b) 0.23=0.008.
(c) 1−0.008=0.992 (complement of "none").
Revision overview
DefinitionP(A ∩ B) = P(A) · P(B) Then P(A | B) = P(A)
Disjoint ≠ independentDisjoint (positive probability) ⇒ never independent Independent events must overlap
ExamplesEven vs odd: no Even vs multiple of 3: yes Spade vs king: yes
IndependenceWeek 0 · Part 6
Mutual independence3 events: pairs AND the triple n events: every subset multiplies
ComplementsA, B independent ⇒ A, Bᶜ independent ⇒ Aᶜ, Bᶜ independent
Repeating a yes/no experiment independently gives the first two named distributions of the course: the binomial (how many successes in n trials) and the geometric (how long until the first success).
7.1Bernoulli trials
A single Bernoulli trial
Setting: the occurrence of event A is "success"; non-occurrence is "failure". Let p=P(A).
Sample space:{success,failure}, or equivalently {0,1}.
P(1)=p, P(0)=1−p. Denoted Bernoulli(p).
Repeated Bernoulli trials
Setting: repeat a Bernoulli trial multiple times independently: perform n independent Bernoulli(p) trials.
Outcome: 0 or 1 for each of trial 1, trial 2, …, trial n. Sample space:2n outcomes. E.g. n=3: {000,001,010,011,100,101,110,111}, 8 outcomes.
Probabilities are computed using independence: just multiply.
P(000)=(1−p)3P(101)=p(1−p)p=p2(1−p)
The general formula
P(b1b2…bn)=pw(1−p)n−w,w=number of 1s in b1b2…bn
Key insight
The actual sequence of 0s and 1s does not matter: only the number of successes matters. A 200-trial sequence with 36 ones has probability p36(1−p)164, whatever the order.
Figure 27. The eight outcomes of three Bernoulli trials
Example: toss a fair coin 5 times
H is 0, T is 1. Sample space: 25=32 equally likely outcomes, each with probability 321. The number of outcomes with k tails is (k5):
Tails
0
1
2
3
4
5
Outcomes
1
5
10
10
5
1
Probability
1/32
5/32
10/32
10/32
5/32
1/32
Figure 28. Number of tails in 5 tosses
P(at least 4 tails)=325+321=326.
P(at most 3 heads): at most 3 heads means at least 2 tails, so =3210+10+5+1=3226 (the notes write 321+5+10+10, the same number by symmetry).
Example: toss a biased coin 5 times
H is 0, T is 1, with P(H)=31 and P(T)=32. Now the outcomes are not equally likely, but the formula still works:
Event
Probability
Value
P(HHHHH)
(31)5
2431
P(1 tail)
5×(32)(31)4
24310
P(2 tails)
10×(32)2(31)3
24340
P(3 tails)
10×(32)3(31)2
24380
P(4 tails)
5×(32)4(31)
24380
P(TTTTT)
(32)5
24332
Check.1+10+40+80+80+32=243, so the six probabilities add to 1. ✓
7.2Binomial distribution
Perform n independent Bernoulli(p) trials. Outcome of interest: the number of successes, denoted B(n,p) or just B.
Sample space:{0,1,2,…,n}.
Example: n = 3
P(B=0)P(B=1)P(B=2)P(B=3)=P(000)=(1−p)3=P(001 or 010 or 100)=3p(1−p)2=P(110 or 101 or 011)=3p2(1−p)=P(111)=p3
Small n, all at once
Figure 29. Binomial probabilities for n = 1 … 5
The general expression
P(B=k) = (number of sequences with exactly k ones) ×pk(1−p)n−k. The number of b1b2…bn with exactly k ones is (kn)=k!(n−k)!n!.
Binomial PMF
P[B(n,p)=k]=(kn)pk(1−p)n−k,k=0,1,…,n
Graph of Binomial(n, p): observations
Starts at (1−p)n, increases and reaches a peak, then falls to pn.
Where is the peak? Near np: exactly at ⌊p(n+1)⌋, the largest integer ≤p(n+1).
All the probabilities must add to 1: (1−p)n+(1n)p(1−p)n−1+(2n)p2(1−p)n−2+⋯+pn=1 (the binomial theorem).
Figure 30. B(10, 0.5) peaks at 5, B(10, 0.3) at 3
A small caveat. If p(n+1) is itself an integer, the two values p(n+1)−1 and p(n+1) are both peaks (they have equal probability). For example B(9,0.5): p(n+1)=5, and the probabilities at k=4 and k=5 are equal.
Example 1: disease testing
Each person has a disease with probability 0.1, independently. Out of 100 people tested, what is the probability that 20 test positive? P(B(100,0.1)=20)=(20100)(0.1)20(0.9)80≈0.0012.
Sense check. The expected number of positives is np=10, so seeing 20 is unlikely: about 0.12%.
Example 2: fair coin, 10 tosses
(a) Probability the number of heads is a multiple of 3? Values {0,3,6,9}: 210(010)+(310)+(610)+(910)=10241+120+210+10=1024341≈0.333.
(b) Probability the number of heads is even? Values {0,2,4,6,8,10}: 10241+45+210+210+45+1=1024512=21.
Why exactly one half? The binomial coefficients (k10) for even k and for odd k both add up to 29=512, because (1+1)10=1024 and (1−1)10=0.
Example 3: bits flipped in transmission
A bit sent by Alice to Bob gets flipped with p=0.1. Probability that at most 2 bits get flipped?
Figure 31. Geometric(1/6): starts at p and keeps falling
Starts at p and keeps falling; keeps decreasing but, if p<1, never goes all the way to zero.
The cumulative formula
P(G≤k)=p+(1−p)p+⋯+(1−p)k−1p=1−(1−p)kP(G>k)=(1−p)k
Easy way to remember.G>k means the first k trials all failed, which has probability (1−p)k. The formula for P(G≤k) is then just 1−P(G>k).
Example 1: Ludo
A player throws a die repeatedly until she gets a 1. Here p=61. "Fewer than n throws" means G≤n−1, so we use P(G≤n−1)=1−(65)n−1:
Event
Formula
Value
fewer than 6 throws
1−(65)5
0.5981
fewer than 11 throws
1−(65)10
0.8385
fewer than 21 throws
1−(65)20
0.9739
A correction to the source notes. The source writes the exponents 5, 11 and 21 and the values 0.5981, 0.8654, 0.9783. Only the first line fits "fewer than": for "fewer than 11" the exponent must be 10, not 11 (1−(5/6)11=0.8654 is at most 11 throws), and for "fewer than 21" it must be 20. The values above are the corrected ones.
Example 2: alternating free throws
Player 1 is a 40% shooter, Player 2 is a 70% shooter. They alternate, Player 1 starting, until the first basket is scored.
Figure 32. One full round multiplies the probability by 0.6 × 0.3 = 0.18
(a) Player 1 wins before the 3rd round? Favourable: P1 scores on throw 1, or P1 misses, P2 misses, P1 scores: 0.4+(0.6×0.3×0.4)=0.472.
(b) Player 1 wins overall? Each extra round multiplies by 0.6×0.3=0.18: an infinite geometric series. 0.4+(0.18)(0.4)+(0.18)2(0.4)+⋯=1−0.180.4=0.820.4≈0.487.
A GP formula you will keep needing
a+a2+a3+⋯=1−aa, valid when ∣a∣<1. The version starting at 1 is 1+a+a2+⋯=1−a1; the notes\' form is the same series with the first term a.
Example 12Binomial or geometric?
Decide which distribution fits: (a) number of sixes in 12 throws of a die; (b) number of throws until the first six; (c) number of defective bulbs in a box of 20, each defective independently with probability 0.05.
Solution
Situation
Distribution
Why
sixes in 12 throws
B(12,61)
fixed number of trials, count successes
throws until first six
G(61)
count trials until the first success
defective bulbs of 20
B(20,0.05)
fixed 20 independent trials
Example 13Binomial probabilities
A fair coin is tossed 6 times. Find the probability of (a) exactly 3 heads, (b) at least 5 heads, (c) at most 1 head.
Solution
(a) (36)/26=6420=165.
(b) 64(56)+(66)=646+1=647.
(c) 64(06)+(16)=641+6=647 (same as (b) by symmetry).
Example 14Geometric probabilities
A basketball player scores a basket with probability 0.3 on each independent attempt. Find (a) P(first basket on the 4th attempt), (b) P(first basket within 3 attempts), (c) P(more than 5 attempts are needed).
From outcomes to numbers. A random variable turns each outcome into a real number; its PMF says how likely each value is.
8.1Random variables
Random variables are numerical values computed from the outcomes of an experiment.
Definition: random variable
A random variable is a function with domain = the sample space and range = the real numbers: a function from the sample space to the real line.
Links to Maths Week 1. This is exactly the "function" of Maths Week 1 (domain, codomain, range), with the sample space as the domain.
Example: toss a coin, S = {H, T}
X(H)=0,X(T)=1
Y(H)=−10,Y(T)=200
Z(H)=2,Z(T)=π
All three are valid random variables, but usually we choose meaningful functions.
Figure 33. A random variable turns outcomes into numbers
Example: throw a die
S={1,…,6}. Pick any 6 real numbers x1,…,x6 and set X(1)=x1,…,X(6)=x6. If the xi are distinct, X is one-to-one: essentially the same as the sample space. But the xi need not be distinct: for instance the random variable E with E(2)=E(4)=E(6)=1 and E(1)=E(3)=E(5)=0.
Random variables and events
If X is a random variable, then (X<x)={s∈S:X(s)<x} is an event for every real x. So (X<x), (X=x), (X≤x), (X≥x) are all events.
Figure 34. On a die with X(i) = i: events described through X
X=1: the event "die shows 1". X<4: the event {1,2,3}. Any event can be expressed in terms of X; e.g. the event {2,5} is (X=2)∪(X=5).
Why random variables?
For one IPL powerplay over, several random variables can be defined: number of runs, number of actual deliveries, number of wickets, number of boundaries, number of dot balls, and so on.
Instead of assigning probabilities to entire outcomes, we study random variables and assign probabilities to events defined through them.
This reduces the detail in the outcome to something simpler. With limited data, only such random variables can realistically be studied.
8.2Range and discrete random variables
Definitions
The range of a random variable is the set of values taken by it: a subset of the real line. Given a random variable\'s definition, the first task is always to find its range. A random variable is discrete if its range is a discrete set.
Throw a die, X = number shown: range ={1,2,3,4,5,6}.
E=0 if odd, 1 if even: range ={0,1}.
8.3PMF and its properties
Definition: probability mass function
The PMF of a discrete random variable X with range T is the function fX:T→[0,1], fX(t)=P(X=t) for t∈T. Here (X=t) is an event: P(X=t)=P(all outcomes that result in X taking value t).
For a subset B of T, the event (X∈B) has probability P(X∈B)=∑t∈BP(X=t)=∑t∈BfX(t).
Properties of a PMF
0≤fX(t)≤1t∈T∑fX(t)=1
Often, random variables and their PMFs are studied without much mention of the experiment or sample space: events are defined using random variables, and probabilities are evaluated using the PMF.
Example: fair coin flipped 3 times
Let X = number of heads, Y = which flip first shows a head (0 stands for "none").
Figure 35. Two different random variables on the same experiment
Example: working with a partial PMF
t
−1
1
2
4
f_X(t)
0.5
0.25
0.125
?
(a) 0.5+0.25+0.125+fX(4)=1⇒fX(4)=0.125.
(b) Range of X={−1,1,2,4}.
(c) P(X>3)=P(X=4)=0.125.
(d) P(X<23)=P(X=1)+P(X=−1)=0.25+0.5=0.75.
Figure 36. Use "the PMF adds to 1" to fill in the missing value
Example: a PMF given by a formula
fX(k)=3kc for k=1,2,3,… Find c, P(X>10), and P(X>10∣X>5).
(a) Find c: the terms form a GP with first term 31: c[31+91+271+⋯]=c⋅1−1/31/3=2c=1, so c=2.
(b) P(X>10)=3112+3122+⋯=2⋅1−1/31/311=3101.
(c) Since (X>10)⊆(X>5): P(X>10∣X>5)=P(X>5)P(X>10)=1/351/310=351.
Figure 37. f(k) = 2/3^k: the tail P(X > 10) is tiny
Memoryless.P(X>10∣X>5)=P(X>5): this is exactly a geometric distribution with p=32 (P(X=k)=(31)k−1⋅32), and geometric random variables "forget" how long they have already waited.
Example 15Build a PMF
Two fair coins are tossed. Let X = number of heads. Find the range and the PMF of X, and P(X≥1).
Solution
t
0
1
2
f_X(t)
1/4
2/4
1/4
Range {0,1,2}; fX adds to 1 ✓. P(X≥1)=42+41=43 (or 1−fX(0)).
Example 16Is it a valid PMF?
Which of these can be a PMF on {1,2,3}? (a) (0.2,0.5,0.3) (b) (0.4,0.4,0.4) (c) (0.6,−0.1,0.5) (d) (0.5,0.25,0.2).
Solution
Option
Check
Valid?
(a)
0.2+0.5+0.3=1, all in [0,1]
Yes
(b)
sum =1.2
No
(c)
a negative value −0.1
No
(d)
sum =0.95
No
Revision overview
Random variableFunction: sample space → ℝ Numbers computed from outcomes
Events from X(X < x), (X = x), (X ≤ x), (X ≥ x) are events
Why use themSimplify the outcome Work with limited data
Random Variables and PMFsWeek 0 · Part 8
Range, discreteRange = values taken (first task) Discrete: range is a discrete set
PMFf_X(t) = P(X = t) P(X ∈ B) = Σ f_X(t)
Properties0 ≤ f_X(t) ≤ 1 Σ f_X(t) = 1 Use it to find a missing value
Seven named distributions cover most situations in the course. For each one: its range, its PMF, and the story it tells. The Poisson distribution gets its own application.
The symbol ∼ reads as "is distributed as". Seven standard distributions are used throughout the course.
Figure 38. The standard distributions and what each one counts
9.1Uniform random variable
X∼Uniform(T), where T is some finite set.
Range: the finite set T.
PMF:fX(t)=∣T∣1 for all t∈T (∣T∣ is the size of T).
Toss a fair coin: X∼Uniform({0,1}), where 0 = head, 1 = tail. Throw a fair die: X∼Uniform({1,…,6}).
9.2Bernoulli random variable
X∼Bernoulli(p), 0≤p≤1.
Range:{0,1}.
PMF:fX(0)=1−p, fX(1)=p.
Example: a Bernoulli trial, where p is the probability of success.
9.3Binomial random variable
X∼Binomial(n,p), n a positive integer, 0≤p≤1.
Range:{0,1,2,…,n}.
PMF:fX(k)=(kn)pk(1−p)n−k.
Meaning: the number of successes in n independent Bernoulli(p) trials. Validity check: every term is ≥0 and ∑k(kn)pk(1−p)n−k=1.
9.4Geometric random variable
X∼Geometric(p), 0<p≤1.
Range:{1,2,3,…}.
PMF:fX(k)=(1−p)k−1p.
Meaning: the number of trials needed for the first success. Validity check: use the sum of a GP.
On the range of p. The source writes 0≤p≤1, but for p=0 the first success never comes (the PMF would be 0 everywhere and not add to 1), so we need p>0.
9.5Negative binomial random variable
A generalisation of the geometric random variable.
X∼Negative Binomial(r,p), r a positive integer, 0<p≤1.
Range:{r,r+1,r+2,…}.
PMF:fX(k)=(r−1k−1)(1−p)k−rpr.
Meaning: the number of trials needed for the r-th success in repeated independent Bernoulli(p) trials. r=1 gives exactly the geometric random variable.
Why this PMF. The r-th success lands exactly on trial k: the last trial is a success, and the earlier k−1 trials contain exactly r−1 successes, which can be placed in (r−1k−1) ways.
9.6Poisson random variable
X∼Poisson(λ), where λ>0 is a real parameter.
Range:{0,1,2,3,…}.
PMF:fX(k)=k!e−λλk.
Validity check:eλ=1+λ+2!λ2+3!λ3+⋯, so ∑kk!e−λλk=e−λeλ=1.
k
0
1
2
3
4
fX(k)
e−λ
e−λλ
e−λλ2/2
e−λλ3/6
e−λλ4/24
9.7Hypergeometric random variable
A population of N persons, with r of Type 1 and N−r of Type 2. Select m persons uniformly at random without replacement. X = number of Type 1 persons selected: X∼HyperGeo(N,r,m).
Range:max(0,m−(N−r))…min(r,m).
PMF:fX(k)=(mN)(kr)(m−kN−r).
Figure 39. Three range examples
N=100,r=50,m=20: X∈{0,1,…,20}.
N=100,r=10,m=20: X∈{0,1,…,10}.
N=100,r=90,m=20: X∈{10,11,…,20}. The last case has a non-zero lower bound: with only 10 Type-2 people available, at least 10 of your 20 picks must be Type 1.
9.8Application of the Poisson random variable
Events occurring over a period of time: arrival of a person to a booking-counter queue, arrival of a visitor to a website, emission of a particle by radioactive decay, a meteorite entering the earth's atmosphere.
What do these have in common?
The arrival rate can be assumed constant.
Given one arrival, the time to the next arrival can be assumed independent of the past.
Under these assumptions, the number of arrivals in a fixed period becomes a Poisson random variable.
Example: radioactive decay
In 2608 time intervals of 7.5 seconds each, emissions of alpha particles were recorded. The source table below is cut off at 8 particles:
Particles
0
1
2
3
4
5
6
7
8
Intervals
57
203
383
525
532
408
273
139
45
Fraction
0.022
0.078
0.147
0.201
0.204
0.156
0.105
0.053
0.017
The table is incomplete. Those counts add up to only 2565, not 2608. The remaining 43 intervals had 9, 10 or 11+ particles (27, 10 and 6 intervals in the full data). Using only the printed rows would give a mean of 3.71; with all 2608 intervals the emission rate is λ=2608total particles≈3.87 (the notes quote 3.8673).
λ=2608total number of particles≈3.87,P(number of particles=k)=k!e−λλk
Figure 40. Observed fractions (bars) against the Poisson model (line)
The time of the next emission is independent of the past, and the observed fractions are close to the probabilities predicted by the Poisson model, as the figure shows.
Example 17Pick the distribution
Name the distribution: (a) number of heads in 8 tosses; (b) number of tosses to get the 3rd head; (c) number of calls arriving at a help desk in an hour; (d) 5 cards drawn without replacement, number of aces; (e) a fair die, the number shown.
Solution
Situation
Distribution
(a)
Binomial(8,21)
(b)
Negative Binomial(3,21)
(c)
Poisson(λ)
(d)
HyperGeo(52,4,5)
(e)
Uniform({1,…,6})
Example 18Poisson probabilities
A website gets visitors at a constant rate of 2 per minute, so the number of visitors in a minute is Poisson(2). Find the probability of exactly 0, 1 and 2 visitors, and of at least one visitor.
Solution
P(0)=e−2≈0.1353.
P(1)=2e−2≈0.2707.
P(2)=24e−2=2e−2≈0.2707.
P(≥1)=1−e−2≈0.8647.
Example 19Hypergeometric probability
An urn has 6 red and 4 blue marbles. 3 are drawn without replacement. Find the probability that exactly 2 are red.
Applying a function to a random variable gives a new random variable. The only task is to find its PMF: group the values that the function sends to the same place and add their probabilities.
10.1A function of a random variable
X is a random variable with range T and PMF fX(t). X is a function from the sample space to T; T is a subset of the real line.
Let f(x) be a function from the real line to the real line. Then f(X) is a composition of two functions: sample space →T→ real line.
So f(X) is also a random variable in the same probability space.
To find the PMF of f(X) at a value a, collect every t in the range of X that f maps to a, and add up their probabilities.
Figure 41. X uniform on {−1, 0, 1, 2}, f(X) = X²: the values −1 and 1 both land on 1
Worked example
Let X take the values −1,0,1,2, each with probability 41. Find the PMF of Y=X2.
Value of Y
t with t² equal to it
fY
0
t=0
41
1
t=−1,1
41+41=21
4
t=2
41
Check.41+21+41=1. Notice the range shrank from 4 values to 3: when f is not one-to-one, different values of X merge into one value of f(X) and their probabilities add.
Links to Maths Week 1. This is exactly "injective or not": a one-to-one f keeps every value separate (the PMF is just relabelled), a many-to-one f adds probabilities.
Example 20PMF of 2X + 1
X has PMF fX(0)=0.2, fX(1)=0.5, fX(2)=0.3. Find the PMF of Y=2X+1.
Solution
Y
1
3
5
fY
0.2
0.5
0.3
f(x)=2x+1 is one-to-one, so each value of Y comes from exactly one t and the probabilities are simply carried over.
Example 21A many-to-one function
X is the number shown on a fair die. Let Y=(X−3)2. Find the PMF of Y.
Solution
X
1
2
3
4
5
6
Y=(X−3)2
4
1
0
1
4
9
Y
0
1
4
9
fY
61
62
62
61
Sum =61+2+2+1=1 ✓.
Revision overview
Ideaf(X) is a composition: sample space → T → ℝ So f(X) is a random variable
Formulaf_{f(X)}(a) = P(X ∈ {t : f(t) = a}) = Σ f_X(t) over f(t) = a
Functions of a Random VariableWeek 0 · Part 10
How to use itCollect every t that f sends to a Add their probabilities