Salta al contenuto
Note per Studenti Conditional Expectation Report

Conditional Expectation

In questa pagina 6

Warm-up: the sum of two independent exponentials

Exercise. Customers need to stop at two service stations. The service time at one station is an exponential random variable, T∼Exp(λ)T \sim \text{Exp}(\lambda), so that the average service time is E(T)=1λE(T)=\frac{1}{\lambda}. The service times at the two stations are T1,T2T_1, T_2, i.i.d. Exp(λ)\text{Exp}(\lambda). Let T=T1+T2T = T_1+T_2 be the total time. Compute the density of TT.

Solution. The density of a sum of independent random variables is the convolution of the densities, fT=f∗ff_T = f * f, where f(t)=λe−λt 1(t)f(t)=\lambda e^{-\lambda t}\,\mathbb{1}(t) and 1\mathbb{1} is the unit step. For t≥0t \ge 0

fT(t)=∫0tf(t−τ) f(τ) dτ=∫0tλe−λ(t−τ) λe−λτ dτ=λ2e−λt∫0t1 dτ=λ2 t e−λt 1(t).f_T(t)=\int_0^t f(t-\tau)\,f(\tau)\,d\tau=\int_0^t \lambda e^{-\lambda (t-\tau)}\,\lambda e^{-\lambda \tau}\,d\tau =\lambda^2 e^{-\lambda t}\int_0^t 1\,d\tau=\lambda^2\, t\, e^{-\lambda t}\,\mathbb{1}(t).

The page closes with the question "what is the expected value?" and leaves it open (it is E(T1)+E(T2)=2λE(T_1)+E(T_2)=\frac{2}{\lambda} by additivity of EE).

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ℓ)p_{X\mid Y}(x_k \mid y_\ell) be a discrete conditional density. The conditional expected value is defined, for Y=yℓY=y_\ell fixed, as

E(X∣Y=yℓ)  ≜  ∑xk∈Xxk  pX∣Y(xk∣yℓ).E(X \mid Y=y_\ell)\;\triangleq\;\sum_{x_k\in\mathcal{X}} x_k\; p_{X\mid Y}(x_k \mid y_\ell).

Definition (absolutely continuous case). Let fX∣Y(x∣y)f_{X\mid Y}(x\mid y) be a given conditional density. Then for Y=yY=y fixed

E(X∣Y=y)  ≜  ∫x fX∣Y(x∣y) dx.E(X \mid Y=y)\;\triangleq\;\int x\, f_{X\mid Y}(x\mid y)\,dx .

Remark. E(X∣Y=y)E(X\mid Y=y) is a real number for any y∈Ry\in\mathbb{R} fixed.

More generally, for g:R→Rg:\mathbb{R}\to\mathbb{R} one defines

E(g(X)∣Y=y)  ≜  ∫g(x) fX∣Y(x∣y) dx.E\big(g(X)\mid Y=y\big)\;\triangleq\;\int g(x)\, f_{X\mid Y}(x\mid y)\,dx .

Example: uniform density on a triangle

Let (X,Y)∼U(T)(X,Y)\sim\mathcal{U}(T), where T⊂R2T\subset\mathbb{R}^2 is the triangle with vertices (−1,0)(-1,0), (1,0)(1,0), (0,1)(0,1) and top sides y=1−∣x∣y=1-|x|, ∣x∣≤1|x|\le 1 (figure: a triangle on the xx-axis between −1-1 and 11 with apex at height 11). Compute E(X∣Y=y)E(X\mid Y=y) and E(Y∣X=x)E(Y\mid X=x).

Flag: the page writes the domain as "y=1−∣x∣y=1-|x|, ∣x∣≤1|x|\le1", but the figure and every computation below use the filled triangle 0≤y≤1−∣x∣0\le y\le 1-|x|, which is what is meant.

The joint density is fXY(x,y)=χT(x,y)f_{XY}(x,y)=\chi_T(x,y) (the area of TT is 11). Since fX∣Yf_{X\mid Y} and fY∣Xf_{Y\mid X} are needed, both marginals are needed.

Marginal of YY. For fixed y∈[0,1]y\in[0,1] the horizontal section of TT goes from x=y−1x=y-1 (line y=1+xy=1+x) to x=1−yx=1-y (line y=1−xy=1-x):

