37363 - Lab/Tutorial 2 Solutions

Scott Alexander

Q1

(a)

If X~B(n,1/2) then P((Subscript[E, k]))=P(X=k) so
P((Subscript[E, n/4])) = P(X=n/4)
  = (({{n}, {n/4}}))((((1/2)))^(n/4))(((1-(1/2)))^(3n/4)) = ((n!)/((n/4)!(3n/4)!))(1/(2^n))
  ≈ (((Sqrt[2π n])(n^n)(e^(-n)))/((Sqrt[2π n/4])(((n/4))^(n/4))(e^(-n/4))(Sqrt[2π×3×n/4])(((3n/4))^(3n/4))(e^(-3n/4))))(1/(2^n))
  = (((2^((3/2)+n))×(3^(-(1/2)-((3 n)/4))))/(Sqrt[n π])).

Calculations

(((Sqrt[2π n])(n^n)(E^(-n)))/((Sqrt[2π n/4])(((n/4))^(n/4))(E^(-n/4))(Sqrt[2π×3×n/4])(((3n/4))^(3n/4))(E^(-3n/4))))(1/(2^n))//FullSimplify

(b)

If X~Binom(n,1/2) then
P(X=n/4) = ((n!)/((n/4)!(3n/4)!))((((1/2)))^(n/4))((((1/2)))^(3n/4))
  =((n!)/((n/4)!(3n/4)!))((((1/2)))^n).

Calculations

probTrue[n_]:=((n!)/((n/4)!(3n/4)!))((((1/2)))^n);
probApprox[n_]:=(((2^((3/2)+n))×(3^(-(1/2)-((3 n)/4))))/(Sqrt[n π]));
n1=(10^2);
probApprox[n1]/probTrue[n1]//N
n2=(10^4);
probApprox[n2]/probTrue[n2]//N

(c)

The hint gives two equations in two unknowns
t((Subscript[n, 1])) = C (Subscript[n, 1]^α)    and    t((Subscript[n, 2])) = C (Subscript[n, 2]^α).

Solving equations for α.
((t((Subscript[n, 1])))/(C (Subscript[n, 1]^α))) = ((t((Subscript[n, 2])))/(C (Subscript[n, 2]^α)))    ⟹    (((((Subscript[n, 2])/(Subscript[n, 1]))))^α) = ((t((Subscript[n, 2])))/(t((Subscript[n, 1]))))    ⟹    α = (Subscript[log, (Subscript[n, 2])/(Subscript[n, 1])])(((t((Subscript[n, 2])))/(t((Subscript[n, 1])))))

Solving equations for C.
C = ((t((Subscript[n, 1])))/(Subscript[n, 1]^α))    or    C=((t((Subscript[n, 2])))/(Subscript[n, 2]^α))

Checking last using α we see
C = ((t((Subscript[n, 1])))/(Subscript[n, 1]^α)) = ((t((Subscript[n, 1]))/(Subscript[n, 2]^α))/((Subscript[n, 1]^α)/(Subscript[n, 2]^α))) = ((t((Subscript[n, 1])))/(Subscript[n, 2]^α))(((((Subscript[n, 2])/(Subscript[n, 1]))))^α) = ((t((Subscript[n, 1])))/(Subscript[n, 2]^α))(((((Subscript[n, 2])/(Subscript[n, 1]))))^((Subscript[log, (Subscript[n, 2])/(Subscript[n, 1])])((t((Subscript[n, 2])))/(t((Subscript[n, 1])))))) = ((t((Subscript[n, 1])))/(Subscript[n, 2]^α))((t((Subscript[n, 2])))/(t((Subscript[n, 1]))))
  = ((t((Subscript[n, 2])))/(Subscript[n, 2]^α)).

Calculations

probTrue[n_]:=((n!)/((n/4)!(3n/4)!))((((1/2)))^n);
n1=(10^5);
tn1=Timing[probTrue[n1]][[1]]//N;
tn1
n2=(10^6);
tn2=Timing[probTrue[n2]][[1]]//N;
tn2
α=Log[n2/n1,tn2/tn1];
α
c=tn2/(n2^α);
c
c ((((10^9)))^α)

Q2

(a)

𝔼[Y Z] = (∑_(y=1)^2)(∑_(z=1)^2)y z*P(Y=z,Z=z) = (∑_(y=1)^2)(∑_(z=1)^2)y z(∑_(x=1)^2)P(X=x,Y=y,Z=z)
  = (∑_(x=1)^2)(∑_(y=1)^2)(∑_(z=1)^2)y z*P(X=x,Y=y,Z=z)
  = 1*1*P(X=1,Y=1,Z=1)+1*2*P(X=1,Y=1,Z=2)+2*1*P(X=1,Y=2,Z=1)+2*2*P(X=1,Y=2,Z=2)
       +  1*1*P(X=2,Y=1,Z=1)+1*2*P(X=2,Y=1,Z=2)+2*1*P(X=2,Y=2,Z=1)+2*2*P(X=2,Y=2,Z=2)

  = 1*1*(5/32)+1*2*(3/32)+2*1*(7/32)+2*2*(2/32)+1*1*(4/32)+1*2*(2/32)+2*1*(6/32)+2*2*(3/32)
  = (65/32)

