In: Statistics and Probability
Use simulation to prove that when X ∼ N(0, 1), Z ∼ N(0, 1), Y = X3 + 10X +Z, we have V ar(X +Y ) = V ar(X) +V ar(Y ) + 2Cov(X, Y ) and V ar(X −Y ) = V ar(X) + V ar(Y ) − 2Cov(X, Y ).
Following is the R code with comments (all statements starting with # are comments)
#set the random seed
set.seed(123)
#set the number of simulations
N<-10000
#draw X from N(0,1)
x<-rnorm(N)
#draw Z from N(0,1)
z<-rnorm(N)
#calculate y
y<-x^3+10*x+z
#calculate the variance of (X+Y)
v_xpy<-var(x+y)
#calculate the variance using var(x)+var(y)+2*cov(x,y)
v<-var(x)+var(y)+2*cov(x,y)
sprintf('Var(X+Y)=%.4f and
Var(X)+Var(Y)+2Cov(X,Y)=%.4f',v_xpy,v)
#calculate the variance of (X-Y)
v_xmy<-var(x-y)
#calculate the variance using var(x)+var(y)-2*cov(x,y)
v<-var(x)+var(y)-2*cov(x,y)
sprintf('Var(X-Y)=%.4f and
Var(X)+Var(Y)-2Cov(X,Y)=%.4f',v_xmy,v)
## get this output
Hence proved that
Var(X +Y) &= Var(X) +Var(Y) + 2Cov(X,Y) and
Var(X −Y) &= Var(X) + Var(Y) − 2Cov(X,Y)