0

Suppose random variable $X$ takes 3 values $1, 2, 3$ with probability $\frac{1}{3}$. Sample 1000 times from $X$ independently and do the following operations. Take a number $T=0$. If 1 comes, add 0.18 with $T$, if 2 comes add 0.05 with $T$ if 3 comes add -0.29 with $T$. It is clear expected value of $T$ is $\frac{(0.18+0.05-0.29)1000}{3}=-20$. How to calculate variance of $T$? Experimentally I am getting around 38.75. This is my Sage code.

C= [0.18, 0.05, -0.29]      
D=[]
for j in range(10000):
 T=0
 for i in range(N):
    aa=random()
    if(aa<=1/3):
        T=T+C[0]
    if(aa>1/3 and aa<=2/3):
        T=T+C[1]  
    if(aa>2/3):
        T=T+C[2]    

 D.append(T)
print mean(D), variance(D)
str
  • 45
  • 4

1 Answers1

1

The variance for a sum of k random variables is defined as
$$Var(X)=\sum_{l=1}^k(Var(X_l))+\sum_{l<m}(Cov(X_l,X_m)$$
As your X's are independent, the covariance part can be dropped.
the variance of a discrete random variable with n possible values is defined as
$$Var(Y)=\frac{1}{n}*(\sum_{i=1}^ny_i^2-\frac{1}{n}(\sum_{i=1}^n y_i)^2) $$

We can calculate this with knowing that n=3; and Y = {0.18, 0.05, -0.29} $$Var(Y) = 0.03926667 $$ Now replacing $Var(X_l)$ with $Var(Y)$ in formula 1 and k = 1000
We reach $$Var(X) = 1000*0.03926667=39.26667$$

Mr Pi
  • 1,315
  • 1
  • 7
  • 15