1 of 88

1

Lecture 3:

Independence

Chris Gregg

Summer 2026

2 of 88

Learning Goals of Today

Mutually Exclusive

Independent

Makes AND easy:

Makes OR easy:

3 of 88

Review

4 of 88

Notation

4

And

Or

Given

5 of 88

Relationship Between Probabilities

5

 

 

Law of Total�Probability

Definition of�conditional probability

Chain rule�(Product rule)

 

 

Bayes’�Theorem

6 of 88

Review: Chain Rule

Piech, CS109, Stanford University

Definition of conditional probability:

The Chain Rule:

10

7 of 88

Bayes’ Theorem

7

 

 

 

8 of 88

SARS Virus Testing

  • A test is 98% effective at detecting SARS (*the test comes back positive for someone who has SARS)
    • However, test has a false positive rate of 1%
    • 0.5% of US population has SARS
    • Let E = you test positive for SARS with this test
    • Let F = you actually have SARS
    • What is P(F | E)?
  • Solution:

P(E | F) P(F) + P(E | Fc) P(Fc)

P(F | E) =

P(E | F) P(F)

(0.98)(0.005) + (0.01)(1 - 0.005)

P(F | E) =

(0.98)(0.005)

≈ 0.330

9 of 88

Bayes’ Theorem and Spam

  •  

9

posterior

likelihood

prior

 

 

normalization constant

    • 60% of all email in 2016 is spam.
    • 20% of spam has the word “Dear”
    • 1% of non-spam (aka ham) has the word “Dear”

You get an email with the word “Dear” in it.

What is the probability that the email is spam?

 

10 of 88

Bayes’ Theorem and Spam

10

 

 

    • 60% of all email in 2016 is spam.
    • 20% of spam has the word “Dear”
    • 1% of non-spam (aka ham) has the word “Dear”

You get an email with the word “Dear” in it.

What is the probability that the email is spam?

 

11 of 88

Bayes’ Theorem and Spam

11

 

 

    • 60% of all email in 2016 is spam.
    • 20% of spam has the word “Dear”
    • 1% of non-spam (aka ham) has the word “Dear”

You get an email with the word “Dear” in it.

What is the probability that the email is spam?

 

.2

.6

.2

.6

.01

(1-0.6)

= 0.968

12 of 88

Intuition Time

13 of 88

Bayes Theorem Intuition

All People

14 of 88

Bayes Theorem Intuition

All People

People with SARS

15 of 88

Bayes Theorem Intuition

All People

People who test positive

16 of 88

Bayes Theorem Intuition

All People

People with SARS

People who test positive

17 of 88

Bayes Theorem Intuition

Conditioning on a positive result changes the sample space to this:

≈ 0.330

People who test positive

People who test positive and have SARS

18 of 88

Bayes Theorem Intuition

Conditioning on a positive result changes the sample space to this:

≈ 0.330

People who test positive

P(F)P(E|F)

P(F)P(E|F) +

P(Fc)P(E|Fc)

People who test positive and have SARS

Let E = you test positive for SARS with this test

Let F = you actually have SARS

19 of 88

Bayes Theorem Intuition

All People

People with positive

test

People with SARS

20 of 88

Bayes Theorem Intuition

Say we have 1000 people:

5 have SARS and test positive, 985 do not have SARS and test negative.

10 do not have SARS and test positive.

≈ 0.333

21 of 88

Bayes Theorem Intuition

Conditioned on just those that test positive:

5 have SARS and test positive, 985 do not have SARS and test negative.

10 do not have SARS and test positive.

≈ 0.333

Notice that all the people with SARS are here, but the group is still mainly folks without SARS

22 of 88

Why it is still good to get tested

    • Let Ec = you test negative for SARS with this test
    • Let F = you actually have SARS
    • What is P(F | Ec)?

P(Ec | F) P(F) + P(Ec | Fc) P(Fc)

P(F | Ec) =

P(Ec | F) P(F)

(0.02)(0.005) + (0.99)(1 - 0.005)

P(F | Ec) =

(0.02)(0.005)

≈ 0.0001

SARS + (F)

SARS – (Fc)

Test + (E)

0.98 = P(E | F)

0.01 = P(E | Fc)

Test – (Ec)

0.02 = P(Ec | F)

0.99 = P(Ec | Fc)

23 of 88

End Review

24 of 88

Law of Total Probability

Sample Space

F

E

FC

25 of 88

Law of Total Probability