Calculations

1*1*(5/32)+1*2*(3/32)+2*1*(7/32)+2*2*(2/32)+  1*1*(4/32)+1*2*(2/32)+2*1*(6/32)+2*2*(3/32)

p=Table[0,{2},{2},{2}];
p[[1,1,1]]=5/32; p[[2,1,1]]=4/32;
p[[1,1,2]]=3/32; p[[2,1,2]]=2/32;
p[[1,2,1]]=7/32; p[[2,2,1]]=6/32;
p[[1,2,2]]=2/32; p[[2,2,2]]=3/32;
(∑_(x=1)^2)(∑_(y=1)^2)(∑_(z=1)^2)y*z*p[[x,y,z]]

(b)

𝔼[X|Y=2] = (∑_(x=1)^2)x*P(X=x|Y=2) = (∑_(x=1)^2)x*((P(X=x,Y=2))/(P(Y=2)))
  = (((∑_(x=1)^2)x*P(X=x,Y=2))/(P(Y=2))) = (((∑_(x=1)^2)x(∑_(z=1)^2)P(X=x,Y=2,Z=z))/((∑_(x=1)^2)(∑_(z=1)^2)P(X=x,Y=2,Z=z)))
  = ((1*(P(X=1,Y=2,Z=1)+P(X=1,Y=2,Z=2))+2*(P(X=2,Y=2,Z=1)+P(X=2,Y=2,Z=2)))/(P(X=1,Y=2,Z=1)+P(X=1,Y=2,Z=2)+P(X=2,Y=2,Z=1)+P(X=2,Y=2,Z=2)))
  = ((1*((7/32)+(2/32))+2*((6/32)+(3/32)))/((7/32)+(2/32)+(6/32)+(3/32)))
  = (3/2)

Calculations

((1*((7/32)+(2/32))+2*((6/32)+(3/32)))/((7/32)+(2/32)+(6/32)+(3/32)))

(((∑_(x=1)^2)(∑_(z=1)^2)x*p[[x,2,z]])/((∑_(x=1)^2)(∑_(z=1)^2)p[[x,2,z]]))

(c)

𝔼[Y Z|X=1] = (∑_(y=1)^2)(∑_(z=1)^2)y z* P(Y=y,Z=z|X=1) =  (∑_(y=1)^2)(∑_(z=1)^2)y z* ((P(X=1,Y=y,Z=z))/(P(X=1)))
  =  (((∑_(y=1)^2)(∑_(z=1)^2)y z* P(X=1,Y=y,Z=z))/((∑_(y=1)^2)(∑_(z=1)^2)P(X=1,Y=y,Z=z)))
  = (33/17)

Calculations

(((∑_(y=1)^2)(∑_(z=1)^2)y*z* p[[1,y,z]])/((∑_(y=1)^2)(∑_(z=1)^2)p[[1,y,z]]))

(d)

𝔼[X|Y=2,Z=2] = (∑_(x=1)^2)x* P(X=x|Y=2,Z=2) =  (∑_(x=1)^2)x* ((P(X=x,Y=2,Z=2))/(P(Y=2,Z=2)))
  = (((∑_(x=1)^2)x* P(X=x,Y=2,Z=2))/((∑_(x=1)^2)P(X=x,Y=2,Z=2)))
  = (8/5)

Calculations

(((∑_(x=1)^2)x* p[[x,2,2]])/((∑_(x=1)^2)p[[x,2,2]]))

Q3

