Notes 3
Notes 3
P({T T }
P(B2 )
P({HT }
P(B1 )
= 12 , P(X = 1|B2 ) =
1
2
P({T H}
P(B2 )
1
2
P({HH}
P(B1 )
= 21 . Then
We can also obtain the conditional distribution of X|B1 and X|B2 by considering the implications
of the experiment. If B1 occurs then X|B1 equals 1+ Y where Y counts the number of heads
in the second toss of the coin, so Y Bernoulli 12 . If B2 occurs then X|B equals Y . Hence
E[X|B1 ] = 1 + E[Y ] = 1 + 21 and E[X|B2 ] = E[Y ] = 12 .
We will now look at a similar law to the law of total probability which is for expectations. This
can be used to find the expected duration of the sequence of games (expected number of games
played) for the gamblers ruin problem.
The law of total probability for expectations
From the law of total probability, if B1 , ..., Bn partition S then for any possible value of x,
n
P(X = x) =
j=1
fX|B j (x)P(B j ).
j=1
Multiplying by x and summing we obtain the Law of Total Probability for Expectations
n
E[X] =
E[X|B j ]P(B j )
j=1
Example. Consider the set-up for a geometric distribution. We have a sequence of independent
trials of an experiment, with probability p of success at each trial. X counts the number of trials
till the first success.
Let B1 be the event that the first trial is a success and B2 be the event that the first trial is a
failure.
When B1 occurs, X must equal 1. So P(X = 1 and B1 ) = P(B1 ) and P(X = x and B1 ) = 0 if
x > 1. Hence the distribution of X|B1 is concentrated at the single value 1 i.e. X|B1 is identically
equal to 1.
If B2 is the event that the first trial is a failure, then the number of trials until a success in the
subsequent trials, Y , has the same distribution as X. We also have carried out the first trial.
Hence X|B2 is equal to 1 +Y where Y has the same distribution as X.
Hence E[X|B1 ] = 1 and E[X|B2 ] = 1 + E[Y ] = 1 + E[X]. Therefore
Ek = 1 + pEk+1 + qEk1
EM = EN = 0 since the gambling stops playing immediately. 2
The equation for Ek is sometimes wriiten in the following equivalent form
pEk+1 Ek + qEk1 = 1
1
. When p = 21 a
When p 6= 12 a particular solution to this equation is Ek = Ck where C = qp
particular solution is Ek = Ck2 where C = 1. Now, as for differential equations, the general
solution to the particular difference equation is the particular solution just obtained plus the
general solution to the general equation pEk+1 Ek + qEk1 = 0.
Case when p 6= 12 .
k
k
q
Ek =
+A+B
q p
p
Since 0 = EM =
M
qp
+A+B
M
q
p
and 0 = EN =
N
qp
+A+B
N
q
p
,B=
and
M
A = (qp)
q
p
q M
p
N .
qp
(NM)
M N
(qp) qp qp
aries we obtain
k
Ek (M, N) =
q
p
(k M) (N M)
(q p)
(q p) q N
M
q
p
M
q
p
Case when p = 12 .
Ek = k2 + A + Bk
Since 0 = EM = M 2 + A + BM and 0 = EN = N 2 + A + BN, B = N + M and A = MN.
Hence writing Ek as Ek (M, N) to explicitly include the boundaries
Ek (M, N) = (k M)(N k)
Conditional distribution of X|Y where X and Y are random variables.
For any value y of Y for which P(Y = y) > 0 we can consider the conditional distribution of
X|Y = y and find the expectation and variance of X over this conditional distribution, E[X|Y = y]
and Var(X|Y = y). Let fX|Y (x|y) = P(X = x|Y = y). Consider the function of Y which takes the
value E[X|Y = y] when Y = y. This is a random variable which we denote by E[X|Y ]. Similarly
we define Var(X|Y ) and E[g(X)|Y ] to be the functions of Y (so random variables) which take
value Var(X|Y = y) and E[g(X)|Y ] when Y = y.
Theorem. (i) E[X] = E[E[X|Y ]], (ii) Var(X) = E[Var(X|Y )] +Var(E[X|Y ]) and (iii) GX (t) =
E[E[t X |N]].
Proof We show that E[g(X)] = E[E[g(X)|Y ]]. Now
E[g(X)|Y = y] =
x=0
E[E[g(X)|Y ]]
g(x)
x=0
P(X = x,Y = y)
P(Y = y)
=
y=0 E[g(X)|Y = y]P(Y = y)
P(X=x,Y =y)
=
y=0 x=0 g(x) P(Y =y) P(Y = y)
=
x=0 g(x) y=0 P(X = x,Y = y)
=
x=0 g(x)P(X = x) = E[g(X)]
P(X = x|R = r) =
P(X=x,R=r)
P(R=r)
P(X=x,Y =rx)
P(R=r)
rx qmr+x
nC px qnx mC
x
rx p
n+mC pr qn+mr
r
P(X=x)P(Y =rx)
P(R=r)
nC mC
x
rx
n+mC
r
Hence the conditional distribution of X|R = r is hypergeometric. This provides the basis of the
2 2 contingency table test of equality of two binomial p parameters in statistics.
Example The number of spam messages Y in a day has Poisson distribution with parameter .
Each spam message (independently) has probability p of not being detected by the spam filter.
Let X be the number getting through the filter. Then X|Y = y has Binomial distribution with
parameters n = y and p. Let q = 1 p.
Hence E[X|Y = y] = py, Var(X|Y = y) = pqy and E[t X |Y = y] = (pt + q)y so that E[X|Y ] = pY ,
Var(X|Y ) = pqY and E[t X |Y ] = (pt + q)Y . Therefore:
so that
h
i
N
GY (t) = E[E[t |N]] = E (GX (t)) = GN (GX (t))
Y
Example
Let X j be the amount of money the jth customer spends in a day in a shop. The X 0 s are i.i.d.
random variables with mean 20 and variance 10. The number of customers per day N has
Poisson distribution parameter 100. The total spend Y in the day is Y = Nj=1 X j . So E[Y ] =
(20)(100) = 2000 and Var(Y ) = (10)(100) + (20)2 (100) = 41000.