37363 - Lab/Tutorial 3 Solutions

Scott Alexander

Q1

(a)

Note that the log-normal property
(Subscript[X, k]) ~ LN((Subscript[μ, k]),(Subscript[σ, k]^2)), k=1,2
can be re-stated as the normal property
ln (Subscript[X, k]) ~ N((Subscript[μ, k]),(Subscript[σ, k]^2)), k=1,2.

Let
ln X = (({{ln (Subscript[X, 1])}, {ln (Subscript[X, 2])}})),  μ=(({{(Subscript[μ, 1])}, {(Subscript[μ, 2])}}))  and  (σ^2)=(({{(Subscript[σ, 1]^2), 0}, {0, (Subscript[σ, 2]^2)}}))
so
ln X ~ N(μ,(σ^2)).

First note that
ln Y = ln((Subscript[X, 1]^(1/2))/(Subscript[X, 2]^2)) = ln (Subscript[X, 1]^(1/2))-ln (Subscript[X, 2]^2)
  = (1/2)ln (Subscript[X, 1])-2ln (Subscript[X, 2]). 

With A=(({{(1/2), -2}})) we can write
ln Y = (1/2)ln (Subscript[X, 1])-2ln (Subscript[X, 2])
  = A ln X
and so by Theorem 2 Chapter 2 Notes
ln Y ~ N(A μ,A (σ^2)(A^T)) ~ N((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2]),(1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2)).

Therefore    Y~LN((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2]),(1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2)).

Calculations

(({{(1/2), -2}})).(({{(Subscript[σ, 1]^2), 0}, {0, (Subscript[σ, 2]^2)}})).(({{(1/2)}, {-2}}))//MatrixForm

(b)

From (a) we know that    Y~LN((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2]),(1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2)).

So we can use MGF from Definition 2 Chapter 2.

To see this observe that
𝔼[Y] = 𝔼[(e^(ln Y))] = (e^(𝔼[ln Y]+(1/2)var(ln Y)))    (Theorem 2 with u=1)
  = (e^((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2])+(1/2)((1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2))))
  = (e^((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2])+(1/8) (Subscript[σ, 1]^2)+2 (Subscript[σ, 2]^2))).

Similarly
𝔼[(Y^2)] = 𝔼[(e^(ln (Y^2)))] = 𝔼[(e^(2ln Y))] = (e^(2*𝔼[ln Y]+((2^2)/2)var(ln Y)))    (Definition 2 with u=2)
  = (e^(2((1/2)(Subscript[μ, 1])-2(Subscript[μ, 2]))+2((1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2))))
  = (e^((Subscript[μ, 1])-4(Subscript[μ, 2])+(1/2) (Subscript[σ, 1]^2)+8 (Subscript[σ, 2]^2))).

So
var(Y) = 𝔼[(Y^2)]-((𝔼[Y])^2)
  = (e^((Subscript[μ, 1])-4(Subscript[μ, 2])+(1/2) (Subscript[σ, 1]^2)+8 (Subscript[σ, 2]^2)))-(e^((Subscript[μ, 1])-4(Subscript[μ, 2])+(1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2)))

Calculations

Clear[a,b,μY,μ1,μ2,σY,σ1,σ2];
a=(1/2); b=-2;
μY=a μ1+b μ2;
σY=(Sqrt[(a^2)((σ1)^2)+(b^2) ((σ2)^2)]);
Expectation[y,y\[Distributed]LogNormalDistribution[μY,σY]]//FullSimplify
MomentGeneratingFunction[NormalDistribution[μY,σY],1]//FullSimplify
Expectation[(y^2),y\[Distributed]LogNormalDistribution[μY,σY]]//FullSimplify
MomentGeneratingFunction[NormalDistribution[μY,σY],2]//FullSimplify

(c)

The density of Y is
(Subscript[f, Y])(y) (1/((Sqrt[2 π((1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2))]) y))exp(-((((ln y-(1/2)(Subscript[μ, 1])+2(Subscript[μ, 2])))^2)/(2 ((1/4) (Subscript[σ, 1]^2)+4 (Subscript[σ, 2]^2)))))
where y>0 and zero otherwise.

Calculations