fY(y)=[∫y−11−y1 dx]χ[0,1](y)=2(1−y) χ[0,1](y).f_Y(y)=\Big[\int_{y-1}^{1-y} 1\,dx\Big]\chi_{[0,1]}(y)=2(1-y)\,\chi_{[0,1]}(y).

Marginal of XX. For fixed xx the vertical section goes from y=0y=0 to y=1+xy=1+x if x∈[−1,0]x\in[-1,0], to y=1−xy=1-x if x∈[0,1]x\in[0,1]:

fX(x)=[∫01+x1 dy]χ[−1,0](x)+[∫01−x1 dy]χ[0,1](x)=(1+x)χ[−1,0](x)+(1−x)χ[0,1](x)=(1−∣x∣) χ[−1,1](x).f_X(x)=\Big[\int_0^{1+x}1\,dy\Big]\chi_{[-1,0]}(x)+\Big[\int_0^{1-x}1\,dy\Big]\chi_{[0,1]}(x) =(1+x)\chi_{[-1,0]}(x)+(1-x)\chi_{[0,1]}(x)=(1-|x|)\,\chi_{[-1,1]}(x).

1. Conditional density of XX given YY.

fX∣Y(x∣y)=fXY(x,y)fY(y)=12(1−y) χT(x,y) χ[0,1](y)=12(1−y) χ[y−1, 1−y](x) χ[0,1](y).f_{X\mid Y}(x\mid y)=\frac{f_{XY}(x,y)}{f_Y(y)}=\frac{1}{2(1-y)}\,\chi_T(x,y)\,\chi_{[0,1]}(y)=\frac{1}{2(1-y)}\,\chi_{[y-1,\,1-y]}(x)\,\chi_{[0,1]}(y).

For each y∈[0,1]y\in[0,1] fixed, fX∣Y(x∣y)∼U([y−1,1−y])f_{X\mid Y}(x\mid y)\sim\mathcal{U}([y-1,1-y]) (it is constant in xx). A uniform density over an interval symmetric with respect to x=0x=0 has mean 00:

E(X∣Y=y)=∫x fX∣Y(x∣y) dx=0.E(X\mid Y=y)=\int x\,f_{X\mid Y}(x\mid y)\,dx=0 .

Note that, since fXYf_{XY} is uniform on TT, the conditional density fX∣Y(x∣y)f_{X\mid Y}(x\mid y) is also uniform on the section of TT with yy fixed: it differs from fXY(x,y)f_{XY}(x,y) only by the factor 1fY(y)\frac{1}{f_Y(y)}, which does not depend on xx.

2. Conditional density of YY given XX.

fY∣X(y∣x)=fXY(x,y)fX(x)=11−∣x∣ χ[−1,1](x) χ[0, 1−∣x∣](y)f_{Y\mid X}(y\mid x)=\frac{f_{XY}(x,y)}{f_X(x)}=\frac{1}{1-|x|}\,\chi_{[-1,1]}(x)\,\chi_{[0,\,1-|x|]}(y)

is, for all x∈[−1,1]x\in[-1,1] fixed, uniform over [0,1−∣x∣][0,1-|x|]. The expected value is therefore

E(Y∣X=x)=∫y fY∣X(y∣x) dy=1−∣x∣2 χ[−1,1](x).E(Y\mid X=x)=\int y\,f_{Y\mid X}(y\mid x)\,dy=\frac{1-|x|}{2}\,\chi_{[-1,1]}(x).

Properties of the conditional expected value

  1. E(g(X)∣Y=y)=h(y)E(g(X)\mid Y=y)=h(y), where h:R→Rh:\mathbb{R}\to\mathbb{R} is a deterministic function of y∈Ry\in\mathbb{R}.

  2. If X⊥YX \perp Y (independent) then E(g(X)∣Y=y)=E(g(X))E(g(X)\mid 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))E(g(X)\mid Y=y)=\int g(x)f_{X\mid Y}(x\mid y)\,dx=\int g(x)f_X(x)\,dx=E(g(X)), since X⊥YX\perp Y is equivalent to fX∣Y≡fXf_{X\mid Y}\equiv f_X. □\square

  3. It makes sense to consider the function of the random variable YY defined as h(Y)h(Y), where h(y)=E(g(X)∣Y=y)h(y)=E(g(X)\mid Y=y); it also makes sense to compute its expected value E(h(Y))=E(E(g(X)∣Y))E(h(Y))=E\big(E(g(X)\mid Y)\big). This is essential.

