Statistics for
Data Science 1
Conditional probability: contingency tables, the multiplication rule, independent events and their properties, the law of total probability and Bayes' rule.
Chapters
- 01Contingency Tables and Conditional ProbabilityLectures 7.1 and 7.2
- 02Multiplication RuleLecture 7.3
- 03Independent EventsLectures 7.4 to 7.6
- 04Law of Total Probability and Bayes' RuleLecture 7.7
- 05Week 8 Summary SheetAll lectures
Based on lectures by Usha Mohan, IIT Madras
Contingency Tables and Conditional Probability
Joint, marginal and conditional probabilities, and the formula for P(E | F).
1.1Contingency table
A contingency table sorts a sample by two categories at once (rows and columns). Dividing every count by the grand total turns it into a table of probabilities.
Example. A survey of 100 people, by gender and smartphone ownership:
| Not owning | Owning | Total | |
|---|---|---|---|
| Female | 10 | 34 | 44 |
| Male | 14 | 42 | 56 |
| Total | 24 | 76 | 100 |
1.2Joint, marginal and conditional probability
| Type | Where in the table | Example |
|---|---|---|
| Joint | a cell (both things at once) | P(Female ∩ Not owning) = 10/100 = 0.10; P(Male ∩ Owning) = 0.42 |
| Marginal | a row or column total (one thing only) | P(Female) = 44/100 = 0.44; P(Owning) = 0.76 |
| Conditional | restrict to one row or column | P(Not owning | Female) = 10/44 |
1.3Reading conditional probability from the table
"Given Female" means: look only at the Female row. That row is the new, smaller sample space (44 people). Count what you want inside it.
| Question | Restrict to | Answer |
|---|---|---|
| Among females, chance of not owning? | Female row (44) | 10/44 ≈ 0.227 |
| Among non-owners, chance of being female? | Not-owning column (24) | 10/24 ≈ 0.417 |
1.4Definition of conditional probability
For events E and F with , the probability of E given F is
Check with the table: , the same answer as counting in the row.
Example 1: sum is 10, given the first roll is 4
A die is rolled twice (36 equally likely outcomes). Find the probability that the sum is 10 given that the first roll is 4.
- F = first roll is 4 = {(4,1), (4,2), ..., (4,6)}, so P(F) = 6/36.
- E = sum is 10. Within F only (4,6) works, so .
- . Directly: of the 6 outcomes in F, one gives sum 10.
- Answer: 1/6.
1.5Going deeper
- is not . From the same cell: P(Not owning | Female) = 10/44 ≈ 0.227 but P(Female | Not owning) = 10/24 ≈ 0.417. Different groups are restricted to, so the numbers differ.
- Conditional probabilities in one row add to 1. 10/44 + 34/44 = 1: once you restrict to F, F is the whole sample space, so all the axioms of Week 7 still hold.
- Without the table (extra remark). Compare P(sum 10) = 3/36 = 1/12 with P(sum 10 | first is 4) = 1/6. Knowing the first roll doubled the chance, because 4 is a roll from which 10 is still reachable.
- A look ahead (extra remark). P(Owning | Female) = 34/44 ≈ 0.773 and P(Owning | Male) = 42/56 = 0.75 are close but not equal, so in this sample ownership is not exactly independent of gender (Chapter 3).
- Underline the word after "given" or "among": that is the group you restrict to.
- Use counts directly when you have a table: cell over row or column total.
- Dividing by the grand total instead of the row or column total.
- Swapping and .
Multiplication Rule
P(E ∩ F) = P(F) P(E | F), the generalized rule, and two lecture examples.
Rearranging the conditional probability formula tells us how to find the chance that both things happen: first F, then E given F.
Multiply both sides of by :
The probability that both E and F occur equals the probability that F occurs times the conditional probability of E given F. It is the tool for the probability of an intersection.
2.1Generalized multiplication rule
Multiply step by step, each event conditioned on all the ones before it:
Example 2: two students, without replacement
A class of 40 has 23 males and 17 females. Two students are chosen at random, the first not returned. Find the probability that the first is female and the second is male.
- P(first is female) = 17/40.
- Given the first was female, 39 students remain and 23 are male: P(second male | first female) = 23/39.
- Answer: ≈ 0.251.
Example 3: each pile gets exactly one ace
A deck of 52 cards is randomly divided into 4 piles of 13. Find the probability that each pile has exactly one ace.
- Let = the ace of spades is in some pile; = the spade and heart aces are in different piles; = spade, heart and diamond aces in different piles; = all four aces in different piles. We need .
- .
- : of the other 51 cards, 39 are in the three piles without the ace of spades.
- : of the remaining 50 cards, 26 are in the two piles with no ace yet.
- : 13 of the last 49 cards are in the one empty pile.
- Product:
- Answer: ≈ 0.105.
When an item is not returned, the counts and the total change for the next draw. That is exactly why the second factor is a conditional probability.
2.2Going deeper
- With replacement (extra remark). If the first student were returned, the second factor would stay 23/40 and the answer would be 17/40 × 23/40 = 391/1600 ≈ 0.244, slightly smaller.
- Either order works. . Pick the order in which the conditional probabilities are easy to read, usually the time order.
- Why not just 1/4 × 1/4 ...? The aces are not placed independently: once a pile has an ace, fewer places are left in it. The conditional factors carry exactly this information.
- Draw a small tree and multiply along the path you want.
- After each draw without replacement, update both the count and the total.
- Using 23/40 for the second draw when the first student was not returned.
- Forgetting when the first step is always possible.
Independent Events
Definition and tests with dice and cards, E and Fᶜ, and three or more events.
3.1Idea and definition
E is independent of F if knowing that F happened does not change the chance of E: . Since , this gives .
Two events E and F are independent if
Events that are not independent are dependent. The rule works both ways: independent ⇒ product rule, and product rule ⇒ independent.
3.2Example: rolling a die twice
Example 4: dice: dependent or independent?
S has 36 outcomes. : first outcome is 3. : sum is 8. : sum is 7. Are independent? Are ?
- . = {(2,6), (3,5), (4,4), (5,3), (6,2)}, so . has six pairs, .
- = {(3,5)}: 1/36, but . Not equal: dependent.
- = {(3,4)}: 1/36, and . Equal: independent.
- Answer: E1, E2 dependent; E1, E3 independent.
Why? Whatever the first roll is, exactly one second roll makes the sum 7, so the first roll tells you nothing about "sum 7". For sum 8 it does: if the first roll were 1, a sum of 8 would be impossible.
3.3Example: a deck of cards
Example 5: cards: dependent or independent?
One card from 52. : a face card (J, Q, K, so 12 cards). : a king (4 cards). : a heart (13 cards).
- : face and king = king, probability 4/52. Product . Not equal: dependent (a king is always a face card).
- : king of hearts, 1/52. Product . Equal: independent.
- Answer: (face, king) dependent; (king, heart) independent.
Compute , compute , compare. Equal means independent. Also check the intuition: does knowing F change the chance of E?
3.4Independence of E and Fc
If E and F are independent, then E and are also independent.
Proof. Write . The two parts are mutually exclusive, so . By independence , so . ∎
So if E is independent of F, the chance of E is unchanged by knowing whether or not F occurred. Check with cards (extra remark): king and "not a heart" gives 3/52, and .
3.5More than two events
E, F, G are independent if all four hold:
For independent events, the probability that all of them occur is the product of their individual probabilities.
Example 6: three children
A couple plans three children. Each child is equally likely to be a boy or a girl, and the sexes are independent. Find the probability that all three are girls.
- = the i-th child is a girl; .
- Independence: .
- Answer: 1/8.
3.6Going deeper
- Pairwise is not enough (extra remark). In the warning example all three pairs are independent: each pair intersection has probability 1/36 = 1/6 × 1/6. But , not 1/216. That is why the definition needs condition 1 as well.
- Independent is not mutually exclusive (extra remark). Mutually exclusive events cannot happen together, so knowing one happened tells you the other did not: that is strong dependence. King and heart are independent but not mutually exclusive.
- Where independence comes from. In the dice and children examples it is an assumption about the experiment (separate rolls, separate births); in the cards example it is checked by counting.
- Always test with numbers: against .
- For three events check all four conditions.
- Calling disjoint events independent.
- Multiplying probabilities of events that are not independent.
Law of Total Probability and Bayes' Rule
Splitting into cases, the probability tree, and reasoning backwards from an event.
4.1Law of total probability
To find the chance of E, split the world into cases (F happens, F does not), find the chance of E in each case, and take a weighted average, weighting each case by how likely it is.
E can be written as : an outcome in E is either in F as well, or not. These parts are mutually exclusive (Figure 6), so
If are mutually exclusive and exhaustive (exactly one of them occurs), then for any event E
4.2Example: insurance policy
People are either accident-prone or not. An accident-prone person has an accident in a year with probability 0.1; others with probability 0.05. A new policyholder is accident-prone with probability 0.2. Let E = has an accident in the first year, F = is accident-prone. Given: P(F) = 0.2, P(E | F) = 0.1, .
Each branch carries a probability; multiply along a path to get the joint probability at its end. The four end values 0.02, 0.18, 0.04, 0.76 add up to 1. The two paths ending in an accident add to P(E).
Example 7: chance of an accident in year one
Find P(E).
- .
- .
- Answer: 0.06, that is 6 percent.
4.3Bayes' rule
Total probability goes from causes to effect: P(E). Bayes' rule goes backwards: given that E happened, how likely is each cause?
Start from ; use the multiplication rule on the top and total probability on the bottom:
For mutually exclusive and exhaustive and any event E,
Example 8: is the policyholder accident-prone?
A new policyholder has an accident in the first year. What is the probability that he or she is accident-prone?
- From Example 7, P(E) = 0.06.
- Answer: 1/3.
Accident-prone people are only 20% of policyholders, so even though they have more accidents, most accidents (0.04 of the 0.06) still come from the other 80%. The prior 0.2 rises to 1/3 after seeing an accident.
4.4Going deeper
- Bayes is just a share of the tree. P(F | E) = (the E-path through F) ÷ (all E-paths) = 0.02 / (0.02 + 0.04). Draw the tree and Bayes needs no extra formula.
- Again, P(E | F) ≠ P(F | E). P(accident | prone) = 0.1 but P(prone | accident) = 1/3. Confusing the two is the most common Bayes mistake.
- Total probability is an average (extra remark). 0.06 lies between 0.05 and 0.1, closer to 0.05 because that case has weight 0.8. P(E) must always lie between the smallest and largest .
- The cases must cover everything once. F and always do; with more cases check that the add to 1.
- Write the given numbers as P(F), P(E | F), P(E | Fᶜ) before calculating.
- Check: the tree's end values add to 1.
- Forgetting the branch in the denominator.
- Reporting P(E | F) when the question asks P(F | E).
Week 8 Summary Sheet
Everything in Week 8 on one sheet.
Lectures 7.1 to 7.7 on one sheet, for a last-minute revision.
All formulas in one table
| Idea | Formula |
|---|---|
| Conditional probability | , |
| Multiplication rule | |
| Generalized | |
| Independent events | , equivalently |
| Complement | E, F independent ⇒ E, independent |
| Three events | triple product and all three pair products |
| Total probability | |
| Bayes' rule |
Formula sheet at a glance
Formulas
Use whenThe question says "given", "among" or "if we know".
- Identify the group after the bar.
- Restrict to it (row, column, or outcomes in F).
- Count or divide inside it.
Use whenBoth events happen, often one after another, without replacement.
- Write the events in time order.
- Multiply the first probability by each conditional one.
- Update counts after each draw.
Use whenYou must decide whether two events affect each other.
- Find P(E), P(F) and P(E ∩ F).
- Multiply P(E) P(F).
- Equal: independent. Otherwise dependent.
Use whenSeveral cases lead to one event; or you see the event and ask about the case.
- Draw the tree with P(F) and P(E | F) branches.
- Add the paths ending in E: P(E).
- For Bayes, divide the path you want by P(E).
Values worked in the lectures
| Question | Answer |
|---|---|
| Survey: P(Not owning | Female), P(Female | Not owning) | 10/44, 10/24 |
| Two dice: P(sum 10 | first is 4) | 1/6 |
| Class of 40: P(female then male) | ≈ 0.251 |
| Piles: each has exactly one ace | ≈ 0.105 |
| Dice: (E1, E2) / (E1, E3) independent? | no / yes |
| Cards: (face, king) / (king, heart) independent? | no / yes |
| Three girls | 1/8 |
| Insurance: P(accident), P(prone | accident) | 0.06, 1/3 |
How to decide
- "Given ..." → conditional: restrict to the given group.
- "Both" or "then" → multiplication rule; update counts if there is no replacement.
- Independence test: compare with .
- Several cases leading to one event → total probability; going backwards from the event → Bayes.
- The lectures are numbered 7.1 to 7.7; these are the Week 8 notes.
- Lecture 7.7 is titled "Bayes' Rule" on its first slide but its file name says "Law of total probability"; both topics are in it.
- In the cards independence check the slide writes where it means .
- Several slides are images (Venn diagrams, set listings); values here come from the slide text and the definitions, each checked by computation.
- The source's extra practice questions are not reproduced, as the Statistics 1 notes carry worked examples only.
Restrict to row or column
Dice: 1/6
Update counts
Students 0.251, aces 0.105
King, heart: yes
E, Fc also independent
Pairwise is not enough
Three girls: 1/8
Tree: add E paths
Insurance: 0.06
Path ÷ all E paths
Prone | accident: 1/3