TITLE: Find the distribution of X, EX, and VarX.
QUESTION [5 upvotes]: Suppose that the random variable $X$ is uniformly distributed symmetrically around zero, but in such a way that the parameter is uniform on $(0,1)$; that is, suppose that $$X\mid A=a\in U(-a,a) \text{ with } A\in U(0,1).$$ Find the distribution of $X$, $EX$, and $\operatorname{Var}X$. 
The answers in the book are $f_X(x)=-\frac{1}{2} \log|x|, \; -1<x<1; \; EX=0, \text{ and } \operatorname{Var}X=\frac{1}{9}$.
Any help on how to work this type of problem would be greatly appreciated.

REPLY [5 votes]: Let $Y\sim U([0,1])$ and $X|Y=y\sim U([-y,y])$
We know that by definition: $f(x,y)=f_{Y}(y)\cdot f_{X|Y}(x|y)$.
Since $Y\sim U([0,1])$ we have it that $f_{Y}(y)=1$ when $y\in[0,1]$
and is zero otherwise. thus $f(x,y)=0$ when $y\not\in[0,1]$ and
is $f_{X|Y}(x|y)$ otherwise.
We are also given that $X|Y=y\sim U([-y,y])$ hence $f_{X|Y}(x|y)=\frac{1}{y-(-y)}=\frac{1}{2y}$
when $x\in[-y,y]$ and is zero otherwise.
We conclude 
$$
f(x,y)=\begin{cases}
\frac{1}{2y} & y\in[0,1],x\in[-y,y]\\
0 & \text{otherwise}
\end{cases}
$$
Note that $x\in[-y,y]$ means $-y\leq x\leq y$, and thus $y\geq x$,
it is also clear that $y\leq1$
Also, $x\geq-y$ means $y\geq-x$ and since also $y\geq x$ we get
$y\geq|x|$
Now that we have the joint density we can get $f_{X}(x)$ by integrating:
$$
f_{X}(x)=\int_{-\infty}^{\infty}f(x,y)\, dy=\int_{|x|}^{1}\frac{1}{2y}\, dy=\frac{1}{2}(\log(y)|_{|x|}^{1})=\frac{1}{2}(\log(1)-\log(|x|))=-\frac{1}{2}\log|x|
$$
Now, $EX=EE[X|Y]$. $X|Y\sim U([-y,y])$ hence $E[X|Y|]=\frac{y+(-y)}{2}=0$.
Thus $EX=E[0]=0$.
Now we can calculate $Var(X)$: 
$$
Var(X)=EX^{2}-(EX)^{2}=EX^{2}
$$
Since $x\in[-y,y]$ and $y\in[0,1]$ we have it that $x\in[-1,1]$.
$$
EX^{2}=\int_{-\infty}^{\infty}x^{2}f_{X}(x)\, dx
$$
$$
=\int_{-1}^{1}x^{2}\cdot-\frac{1}{2}\log(|x|)\, dx
$$
$$
=-\frac{1}{2}\int_{-1}^{1}x^{2}\log(|x|)\, dx
$$
Using integration by parts with $u=\log(|x|),v'=x^{2}$we get 
$$
\int x^{2}\log(|x|)\, dx=\log(|x|)\cdot\frac{x^{3}}{3}-\int\frac{1}{x}\cdot\frac{x^{3}}{3}=\log(|x|)\cdot\frac{x^{3}}{3}-\frac{1}{3}\cdot\frac{x^{3}}{3}=\frac{x^{3}}{3}(\log(|x|)-\frac{1}{3})
$$
Hence 
$$
-\frac{1}{2}\int_{-1}^{1}x^{2}\log(|x|)\, dx
$$
$$
=-\frac{1}{2}(\frac{x^{3}}{3}(\log(|x|)-\frac{1}{3})|_{-1}^{1})
$$
$$
=-\frac{1}{2}(\frac{1^{3}}{3}(\log(|1|)-\frac{1}{3})-\frac{(-1)^{3}}{3}(\log(|-1|)-\frac{1}{3}))
$$
$$
=-\frac{1}{2}(-\frac{1}{3\cdot3}-\frac{1}{3\cdot3})=\frac{1}{9}
$$