Spam

Not Spam

Sample Space

Email

F

E

FC

26 of 88

Law of Total Probability

B1

B2

Sample Space

E

B3

B4

 

Thm

are mutually exclusive

partition events:

27 of 88

Background event. Where is the person in San Francisco?

San Francisco, CA

28 of 88

Background event. Where is the person in San Francisco?

San Francisco, CA

From Google’s Perspective:

There are 18 different “districts” in San Francisco.

Know:

Want:

It rains tomorrow

Person is in district i

29 of 88

Background event. Where is the person in San Francisco?

San Francisco, CA

From Google’s Perspective:

There are 18 different “districts” in San Francisco.

Know:

Want:

Mission District

Presidio

SOMA

0.23

0.84

0.52

0.15

0.02

0.24

30 of 88

Background event. Where is the person in San Francisco?

San Francisco, CA

From Google’s Perspective:

There are 18 different “districts” in San Francisco.

Know:

Want:

Mission District

Presidio

SOMA

0.23

0.84

0.52

0.15

0.02

0.24

31 of 88

Monty Hall Problem

31

32 of 88

Monty Hall Problem

32

33 of 88

Monty Hall Problem from Let’s Make a Deal

  • Behind one door is a prize (equally likely to be any door).
  • Behind the other two doors is nothing
  • We choose a door
  • Host opens 1 of other 2 doors, revealing nothing
  • We are given an option to change to the other door.
  • Should we switch?

Doors A,B,C

Note: If we don’t switch,

P(Win) = 1/3

34 of 88

In the world where we switch

A: Prize in Door A

    • Host opens B or C
    • We switch
    • We always lose
  • P(Win | A) = 0

B: Prize in Door B

    • Host must open C
    • We switch to B
    • We always win
  • P(Win | B) = 1

C: Prize in Door C

    • Host must open B
    • We switch to C
    • We always win
  • P(Win | C) = 1

34

Without loss of generality, say we pick A (out of Doors A,B,C).

1/3

1/3

1/3

You should switch!

35 of 88

Marilyn Vos Savant

35

36 of 88

Monty Hall, 1000 envelope version

  • Start with 1000 envelopes (of which 1 is the prize).
  • You choose 1 envelope.�
  • I open 998 of remaining�999 (showing they are empty).��
  • Should you�switch?

36

No: P(win without switching) =

Yes: P(win with new knowledge) =

1

original # envelopes

original # envelopes - 1

original # envelopes

 

37 of 88

Learning Goals for Rest of Today

Mutually Exclusive

Independent

Makes AND easy:

Makes OR easy:

38 of 88

Probability of “OR”

39 of 88

Review: OR with Mutually Exclusive Events