Clear[a,b,μY,μ1,μ2,σY,σ1,σ2];
a=(1/2); b=-2;
μY=a μ1+b μ2;
σY=(Sqrt[(a^2)((σ1)^2)+(b^2) ((σ2)^2)]);
PDF[LogNormalDistribution[μY,σY],y]

(d)

Mathematica

Clear[a,b,μY,μ1,μ2,σY,σ1,σ2];
a=(1/2); b=-2;
μ1=μ2=σ1=σ2=1;
μY=a μ1+b μ2;
σY=(Sqrt[(a^2)((σ1)^2)+(b^2) ((σ2)^2)]);
fY[y_]:=PDF[LogNormalDistribution[μY,σY],y];

mean=Integrate[y*fY[y],{y,0,Infinity}];

variance=(∫_0^∞)(y^2)*fY[y]\[DifferentialD]y-(mean^2);
{mean,variance}//FullSimplify
{mean,variance}//N

R

#This won't run in Mathematica.

mu.Y=1/2-2
sigma.Y=sqrt(1/4+4)

fnc1=function(y) y*dlnorm(x=y,meanlog=mu.Y,sdlog=sigma.Y,log=FALSE)
fnc2=function(y) y^2*dlnorm(x=y,meanlog=mu.Y,sdlog=sigma.Y,log=FALSE)

EY=integrate(f=fnc1,lower=0,upper=Inf) #E[Y]
EY2=integrate(f=fnc2,lower=0,upper=Inf) #E[Y^2]

EY2$value-EY$value^2 #variance

(e)

Clear[a,b,μY,μ1,μ2,σY,σ1,σ2];
a=(1/2); b=-2;
μ1=μ2=σ1=σ2=1;
μY=a μ1+b μ2;
σY=(Sqrt[(a^2)((σ1)^2)+(b^2) ((σ2)^2)]);
mean=Mean[LogNormalDistribution[μY,σY]];
variance=Variance[LogNormalDistribution[μY,σY]];
{mean,variance}//FullSimplify
{mean,variance}//N

(f)

Clear[a,b,μY,μ1,μ2,σY,σ1,σ2];
a=(1/2); b=-2;
μ1=μ2=σ1=σ2=1;
μY=a μ1+b μ2;
σY=(Sqrt[(a^2)((σ1)^2)+(b^2) ((σ2)^2)]);
mean=Expectation[y,y\[Distributed]LogNormalDistribution[μY,σY]];
variance=Expectation[(y^2),y\[Distributed]LogNormalDistribution[μY,σY]]-(mean^2);
{mean,variance}//FullSimplify
{mean,variance}//N

Q2

(a)

The characteristic function of Y is
(Subscript[ψ, Y])(u) = 𝔼[(e^(i u Y))] = 𝔼[(e^(i u ((1/3)(Subscript[X, 1])+5(Subscript[X, 2]))))] = 𝔼[(e^(i(1/3)u (Subscript[X, 1])))(e^(i 5u (Subscript[X, 2])))]
  = 𝔼[(e^(i ((u/3))(Subscript[X, 1])))]𝔼[(e^(i(5u)(Subscript[X, 2])))]    ((Subscript[X, 1]) and (Subscript[X, 2]) are independent)
  = (((1-i ((u/3)) 3β))^(-2α))(((1-i (5u) (β/5)))^(-α/3))
  = (((1-i u β))^(-7α/3)).

Calculations

Clear[α,β];
CharacteristicFunction[GammaDistribution[α,β],u]

(b)

From the characteristic function in (a) we see that Y~Γ(7α/3,β).

Calculations

Clear[α,β];
CharacteristicFunction[GammaDistribution[7α/3,β],u]

(c)

Clear[α,β,u];
α=β=1;
Ymoment[n_]:=(1/(I^n))*D[(((1-I u β))^(-7α/3)),{u,n}]/.u->0;
mean=Ymoment[1];
variance=Ymoment[2]-(mean^2);
{mean,variance}//FullSimplify

(d)

Mathematica

fY[y_]:=PDF[GammaDistribution[7/3,1],y];

mean=Integrate[y*fY[y],{y,0,Infinity}];

variance=(∫_0^∞)(y^2)*fY[y]\[DifferentialD]y-(mean^2);
{mean,variance}//FullSimplify
{mean,variance}//N