Law of the Iterated Expectation (LIE)

Theorem. E(g(X))=E(E(g(X)∣Y)).E\big(g(X)\big)=E\Big(E\big(g(X)\mid Y\big)\Big).

Proof. Work starting from the right-hand side: the expectation of the function h(Y)=E(g(X)∣Y)h(Y)=E(g(X)\mid Y) of the random variable YY is, by the LOTUS (law of the unconscious statistician),

E(h(Y))=∫h(y) fY(y) dy=∫E(g(X)∣Y=y)fY(y) dy=∫[∫g(x) fX∣Y(x∣y) dx]fY(y) dy=∫g(x)[∫fX∣Y(x∣y) fY(y) dy]dx=∫g(x) fX(x) dx=E(g(X)).□\begin{aligned} E(h(Y))&=\int h(y)\,f_Y(y)\,dy=\int E\big(g(X)\mid Y=y\big) f_Y(y)\,dy\\ &=\int\Big[\int g(x)\,f_{X\mid Y}(x\mid y)\,dx\Big]f_Y(y)\,dy =\int g(x)\Big[\int f_{X\mid Y}(x\mid y)\,f_Y(y)\,dy\Big]dx\\ &=\int g(x)\,f_X(x)\,dx=E(g(X)). \qquad\square \end{aligned}

Remark (discrete case). For discrete random variables the LIE reads

∑xkg(xk) pX(xk)=∑yℓ∑xkg(xk) pX∣Y(xk∣yℓ) pY(yℓ),\sum_{x_k} g(x_k)\,p_X(x_k)=\sum_{y_\ell}\sum_{x_k} g(x_k)\,p_{X\mid Y}(x_k\mid y_\ell)\,p_Y(y_\ell),

which shows well the connection with the law of total probability to evaluate pX(xk)p_X(x_k).

Example: the breadstick

A breadstick has length LL. Take a bite of random length and let YY be the length of the breadstick remaining: clearly Y∼U([0,L])Y\sim\mathcal{U}([0,L]), fY(y)=1Lχ[0,L](y)f_Y(y)=\frac1L\chi_{[0,L]}(y). Take a second random bite and let XX be the length remaining: clearly X∣Y=y∼U([0,y])X\mid Y=y\sim\mathcal{U}([0,y]), that is fX∣Y(x∣y)=1yχ[0,y](x)χ[0,L](y)f_{X\mid Y}(x\mid y)=\frac1y\chi_{[0,y]}(x)\chi_{[0,L]}(y). Compute E(X)E(X).

Direct computation. The joint density is fXY(x,y)=1LyχD(x,y)f_{XY}(x,y)=\frac{1}{Ly}\chi_D(x,y), where DD is the triangle 0≤x≤y≤L0\le x\le y\le L (figure: square [0,L]2[0,L]^2 cut by the line y=xy=x, DD is the part above it). The marginal is

fX(x)=∫xLfXY(x,y) dy=∫xL1Ly dy=1Lln⁡y∣xL=1L(ln⁡L−ln⁡x) χ[0,L](x),f_X(x)=\int_x^L f_{XY}(x,y)\,dy=\int_x^L\frac{1}{Ly}\,dy=\frac1L\ln y\Big|_x^L=\frac1L(\ln L-\ln x)\,\chi_{[0,L]}(x),

and E(X)=∫0Lx 1L(ln⁡L−ln⁡x) dxE(X)=\int_0^L x\,\frac1L(\ln L-\ln x)\,dx (the page leaves this integral unevaluated).

Same computation with the LIE. E(X)=E(E(X∣Y))E(X)=E\big(E(X\mid Y)\big). Here

h(y)=E(X∣Y=y)=∫x fX∣Y(x∣y) dx=y2h(y)=E(X\mid Y=y)=\int x\,f_{X\mid Y}(x\mid y)\,dx=\frac y2

