0
$\begingroup$

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)
$\endgroup$
4
  • $\begingroup$ You do the same calculations that you've done for the expected value, but for variance instead: en.wikipedia.org/wiki/Variance#Discrete_random_variable $\endgroup$ Oct 5, 2019 at 8:43
  • $\begingroup$ So variance should be 1000*((0.18^2+0.05^2+0.29^2)*(1/3)-((0.18+0.05+0.29)*(1/3))^2)=39.27 ? $\endgroup$
    – str
    Oct 5, 2019 at 9:02
  • $\begingroup$ look like, congrats! $\endgroup$ Oct 5, 2019 at 9:07
  • 1
    $\begingroup$ Thank you so much for your help. $\endgroup$
    – str
    Oct 5, 2019 at 9:15

1 Answer 1

1
$\begingroup$

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$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.