R

#This won't run in Mathematica.

fnc1=function(y) y*dgamma(x=y,shape=7/3,rate=1,log=FALSE)
fnc2=function(y) y^2*dgamma(x=y,shape=7/3,rate=1,log=FALSE)

EY=integrate(f=fnc1,lower=0,upper=Inf) #E[Y]
EY2=integrate(f=fnc2,lower=0,upper=Inf) #E[Y^2]

EY2$value-EY$value^2 #variance

(e)

Clear[α,β,u];
α=β=1;
mean=Expectation[y,y\[Distributed]GammaDistribution[7α/3,β]];
variance=Expectation[(y^2),y\[Distributed]GammaDistribution[7α/3,β]]-(mean^2);
{mean,variance}//FullSimplify

Q3

Info

We have    (({{X}, {Y}, {Z}}))~N((({{3}, {2}, {-5}})),(({{1, 1, -1}, {1, 2, -2}, {-1, -2, 3}}))).

(a)

Note we can write
(({{(Subscript[H, 1])}, {(Subscript[H, 2])}})) = (({{-3, 4, 0}, {-1, -2, 7}}))(({{X}, {Y}, {Z}}))
which is a linear affine transformation of joint-Gaussian RVs.

We have
𝔼[(({{(Subscript[H, 1])}, {(Subscript[H, 2])}}))] = (({{-3, 4, 0}, {-1, -2, 7}}))(({{3}, {2}, {-5}}))=(({{-1}, {-42}}))
and
cov((({{(Subscript[H, 1])}, {(Subscript[H, 2])}})),(({{(Subscript[H, 1])}, {(Subscript[H, 2])}}))) = (({{-3, 4, 0}, {-1, -2, 7}}))(({{1, 1, -1}, {1, 2, -2}, {-1, -2, 3}}))(({{-3, -1}, {4, -2}, {0, 7}})) = (({{17, -46}, {-46, 230}})).

So by Theorem 2 Chapter 2 Notes
(({{(Subscript[H, 1])}, {(Subscript[H, 1])}})) ~ N((({{-1}, {-42}})),(({{17, -46}, {-46, 230}}))).

So
𝔼[(Subscript[H, 1])] = -1.
var((Subscript[H, 2])) = 230
and
cov((Subscript[H, 1]),(Subscript[H, 2])) = -46.

Calculations

Clear[m,QQ,AA];
m=(({{3}, {2}, {-5}}));    QQ=(({{1, 1, -1}, {1, 2, -2}, {-1, -2, 3}}));
PositiveDefiniteMatrixQ[QQ]
AA=(({{-3, 4, 0}, {-1, -2, 7}}));
AA.m//MatrixForm
AA.QQ.Transpose[AA]//MatrixForm

(b)

As a weighted sum of joint-Gaussian RVs    (Subscript[H, 1])=-3X+4Y    is Gaussian (Thrm 2 Ch 2).

We also know that X,Y,Z is joint-Gaussian, so we may use TNC.

Proceeding we have
V = 𝔼[(Subscript[H, 1])|Z] = 𝔼[-3X+4Y|Z]
  = 𝔼[-3X+4Y] + ((cov(-3X+4Y,Z))/(var(Z)))(Z-𝔼[Z])
  = -3𝔼[X]+4𝔼[Y] + ((-3cov(X,Z)+4cov(Y,Z))/(var(Z)))(Z-𝔼[Z])
  = -3*3+4*2 + ((-3(-1)+4(-2))/3)(Z-(-5))
  = -(28/3)-(5/3)Z.