because fX∣Y(⋅∣y)∼U([0,y])f_{X\mid Y}(\cdot\mid y)\sim\mathcal{U}([0,y]). Hence h(Y)=Y2h(Y)=\frac Y2 and, since Y∼U([0,L])Y\sim\mathcal{U}([0,L]),

E(X)=E(Y2)=L4.E(X)=E\Big(\frac Y2\Big)=\frac L4 .

The result is very intuitive: each bite removes on average half of what is left.

Random sums

Let S=∑i=1nXiS=\sum_{i=1}^n X_i. Then E(S)=∑i=1nE(Xi)E(S)=\sum_{i=1}^n E(X_i); if the XiX_i are identically distributed, E(S)=nE(X1)E(S)=nE(X_1).

Consider now the sum

W=∑i=1NXi,W=\sum_{i=1}^{N} X_i ,

where NN is a random variable with alphabet N⊂N\mathcal{N}\subset\mathbb{N}. Assume that the random variables {N,X1,X2,… }\{N,X_1,X_2,\dots\} are independent and that {X1,X2,… }\{X_1,X_2,\dots\} are i.i.d. (identically distributed, discrete or continuous).

Problem. Compute E(W)=E(∑i=1NXi)E(W)=E\big(\sum_{i=1}^N X_i\big).

Solution. This is a typical application of the LIE: E(W)=E(E(W∣N))E(W)=E\big(E(W\mid N)\big). Let

h(n)=E(∑i=1NXi  ∣  N=n)=E(∑i=1nXi  ∣  N=n)=E(∑i=1nXi)=nE(X1),h(n)=E\Big(\sum_{i=1}^{N}X_i\;\Big|\;N=n\Big)=E\Big(\sum_{i=1}^{n}X_i\;\Big|\;N=n\Big)=E\Big(\sum_{i=1}^{n}X_i\Big)=nE(X_1),

where the third equality holds because {X1,…,Xn}⊥N\{X_1,\dots,X_n\}\perp N. Therefore h(N)=N E(X1)h(N)=N\,E(X_1) and

E(∑i=1NXi)=E(h(N))=E(N E(X1))=E(N) E(X1).□E\Big(\sum_{i=1}^{N}X_i\Big)=E(h(N))=E\big(N\,E(X_1)\big)=E(N)\,E(X_1). \qquad\square

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(λ)N\sim\mathcal{P}(\lambda). Each grandparent brings one child with probability pp, independently from all the others. Let KK be the random variable representing the number of children present.

(a) Determine pK∣N(k∣n)p_{K\mid N}(k\mid n). (b) Compute pK(0)p_K(0). (c) Let S=N+KS=N+K be the total number of participants. Find E(S∣N)E(S\mid N). (d) Compute E(S)E(S).

Solution.

(a) If N=nN=n grandparents are present, each with probability pp (constant over all nn grandparents) of bringing a child independently of all the others, then K∣N=n∼Bin(n,p)K\mid N=n\sim\text{Bin}(n,p), that is

pK∣N(k∣n)=(nk)pk(1−p)n−k,n≥1,  k=0,1,…,n.p_{K\mid N}(k\mid n)=\binom nk p^k(1-p)^{n-k},\qquad n\ge1,\; k=0,1,\dots,n.

(b) By total probability,

pK(0)=∑n=0∞pK∣N(0∣n) pN(n)=∑n=0∞(1−p)ne−λλnn!=e−λ∑n=0∞[λ(1−p)]nn!=e−λeλ(1−p)=e−λp.p_K(0)=\sum_{n=0}^\infty p_{K\mid N}(0\mid n)\,p_N(n)=\sum_{n=0}^\infty(1-p)^n e^{-\lambda}\frac{\lambda^n}{n!} =e^{-\lambda}\sum_{n=0}^\infty\frac{[\lambda(1-p)]^n}{n!}=e^{-\lambda}e^{\lambda(1-p)}=e^{-\lambda p}.

(c) E(S∣N=n)=E(N+K∣N=n)=n+E(K∣N=n)=n+np=n(1+p)E(S\mid N=n)=E(N+K\mid N=n)=n+E(K\mid N=n)=n+np=n(1+p), since K∣N=n∼Bin(n,p)K\mid N=n\sim\text{Bin}(n,p). Therefore E(S∣N)=N(1+p)E(S\mid N)=N(1+p).

