Verify whether my variance calculation is correct

48 Views Asked by At

I am a little stuck with the idea of variance of a random variable, so I just wanted to know whether my variance calculation is correct.

Suppose we had a game where we flip a coin and I get $\$1$ if it lands on heads and I lose $\$0.50$ if it lands on tails. I want to find the variance of the distribution.

What I did was I defined a random variable $$X=\begin{cases} 1, & \text{if heads} \\ -0.5, & \text{if tails} \end{cases}$$ Then $$\mathbb{E}(X)=\frac{1}{2}\cdot1+\frac{1}{2}\cdot-\frac12=\frac14.$$ Since $X\in\{1, -0.5\}$, we have $X^2\in\{1, 0.25\}$, and $$\mathbb{E}(X^2)=\frac{1}{2}\cdot1+\frac{1}{2}\cdot\frac14=\frac58.$$ Since $\operatorname{Var}(X)=\mathbb{E}(X^2)-(\mathbb{E}(X))^2$, we have $$\operatorname{Var}(X)=\frac58-\left(\frac14\right)^2=\frac58-\frac{1}{16}=\frac{9}{16}.$$ Are all my steps correct? I ask because I don't know how to intuitively check my answer.

1

There are 1 best solutions below

0
On BEST ANSWER

This is correct. As for "intuitive" you need to trust the math but you can numerically verify it using Python:

import statistics
import random
statistics.variance([1-1.5*random.randint(0,1) for _ in range(100000)]) - 9/16

With answer on order $10^{-5}$ so very close.