Important property.
cov((∑_(i=1)^m)(Subscript[a, i])(Subscript[A, i]),(∑_(j=1)^n)(Subscript[b, j])(Subscript[B, j])) = 𝔼[(∑_(i=1)^m)(Subscript[a, i])(Subscript[A, i])(∑_(j=1)^n)(Subscript[b, j])(Subscript[B, j])]-𝔼[(∑_(i=1)^m)(Subscript[a, i])(Subscript[A, i])]𝔼[(∑_(j=1)^n)(Subscript[b, j])(Subscript[B, j])]
  = 𝔼[(∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])(Subscript[A, i])(Subscript[B, j])]-𝔼[(∑_(i=1)^m)(Subscript[a, i])(Subscript[A, i])]𝔼[(∑_(j=1)^n)(Subscript[b, j])(Subscript[B, j])]
  = (∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])𝔼[(Subscript[A, i])(Subscript[B, j])]-(∑_(i=1)^m)(Subscript[a, i])𝔼[(Subscript[A, i])](∑_(j=1)^n)(Subscript[b, j])𝔼[(Subscript[B, j])]
  = (∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])𝔼[(Subscript[A, i])(Subscript[B, j])]-(∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])𝔼[(Subscript[A, i])]𝔼[(Subscript[B, j])]
  = (∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])(𝔼[(Subscript[A, i])(Subscript[B, j])]-𝔼[(Subscript[A, i])]𝔼[(Subscript[B, j])])
  = (∑_(i=1)^m)(∑_(j=1)^n)(Subscript[a, i])(Subscript[b, j])cov((Subscript[A, i]),(Subscript[B, j])).

Calculations

-3*3+4*2 + ((-3(-1)+4(-2))/3)(Z-(-5))//Expand

(c)

From (b) we know TNC may be used.

Proceeding we have
𝔼[((((Subscript[H, 1])-V))^2)] = 𝔼[(((-3X+4Y-𝔼[-3X+4Y|Z]))^2)]
  = var(-3X+4Y)-((cov(((-3X+4Y,Z))^2))/(var(Z)))
  = (((-3))^2)var(X)+(4^2)cov(Y)+2(-3)4cov(X,Y)-((((-3cov(X,Z)+4cov(Y,Z)))^2)/(var(Z)))
  = (((-3))^2)1+(4^2)*2+2(-3)4*1-((((-3(-1)+4(-2)))^2)/3)
  = (26/3).

Calculations

(((-3))^2)1+(4^2)*2+2(-3)4*1-((((-3(-1)+4(-2)))^2)/3)

(d)

First note that
(Subscript[H, 1])-V = -3X+4Y-(-(28/3)-(5/3)Z)    (using result from (a))
  = -3X+4Y+(5/3)Z+(28/3)
  = (({{-3, 4, (5/3)}}))(({{X}, {Y}, {Z}}))+(28/3)
which as a linear affine combination of joint-Gaussian RVs is Gaussian (Thrm 2 Ch 2). 

So by Theorem 2 Chapter 2 Notes
𝔼[(Subscript[H, 1])-V] =  (({{-3, 4, (5/3)}}))𝔼(({{X}, {Y}, {Z}}))+(28/3)
  = (({{-3, 4, (5/3)}}))(({{3}, {2}, {-5}}))+(28/3)
  = 0

Also by Theorem 2 Chapter 2 Notes
var((Subscript[H, 1])-V) = (({{-3, 4, (5/3)}}))cov((({{X}, {Y}, {Z}})),(({{X}, {Y}, {Z}})))(({{-3}, {4}, {(5/3)}}))
  = (({{-3, 4, (5/3)}}))(({{1, 1, -1}, {1, 2, -2}, {-1, -2, 3}}))(({{-3}, {4}, {(5/3)}}))
  = (26/3).

Thefore
𝔼[((((Subscript[H, 1])-V))^2)] = var((Subscript[H, 1])-V)+((𝔼[(Subscript[H, 1])-V])^2)
  = (26/3).

So
𝔼[(((2X-6Z -V))^2)]  = var(2X-6Z -V)+((𝔼[2X-6Z -V])^2)
  = 171+(0^2) = 171.

Another way to find expectation
𝔼[(Subscript[H, 1])-V] = 𝔼[-3X+4Y-𝔼[-3X+4Y|Z]]
  = 𝔼[-3X+4Y]-𝔼[[-3X+4Y|Z]]
  = 𝔼[-3X+4Y]-𝔼[-3X+4Y]    (tower law -- Prop 1 Ch 2)
  = 0.

Calculations

(({{-3, 4, (5/3)}})).(({{3}, {2}, {-5}}))+(28/3)

(({{-3, 4, (5/3)}})).(({{1, 1, -1}, {1, 2, -2}, {-1, -2, 3}})).(({{-3}, {4}, {(5/3)}}))