We have
(Subscript[f, X,Y])(x,y) = ({{{, ({{(7/54)x (e^(-7y/x-x/3)),, x,y>0}, {0,, otherwise}})}}).

Calculations

(* maths syntax *)
fXY[x_,y_]:=(7/54)x (E^(-7y/x-x/3));
Plot3D[fXY[x,y],{x,0,4},{y,0,4},AxesLabel->{"x","y","(Subscript[f, X, Y])(x,y)"},PlotRange->All]

(∫_0^∞)(∫_0^∞)fXY[x,y]\[DifferentialD]x\[DifferentialD]y

(* code syntax  *)
fXY[x_,y_]:=7*x*Exp[-7y/x-x/3]/54;Integrate[fXY[x,y],{x,0,Infinity},{y,0,Infinity}]

(a)

First we find the marginal density of X, which for x>0 is
(Subscript[f, X])(x) = (∫_(-∞)^∞)(Subscript[f, X,Y])(x,y)dy
  =  (∫_(-∞)^0)0dx+ (∫_0^∞)(7/54)x (e^(-7y/x-x/3))dy = (7/54)x (e^(-x/3))(∫_0^∞)(e^(-7y/x))dy
  = (7/54)x (Subscript[(e^(-x/3))[-(x/7)(e^(-7y/x))], 0]^∞) = -(1/54)(x^2) (e^(-x/3))((lim_(y->∞))(e^(-7y/x))-1)
  = (1/54)(x^2) (e^(-x/3))
so
(Subscript[f, X])(x) = ({{{, ({{(1/54)(x^2) (e^(-x/3)),, x>0}, {0,, otherwise}})}}).

Then the conditional density of Y|X=x for x,y>0
(Subscript[f, Y|X])(x,y) = (((Subscript[f, X,Y])(x,y))/((Subscript[f, X])(x)))
  = (((7/54)x (e^(-7y/x-x/3)))/((1/54)(x^2) (e^(-x/3))))
  = (7/x) (e^(-(7/x)y))
so
(Subscript[f, Y|X])(x,y) = ({{{, ({{(7/x) (e^(-(7/x)y)),, x,y>0}, {0,, otherwise}})}}).    [3 marks]

Calculations

(((7/54)x (E^(-7y/x-x/3)))/((1/54)(x^2) (E^(-x/3))))

(b)

It is clear that (Subscript[f, Y|X])>0.

Showing the conditional density integrates to 1 we have
(∫_(-∞)^∞)(Subscript[f, Y|X])(x,y)dy = (∫_(-∞)^0)0dy+(∫_0^∞)(7/x) (e^(-(7/x)y))dy = (∫_0^∞)(d/(dy))(-(e^(-(7/x)y)))dy
  = (Subscript[[-(e^(-(7/x)y))], 0]^∞) = -((lim_(x->∞))(e^(-(7/x)y))-1)
  = 1.

(c)

It is clear from the density found in (a) that (Y|X=x)~Exp(7/x)
(see page 26 Chapter 1 Notes).

(d)

𝔼[Y|X=x] = (∫_(-∞)^∞)y (Subscript[f, Y|X])(x,y)dy
  = (∫_∞^0)0* (Subscript[f, Y|X])(x,y)dy+(∫_0^∞)y (7/x) (e^(-(7/x)y))dy
  = (∫_0^∞)y (d/(dy))(-(e^(-(7/x)y)))dy = (Subscript[[-y (e^(-(7/x)y))], 0]^∞)+(∫_0^∞)(e^(-(7/x)y)) (d/(dy))ydy
  = (Subscript[[-y (e^(-(7/x)y))], 0]^∞)+(∫_0^∞)(e^(-(7/x)y)) dy = (Subscript[[-y (e^(-(7/x)y))], 0]^∞)+(x/7)(∫_0^∞)(7/x)(e^(-(7/x)y)) dy
  = (Subscript[[-y (e^(-(7/x)y))], 0]^∞)+(x/7)    (densitiy integrates to 1)
  = -(lim_(y->∞)) (y/(e^((7/x)y)))+0+(x/7) = -(lim_(y->∞)) (((d/(dy))y)/((d/(dy))(e^((7/x)y))))+(x/7)    (L'Hospital Rule)
  =  -(lim_(y->∞)) (1/((7/x)(e^((7/x)y))))+(x/7) = (x/7)

This can also be seen directly from (c).

(e)

Maths-like syntax

fXY[x_,y_]:=(7/54)x (E^(-7y/x-x/3)); (* density of X,Y *)
fX[x_]:=Assuming[{x>0},(∫_0^∞)fXY[x,y]\[DifferentialD]y]    (* density of X *)
fX[x] (* view *)

fYcondX[x_,y_]:=((fXY[x,y])/(fX[x])); (* density of Y|X=x *)
fYcondX[x,y] (* view *)

Assuming[{x>0},(∫_0^∞)fYcondX[x,y]\[DifferentialD]y] (* density of Y|X=x integrates to 1 *)

Assuming[{x>0},(∫_0^∞)y fYcondX[x,y]\[DifferentialD]y] (* E[Y|X=x] *)

Code syntax

fXY[x_,y_]:=7*x*Exp[-7y/x-x/3]/54; (* density of X,Y *)
fX[x_]:=Assuming[{x>0},Integrate[fXY[x,y],{y,0,∞}]]    (* density of X *)
fX[x] (* view *)
fYcondX[x_,y_]:=fXY[x,y]/fX[x]; (* density of Y|X=x *)
fYcondX[x,y] (* view *)

Assuming[{x>0},Integrate[fYcondX[x,y],{y,0,∞}]] (* density of Y|X=x integrates to 1 *)

Assuming[{x>0},Integrate[y*fYcondX[x,y],{y,0,∞}]] (* E[Y|X=x] *)