I have the following stepwise function:$$f(x) = \begin{cases} \frac{1}{3} & -1\le x \lt 0 \\ \frac{2}{3} & 0 \le x \le 1 \\ 0 & \text{otherwise} \end{cases} $$
I wonder how I can derive $E(X)$ and $Var(X)$ of a stepwise uniform function using the integral. If I draw it I would say the mean is at $x = 1/4$ (as then the area below the function equals $0.5$). But when I am integrating it I get $1/6$.
Can someone help me and show how I properly solve this question?
Thanks a lot!
$\endgroup$ 22 Answers
$\begingroup$Here is a start:
$$\mu = E(X) = \int_{-1}^1 xf(x)\,dx = \int_{-1}^0 x(1/3)\,dx + \int_0^1 x(2/3)\,dx = \dots\,.$$ Find $E(X^2)$ similarly, and use $Var(X) = E(X^2) - \mu^2.$
$\endgroup$ 1 $\begingroup$Thank you already!
So, then
$$\mu=E[X]=\int_{-1}^0x(1/3)dx + \int_0^1x(2/3)dx = (0-{1\over6})+({1\over3}-0)={1\over6}$$
and
$$Var[X]=\int_{-1}^0x^2(1/3)dx + \int_0^1x^2(2/3)dx - \mu^2=(0+{1\over9})+({2\over9}-0)-({1\over6})^2={11\over36}$$
Is this correct?
$\endgroup$