L16 RandomVariables ExpectedValue F20
L16 RandomVariables ExpectedValue F20
L16 RandomVariables ExpectedValue F20
U
E
F
Plugging in:
€
Useful Identities to remember
• We can show that the following equality holds
for any events Y and D:
p(Y | D) + p(Y | D) = 1
• Proof:
p(Y ∩ D) + P(Y ∩ D) Defn of conditional
p(Y | D) + p(Y | D) = probability
p(D)
p((Y∩ D)∪ (Y ∩ D)) Union of disjoint
€ =
p(D)
events
€
Useful Identities to remember
• We can show that the following equality holds
for any events Y and D:
p(Y | D) + p(Y | D) = 1
• Proof:
p(Y ∩ D) + P(Y ∩ D) Defn of conditional
p(Y | D) + p(Y | D) = probability
p(D)
p((Y∩ D)∪ (Y ∩ D)) Union of disjoint
€ =
p(D)
events
€
Useful Identities to remember
• We can show that the following equality holds
for any events Y and D:
p(Y | D) + p(Y | D) = 1
• Proof:
p(Y ∩ D) + P(Y ∩ D) Defn of conditional
p(Y | D) + p(Y | D) = probability
p(D)
p((Y∩ D)∪ (Y ∩ D)) Union of disjoint
€ =
p(D)
events
€
Useful Identities to remember
• We can show that the following equality holds
for any events Y and D:
p(Y | D) + p(Y | D) = 1
• Proof:
p(Y ∩ D) + P(Y ∩ D) Defn of conditional
p(Y | D) + p(Y | D) = probability
p(D)
p((Y∩ D)∪ (Y ∩ D)) Union of disjoint
€ =
p(D)
events
€
Important Tips for Bayes’ Theorem
• When applying Bayes’ Theorem to a situation
that involves events Y and D (or any arbitrary
notation), you can use the following identities
p(Y | D) + p(Y | D) = 1
p(Y | D ) + p(Y | D ) = 1
p(Y ) + p(Y ) = 1
p(D) + p(D ) = 1
Fall 2020 UM EECS 203 Lecture 16 22
False positives, False negatives
• Let D be the event that a person has the disease
• Let Y be the event that a test for the disease comes back
positive
𝑫 "
𝑫
𝒀 True positive False positive
"
𝒀 False negative True negative
We want
• High probabilities of TP and TN
• Low probabilities of FP and FN
Y ∩ D : True positive (accurate prediction)
Y ∩ D : False positive (inaccurate prediction)
Y ∩ D : False negative (inaccurate prediction)
Y ∩ D : True negative (accurate prediction)
Fall 2020 UM EECS 203 Lecture 16 23
Testing for Disease (Medical Diagnosis)
• The disease is very rare: p(D) = 1/100,000
• Testing is Accurate
– Few False Positives p(Y | D ) = 0.5%
– Few False Negatives p(Y | D) = 1%
• Suppose you get a positive result. What do you
conclude? € p(Y | D) = 1− p(Y | D)
€
p (Y | D) p ( D)
p( D | Y ) =
p (Y | D) p ( D) +€p (Y | D ) p ( D )
0.99 *10 -5
= -5 -5
» 0.002
0.99 *10 + 0.005 * (1 - 10 )
Ans: If you get a positive result, there is a 0.2% chance that you have the disease.
Fall 2020 UM EECS 203 Lecture 16 24
Exercise
• When a test for steroids is given to soccer players
– 98% of the players taking steroids test positive
– 12% of the players not taking steroids test positive
• Suppose 5% of soccer players take steroids. What is
the probability that a soccer player who tests
positive takes steroids?
P( E | F j ) p( F j )
P( F j | E ) =
å
n
i =1
P ( E | Fi ) p ( Fi )
k= 0 è ø
• Binomial expansion of 𝑝 + 𝑞 + k
– Each term gives probability of k successes
$ $ $ $
𝑝+𝑞 $ = ∑$#&' #
𝑝# 𝑞$%# = '
𝑞$ + (
𝑝( 𝑞$%( +…+ $
𝑝$
• What is 𝑝 + 𝑞 + ?
𝑝 + 𝑞 + = 𝑝 + (1 − 𝑝 )+ = 1 + = 1
• Why is this important?
Answer: The sum of the probabilities must be 1
Fall 2020 UM EECS 203 Lecture 16 43
Random Variables
A random variable is a function from
a sample space to the real numbers
X:S→R
R
-2 0 2
S
-2 0 2
R
S
– X((6,6))= 12.
0.06
0.04
0.02
0
2 4 6 8 10 12
X
0.16
0.2
0.14
0.12
0.15
0.1
p(X)
p(X) 0.08
0.1
0.06
0.05 0.04
0.02
0 0
0 2 4 6 8 10 12 0 5 10 15 20 25
X X
0.18 0.18
0.16 0.16
0.14 0.14
0.12 0.12
p(X)
p(X)
0.1 0.1
0.08 0.08
0.06 0.06
0.04 0.04
0.02 0.02
0 0
0 5 10 15 20 25 0 5 10 15 20 25
X X
E( X) = ∑ p(s) ⋅ X(s) =∑ p( X = r) ⋅ r
s∈S r
𝐸 𝑋 = % 𝑝(𝑠) * 𝑋(𝑠)
€ #∈%
=𝑝 1 𝑋 1 +𝑝 2 𝑋 2 +𝑝 3 𝑋 3 +𝑝 4 𝑋 4 +𝑝 5 𝑋 5 +𝑝 6 𝑋 6
= (1⁄6) * 1 + (1⁄6) * 2 + (1⁄6) * 3 + (1⁄6) * 4 + (1⁄6) * 5 + (1⁄6) * 6
= 1⁄6 + 2⁄6 + 3⁄6 + 4⁄6 + 5⁄6 + 6⁄6 = 7/2
• Proof:
€
E( X1 + X2 ) =∑ p(s)( X1 (s) + X2 (s)) defn of E( )
s∈S
s∈S s∈S
= E( X1 ) + E( X2 ) defn of E( )
A: 0
B: 1
C: 2
D: n/2
E: n(n-1)/2
𝐸 𝑋 = 𝐸(𝑋- + 𝑋. + 𝑋/ + ⋯ + 𝑋+ )
= 𝐸 𝑋- + 𝐸 𝑋. + … + 𝐸 𝑋+ By linearity of expectations
-
= 𝑛 , 𝐸 𝑋- = 𝑛 , =1
+
Fall 2020 UM EECS 203 Lecture 16 66
Geometric Distributions
• A coin has probability p of Tails. Flip it until you get the
first Tails; count the total number of flips (including the
last one).
– What is the sample space S?
– What is the probability distribution?
0.18
0.16
0.14
0.12
p(X)
0.1
0.08
0.06
0.04
0.02 Geometric(1/50)
0.02
0
0 5 10 15 20 25 0.018
X
0.016
0.014
p(X) 0.012
0.01
0.008
0.006
0.004
0.002
0
0 20 40 60 80 100
X
E( X) = å j × P( X = j) = å j(1- p) j -1 p = på j(1- p) j -1
j =1 j =1 j =1
¥
1 1
å j (1 - p)
j =1
j -1
=
(1 - (1 - p )) 2
= 2 (From
p
(From Table
Table2,2,PgPg176)
166)
) )
Thus, 𝐸 𝑋 = 𝑝 !8
= !
Fall 2020 UM EECS 203 Lecture 16 70
Geometric Distributions
• The sample space is countably infinite!
• The probability of sequence: 𝑝 𝑋 = 𝑗 = (1 − 𝑝)'+) 𝑝.
¥
E( X) = å j × P( X = j)
j =1 How many times is the event
¥ “X=j” counted in this sum?
= å P( X ³ j) A handy alternative expression for E(X)
j =1
¥ when X is always a non-negative integer.
= åj =1
(1- p) j -1
1 1
= =
1- (1- p) p
Fall 2020 UM EECS 203 Lecture 16 71
Watching Seinfeld Reruns
• Every night a Seinfeld episode is drawn uniformly
at random from the 180 shows and broadcast.
• What is the expected number of nights you need
to watch to see all episodes?
• Independent: X1 and X2 are number of heads on first and second flip respectively. So
E(X1)= E(X2)= 1/2.
(X1X2)(HH)= 1*1 = 1. (X1X2)(HT)= 1*0 = 0. (X1X2)(TH)= 0*1 = 0. (X1X2)(TT)= 0*0 = 0
Then E(X1X2)= ¼*1 + ¼*0 + ¼*0 + ¼*0 = ¼ = E(X1)E(X2).
• Dependent: X1 is number of heads on first flip and X3 is number of heads across both
flips. So E(X1)= ½, E(X3)= 1.
(X1X3)(HH)=1*2=2. (X1X3)(HT)=1*1=1. (X1X3)(TH)=0*1=0. (X1X3)(TT)=0*0=0
E(X1X3) = ¼*2 + ¼*1 + ¼*0 + ¼*0 = ¾ ≠ ½ = E(X1)E(X2).