P (E [ F ) = P (E) + P (F )

If events are mutually exclusive, probability of OR is simple:

7/50

4/50

40 of 88

Review: OR with Mutually Exclusive Events

If events are mutually exclusive, probability of OR is simple:

7 4 11

P (E [ F ) = 50 + 5 =

7/50

4/50

Piech, CS109, Stanford Uversity

41 of 88

What about when they are not

Mutually exclusive?

42 of 88

AKA

Inclusion Exclusion

OR without Mutually Exclusive Events

43 of 88

AKA

Inclusion Exclusion

OR without Mutually Exclusive Events

44 of 88

More than two sets?

45 of 88

Inclusion / Exclusion with Three Events

E

F

G

P (E or F or G) =

or

46 of 88

Inclusion / Exclusion with Three Events

E

1

F

G

Piech, CS109, Stanford University

1

1

1

P (E [ F [ G) = P (E)

or

or

47 of 88

Inclusion / Exclusion with Three Events

E

1

F

G

Piech, CS109, Stanford University

2

1

2

1

1

P (E [ F [ G) = P (E) + P (F )

or

or

48 of 88

Inclusion / Exclusion with Three Events

E

1

F

G

Piech, CS109, Stanford University

2

1

2

1

1

P (E [ F [ G) = P (E) + P (F )

or

or

1

2

3

2

49 of 88

Inclusion / Exclusion with Three Events

E

1

2

2

3

1

1

2

F

G

Piech, CS109, Stanford University

P (E [ F [ G) = P (E) + P (F ) + P (G)

or

or

50 of 88

Inclusion / Exclusion with Three Events

P (E [ F [ G) = P (E) + P (F ) + P (G)

P (EF )

E 1

1

2

2

1

1

2

F

G

Piech, CS109, Stanford University

or

or

51 of 88

Inclusion / Exclusion with Three Events

1

1

1

2

F

G

Piech, CS109, Stanford University

1

1

P (E [ F [ G) = P (E) + P (F ) + P (G)

P (EF ) P (EG)

E 1

or

or

52 of 88

Inclusion / Exclusion with Three Events

E

Piech, CS109, Stanford University

F

G

1

1

1

1

1

1

1

P (E [ F [ G) = P (E) + P (F ) + P (G)

P (EF ) P (EG) P (FG)

+P (EFG)

or

or

53 of 88

Inclusion / Exclusion with 3 Events

54 of 88

Inclusion / Exclusion with 4 Events

55 of 88

General Inclusion / Exclusion

n

Piech, CS109, Stanford University

P (E1 [ E2 [ · · · [ E ) =

n

X

r=1

X

r+1

(1) Y

r

* Where Yr is the sum, for all combinations of r events, of the probability of the union those events.

Y1 = Sum of all events on their own

i

i

P (E )

X

i,j,k

P (Ei \ Ej \ Ek)

s.t.i =6 j, j 6= k, i =6 k

X

i,j

P (Ei \ Ej )

s.t.i =6 j

Y2 = Sum of all pairs of events

Y3 = Sum of all triples of events

Where Yr is the sum, for all combinations of r events, of the probability of the intersection of those events

or

or

and

and

and

56 of 88

Learning Goals of Today

Mutually Exclusive

Independent

Makes AND easy:

Makes OR easy:

57 of 88

Probability of “AND”

58 of 88

Piech, CS109, Stanford University

59 of 88

Independence

Two events A and B are called independent if:

Piech, CS109, Stanford University

Otherwise, they are called dependent events

Knowing that event B happened, doesn’t change our belief that A will happen.

60 of 88

Alternative Definition of Independence

Piech, CS109, Stanford University

Chain rule

Since B is independent of A

If you show this is true, you have proved the two events are independent!

Notation for and

61 of 88

If events are independent

probability of AND is easy!

*You will need to use this “trick” with high probability

62 of 88

Dice, our misunderstood friends

What is P(E), P(G), and P(E G)?

  • P(E) = 1/6, P(G) = 4/36 = 1/9, P(E G) = 1/36
  • P(E G) P(E) P(G) → E and G dependent

Piech, CS109, Stanford University

Roll two 6-sided dice, yielding values D1 and D2

  • Let E be event: D1 = 1
  • Let F be event: D2 = 1
  • Let G be event: D1 + D2 = 5

{(1, 4), (2, 3), (3, 2), (4, 1)}

What is P(E), P(F), and P(E F)?

  • P(E) = 1/6, P(F) = 1/6, P(E F) = 1/36
  • P(E F) = P(E) P(F) → E and F independent

63 of 88

Intuition through proofs:

64 of 88

Independence is reciprocal

If A is independent of B, then B is independent of A

Piech, CS109, Stanford University

Proof:

Bayes’ Thm.

Because A is independent of B

65 of 88

Independence

So if A and B are independent A and BC are also independent

Piech, CS109, Stanford University

Given independent events A and B, prove that A and BC are independent

We want to show that P( ABC) = P( A)P(BC)

P (ABC ) = P (A) P (AB)

= P (A) P (A)P (B)

= P (A)[1 P (B)]

= P (A)P (BC )

By Total Law of Prob.

By independence Factoring

Since P(B) + P(BC) = 1

Independence of a complement

66 of 88

What does independence look like?

67 of 88

Independence

A

B

S

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 1:

P (AB) = P (A)P (B)

0

Piech, CS109, Stanford University

68 of 88

Independence

A

B

S

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 1:

P (AB) = P (A)P (B)

0

Piech, CS109, Stanford University

Not independence!

69 of 88

Independence

A

B

S

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 1:

P (AB) = P (A)P (B)

0

Piech, CS109, Stanford University

Not independence!

This is mutual exclusion!

70 of 88

Independence

A

Piech, CS109, Stanford University

B

AB

S

Independence Definition 1:

P (AB) = P (A)P (B)

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 2:

P (A|B) = P (A)

|AB| = |A|

|B| |S|

71 of 88

Independence

A

S

B

Piech, CS109, Stanford University

AB

This ratio, P(A)…

… is the same as this one, P(A|B)

72 of 88

Independence

A

Piech, CS109, Stanford University

B

AB

S

Independence Definition 1:

P (AB) = P (A)P (B)

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 2:

P (A|B) = P (A)

|AB| = |A|

|B| |S|

73 of 88

Dependence

A

|AB|

|B|

|A|

|S|

=

Piech, CS109, Stanford University

B

AB

S

Independence Definition 1:

P (AB) = P (A)P (B)

|AB| = |A| |B|

|S| |S| |S|

Independence Definition 2:

P (A|B) = P (A)

74 of 88

Generalized Independence

Piech, CS109, Stanford University

General definition of Independence:

Events E1 , E2 , ..., En are independent if for every subset

with r elements (where r n) it holds that:

Example: outcomes of n separate flips of a coin are all independent of one another

  • Each flip in this case is called a “trial” of the experiment

75 of 88

Math > Intuition

76 of 88

Two Dice

Piech, CS109, Stanford University

Roll two 6-sided dice, yielding values D1 and D2

  • Let E be event: D1 = 1
  • Let F be event: D2 = 6
  • Let G be event: D1 + D2 = 7

2. Are E and G independent?

  • P(E) = 1/6, P(G) = 1/6,

P(E G) = 1/36

[roll (1, 6)]

  • P(F) = 1/6, P(G) = 1/6, P(F G) = 1/36

[roll (1, 6)]

Yes!

1. Are E and F independent?

3. Are F and G independent?

4. Are E, F and G independent?

  • P(E F G) = 1/36 ≠ 1/216 = (1/6)(1/6)(1/6)

Yes!

Yes!

No!

When you impose a 1 and a 6, the sum is redundant

77 of 88

New Ability

78 of 88

Properties of Pairs of Events

Mutually Exclusive

Independent

also:

also:

79 of 88

Story: Ultimate Probability

https://www.maikaisogawa.com/ultimate-frisbee-probability/

80 of 88

Practice: Lets do the Frisbee Problem.

  • You flip two frisbees. For each frisbee, the probability that it lands “heads” is 0.6. The two frisbees are considered “even” if both frisbees are heads or both frisbees are tails.
  • What is the probability that the frisbees are even?

80

81 of 88

Same Problem!

81

Let p be the probability of a 1 from unknown_random.

What is the probability of a True from fair_random if p =.45?

82 of 88

Network reliability

82

Consider the following parallel network:

  • 𝑛 independent routers, each with

probability 𝑝i of functioning (where 1 ≤ 𝑖 ≤ 𝑛)

  • 𝐸 = functional path from A to B exists.

What is P(E)?

𝑝1

𝑝2

𝑝𝑛

𝐴

𝐵

Piech, CS109, Stanford University

83 of 88

Network reliability

83

Consider the following parallel network:

  • 𝑛 independent routers, each with

probability 𝑝i of functioning (where 1 ≤ 𝑖 ≤ 𝑛)

  • 𝐸 = functional path from A to B exists.

What is P(E)?

𝑝1

𝑝2

𝑝𝑛

𝐴

𝐵

Piech, CS109, Stanford University

84 of 88

Network reliability

84

Consider the following parallel network:

  • 𝑛 independent routers, each with

probability 𝑝i of functioning (where 1 ≤ 𝑖 ≤ 𝑛)

  • 𝐸 = functional path from A to B exists.

What is P(E)?

𝑝1

𝑝2

𝑝𝑛

𝐴

𝐵

Piech, CS109, Stanford University

85 of 88

Network reliability

85

Consider the following parallel network:

  • 𝑛 independent routers, each with

probability 𝑝i of functioning (where 1 ≤ 𝑖 ≤ 𝑛)

  • 𝐸 = functional path from A to B exists.

What is P(E)?

𝑝1

𝑝2

𝑝𝑛

𝐴

𝐵

Piech, CS109, Stanford University

86 of 88

Network reliability

86

Consider the following parallel network:

  • 𝑛 independent routers, each with

probability 𝑝i of functioning (where 1 ≤ 𝑖 ≤ 𝑛)

  • 𝐸 = functional path from A to B exists.

What is P(E)?

𝑝1

𝑝2

𝑝𝑛

𝐴

𝐵

Piech, CS109, Stanford University

87 of 88

Learning Goals of Today

Mutually Exclusive

Independent

Makes AND easy:

Makes OR easy:

88 of 88

Independence relationships can change with conditioning.

If E and F are independent, that does not mean they will still be independent given another event G.