Exercise. Customers need to stop at two service stations. The service time at one station is an exponential random variable, T∼Exp(λ), so that the average service time is E(T)=λ1. The service times at the two stations are T1,T2, i.i.d. Exp(λ). Let T=T1+T2 be the total time. Compute the density of T.
Solution. The density of a sum of independent random variables is the convolution of the densities, fT=f∗f, where f(t)=λe−λt1(t) and 1 is the unit step. For t≥0
The page closes with the question "what is the expected value?" and leaves it open (it is E(T1)+E(T2)=λ2 by additivity of E).
Conditional expected value
Having defined the conditional densities, discrete and absolutely continuous, it makes sense to compute the expected value with respect to these densities.
Definition (discrete case). Let pX∣Y(xk∣yℓ) be a discrete conditional density. The conditional expected value is defined, for Y=yℓ fixed, as
E(X∣Y=yℓ)≜xk∈X∑xkpX∣Y(xk∣yℓ).
Definition (absolutely continuous case). Let fX∣Y(x∣y) be a given conditional density. Then for Y=y fixed
E(X∣Y=y)≜∫xfX∣Y(x∣y)dx.
Remark.E(X∣Y=y) is a real number for any y∈R fixed.
More generally, for g:R→R one defines
E(g(X)∣Y=y)≜∫g(x)fX∣Y(x∣y)dx.
Example: uniform density on a triangle
Let (X,Y)∼U(T), where T⊂R2 is the triangle with vertices (−1,0), (1,0), (0,1) and top sides y=1−∣x∣, ∣x∣≤1 (figure: a triangle on the x-axis between −1 and 1 with apex at height 1). Compute E(X∣Y=y) and E(Y∣X=x).
Flag: the page writes the domain as "y=1−∣x∣, ∣x∣≤1", but the figure and every computation below use the filled triangle 0≤y≤1−∣x∣, which is what is meant.
The joint density is fXY(x,y)=χT(x,y) (the area of T is 1). Since fX∣Y and fY∣X are needed, both marginals are needed.
Marginal of Y. For fixed y∈[0,1] the horizontal section of T goes from x=y−1 (line y=1+x) to x=1−y (line y=1−x):
fY(y)=[∫y−11−y1dx]χ[0,1](y)=2(1−y)χ[0,1](y).
Marginal of X. For fixed x the vertical section goes from y=0 to y=1+x if x∈[−1,0], to y=1−x if x∈[0,1]:
For each y∈[0,1] fixed, fX∣Y(x∣y)∼U([y−1,1−y]) (it is constant in x). A uniform density over an interval symmetric with respect to x=0 has mean 0:
E(X∣Y=y)=∫xfX∣Y(x∣y)dx=0.
Note that, since fXY is uniform on T, the conditional density fX∣Y(x∣y) is also uniform on the section of T with y fixed: it differs from fXY(x,y) only by the factor fY(y)1, which does not depend on x.
is, for all x∈[−1,1] fixed, uniform over [0,1−∣x∣]. The expected value is therefore
E(Y∣X=x)=∫yfY∣X(y∣x)dy=21−∣x∣χ[−1,1](x).
Properties of the conditional expected value
E(g(X)∣Y=y)=h(y), where h:R→R is a deterministic function of y∈R.
If X⊥Y (independent) then E(g(X)∣Y=y)=E(g(X)).
Proof.E(g(X)∣Y=y)=∫g(x)fX∣Y(x∣y)dx=∫g(x)fX(x)dx=E(g(X)), since X⊥Y is equivalent to fX∣Y≡fX. □
It makes sense to consider the function of the random variable Y defined as h(Y), where h(y)=E(g(X)∣Y=y); it also makes sense to compute its expected value E(h(Y))=E(E(g(X)∣Y)). This is essential.
Law of the Iterated Expectation (LIE)
Theorem.E(g(X))=E(E(g(X)∣Y)).
Proof. Work starting from the right-hand side: the expectation of the function h(Y)=E(g(X)∣Y) of the random variable Y is, by the LOTUS (law of the unconscious statistician),
which shows well the connection with the law of total probability to evaluate pX(xk).
Example: the breadstick
A breadstick has length L. Take a bite of random length and let Y be the length of the breadstick remaining: clearly Y∼U([0,L]), fY(y)=L1χ[0,L](y). Take a second random bite and let X be the length remaining: clearly X∣Y=y∼U([0,y]), that is fX∣Y(x∣y)=y1χ[0,y](x)χ[0,L](y). Compute E(X).
Direct computation. The joint density is fXY(x,y)=Ly1χD(x,y), where D is the triangle 0≤x≤y≤L (figure: square [0,L]2 cut by the line y=x, D is the part above it). The marginal is
and E(X)=∫0LxL1(lnL−lnx)dx (the page leaves this integral unevaluated).
Same computation with the LIE.E(X)=E(E(X∣Y)). Here
h(y)=E(X∣Y=y)=∫xfX∣Y(x∣y)dx=2y
because fX∣Y(⋅∣y)∼U([0,y]). Hence h(Y)=2Y and, since Y∼U([0,L]),
E(X)=E(2Y)=4L.
The result is very intuitive: each bite removes on average half of what is left.
Random sums
Let S=∑i=1nXi. Then E(S)=∑i=1nE(Xi); if the Xi are identically distributed, E(S)=nE(X1).
Consider now the sum
W=i=1∑NXi,
where N is a random variable with alphabet N⊂N. Assume that the random variables {N,X1,X2,…} are independent and that {X1,X2,…} are i.i.d. (identically distributed, discrete or continuous).
Problem. Compute E(W)=E(∑i=1NXi).
Solution. This is a typical application of the LIE: E(W)=E(E(W∣N)). Let
where the third equality holds because {X1,…,Xn}⊥N. Therefore h(N)=NE(X1) and
E(i=1∑NXi)=E(h(N))=E(NE(X1))=E(N)E(X1).□
Exercise: grandparents and children
Participation in a charity event is restricted to grandparents accompanied by at most one child. The number of grandparents present is modeled with a Poisson random variable N∼P(λ). Each grandparent brings one child with probability p, independently from all the others. Let K be the random variable representing the number of children present.
(a) Determine pK∣N(k∣n). (b) Compute pK(0). (c) Let S=N+K be the total number of participants. Find E(S∣N). (d) Compute E(S).
Solution.
(a) If N=n grandparents are present, each with probability p (constant over all n grandparents) of bringing a child independently of all the others, then K∣N=n∼Bin(n,p), that is
(c) E(S∣N=n)=E(N+K∣N=n)=n+E(K∣N=n)=n+np=n(1+p), since K∣N=n∼Bin(n,p). Therefore E(S∣N)=N(1+p).
(d) By the LIE, E(S)=E(E(S∣N))=E(N(1+p))=λ(1+p).
Versione ripasso
Definitions. Discrete: E(X∣Y=yℓ)=∑xkxkpX∣Y(xk∣yℓ). Absolutely continuous: E(X∣Y=y)=∫xfX∣Y(x∣y)dx. General: E(g(X)∣Y=y)=∫g(x)fX∣Y(x∣y)dx. For y fixed it is a real number.
Properties.
E(g(X)∣Y=y)=h(y) with h a deterministic function; then h(Y)=E(g(X)∣Y) is a random variable.
X⊥Y⇒E(g(X)∣Y=y)=E(g(X)) (because fX∣Y≡fX).
LIE:E(g(X))=E(E(g(X)∣Y)). Proof: LOTUS on h(Y), swap the two integrals, use ∫fX∣YfYdy=fX. Discrete version = law of total probability.
Triangle example (fXY=χT, T={0≤y≤1−∣x∣}): fY=2(1−y)χ[0,1], fX=(1−∣x∣)χ[−1,1]; X∣Y=y∼U([y−1,1−y]), so E(X∣Y=y)=0; Y∣X=x∼U([0,1−∣x∣]), so E(Y∣X=x)=21−∣x∣.
Typical mistakes. Treating E(X∣Y) as a number (it is a function of Y, hence random); forgetting independence of N and the Xi before replacing N by n; writing E(NX1) without noting E(NE(X1))=E(N)E(X1) since E(X1) is a constant; sum of two i.i.d. Exp(λ) has density λ2te−λt1(t), not an exponential.