(d) By the LIE, E(S)=E(E(S∣N))=E(N(1+p))=λ(1+p)E(S)=E\big(E(S\mid N)\big)=E\big(N(1+p)\big)=\lambda(1+p).

Versione ripasso

Definitions. Discrete: E(X∣Y=yℓ)=∑xkxk pX∣Y(xk∣yℓ)E(X\mid Y=y_\ell)=\sum_{x_k}x_k\,p_{X\mid Y}(x_k\mid y_\ell). Absolutely continuous: E(X∣Y=y)=∫x fX∣Y(x∣y) dxE(X\mid Y=y)=\int x\,f_{X\mid Y}(x\mid y)\,dx. General: E(g(X)∣Y=y)=∫g(x)fX∣Y(x∣y) dxE(g(X)\mid Y=y)=\int g(x)f_{X\mid Y}(x\mid y)\,dx. For yy fixed it is a real number.

Properties.

  • E(g(X)∣Y=y)=h(y)E(g(X)\mid Y=y)=h(y) with hh a deterministic function; then h(Y)=E(g(X)∣Y)h(Y)=E(g(X)\mid Y) is a random variable.
  • X⊥Y⇒E(g(X)∣Y=y)=E(g(X))X\perp Y\Rightarrow E(g(X)\mid Y=y)=E(g(X)) (because fX∣Y≡fXf_{X\mid Y}\equiv f_X).
  • LIE: E(g(X))=E(E(g(X)∣Y))E(g(X))=E\big(E(g(X)\mid Y)\big). Proof: LOTUS on h(Y)h(Y), swap the two integrals, use ∫fX∣YfY dy=fX\int f_{X\mid Y}f_Y\,dy=f_X. Discrete version = law of total probability.

Triangle example (fXY=χTf_{XY}=\chi_T, T={0≤y≤1−∣x∣}T=\{0\le y\le1-|x|\}): fY=2(1−y)χ[0,1]f_Y=2(1-y)\chi_{[0,1]}, fX=(1−∣x∣)χ[−1,1]f_X=(1-|x|)\chi_{[-1,1]}; X∣Y=y∼U([y−1,1−y])X\mid Y=y\sim\mathcal{U}([y-1,1-y]), so E(X∣Y=y)=0E(X\mid Y=y)=0; Y∣X=x∼U([0,1−∣x∣])Y\mid X=x\sim\mathcal{U}([0,1-|x|]), so E(Y∣X=x)=1−∣x∣2E(Y\mid X=x)=\frac{1-|x|}{2}.

Breadstick: Y∼U([0,L])Y\sim\mathcal{U}([0,L]), X∣Y∼U([0,Y])X\mid Y\sim\mathcal{U}([0,Y]), h(y)=y2h(y)=\frac y2, E(X)=E(Y2)=L4E(X)=E(\frac Y2)=\frac L4.

Random sums. W=∑i=1NXiW=\sum_{i=1}^N X_i with {N,X1,X2,… }\{N,X_1,X_2,\dots\} independent and the XiX_i i.i.d.: E(W∣N=n)=nE(X1)E(W\mid N=n)=nE(X_1), so E(W)=E(N)E(X1)E(W)=E(N)E(X_1).

Grandparents: K∣N=n∼Bin(n,p)K\mid N=n\sim\text{Bin}(n,p); pK(0)=e−λpp_K(0)=e^{-\lambda p}; E(S∣N)=N(1+p)E(S\mid N)=N(1+p); E(S)=λ(1+p)E(S)=\lambda(1+p).

Typical mistakes. Treating E(X∣Y)E(X\mid Y) as a number (it is a function of YY, hence random); forgetting independence of NN and the XiX_i before replacing NN by nn; writing E(NX1)E(N X_1) without noting E(NE(X1))=E(N)E(X1)E(N E(X_1))=E(N)E(X_1) since E(X1)E(X_1) is a constant; sum of two i.i.d. Exp(λ)\text{Exp}(\lambda) has density λ2te−λt1(t)\lambda^2te^{-\lambda t}\mathbb{1}(t), not an exponential.