# Variance of uniform distribution

I can see how one can compute the variance of a uniform distribution on $[a,b]$ using

$$Var[X] = E[X^2] - E[X]^2 = \frac{(b-a)^2}{12}$$

as explained e.g. here: http://www.statlect.com/probability-distributions/uniform-distribution

However, how does one compute it using

$$Var[X] = E[(X - E[X])^2]$$ ?

My approach would be transform $(X-E[X])^2$ to a new random variable $Y$ which follows a cdf $$G(y) = P(Y < y) = P((X-E[X])^2 < y) = P(X < \sqrt{y} + E[X]) = \frac{\sqrt{y} + E[X]-a}{b-a}$$

whenever $\sqrt{y} + E[X] \in [a,b]$, i.e., $y \in [a_Y, b_Y]$ where $a_Y = (\frac{3a-b}{2})^2$ and $b_Y = (\frac{b+a}{2})^2$, and 0 otherwise.

Thus $g(y) = \frac{1}{2(b-a)\sqrt{y}}$ for $y \in [a_Y, b_Y]$ and 0 otherwise.

And then I would compute $$Var[X] = E[(X - E[X])^2] = E[Y] = \int_{a_Y}^{b_Y} y g(y) dy = \frac{1}{2(b-a)} \int_{a_Y}^{b_Y} \sqrt{y} dy$$

which does not yield the desired result.

What goes wrong with my transformation?

• You could just use the law of the unconscious statistician $\operatorname{E}[g(X)] = \int_{-\infty}^\infty g(x) f_X(x) \, dx$ where $g$ is $(X-\mu)^2$ – Glen_b -Reinstate Monica Apr 12 '16 at 16:54
• Err..., $Y = (X-E[X])^2 =\left (X-\frac{a+b}{2}\right)^2$ takes on values in $\left[0,\left(\frac{b-a}{2}\right)^2\right]$ and not what you have written. – Dilip Sarwate Apr 12 '16 at 17:00

However, how does one compute it using $Var[X] = E[(X - E[X])^2]$?

You could just use the law of the unconscious statistician
$\operatorname{E}[g(X)] = \int_{-\infty}^\infty g(x) f_X(x) \, dx$ where $g$ is $(X-\mu)^2$

What goes wrong with my transformation?

Well, this is wrong, for one thing:

$P((X-E[X])^2 < y) = P(X < \sqrt{y} + E[X])$

• What exactly is wrong with that $P(X \ldots)$ ? – bonifaz Apr 12 '16 at 18:21
• @bonifaz For a similar example, consider the distinction between $P(Z^2<2)$ and $P(Z<\sqrt{2})$ (if it helps, you could imagine $Z$ to be standard normal). If you still don't see it, draw a picture. – Glen_b -Reinstate Monica Apr 13 '16 at 0:02