# PDF of the difference between two independent beta random variables

I am having trouble deriving the distribution of the difference of two beta random variables and would like some help verifying the steps I have taken. In particular calculating the bounds.

Say I have $X_1\sim\text{Beta}(a_1,b_1)$ and $X_2\sim\text{Beta}(a_2,b_2)$, independent, and am interested in calculating the distribution of $X_1-X_2$. So here is what I have come up with so far:

Let $Z=X_1-X_2$ and $W=X_1$ where $0\leq X_i\leq 1$ for $i=1,2$. So $X_1=W$ and $X2 = W-Z$.

Likewise $\frac{dX_1}{dW}=1$, $\frac{dX_1}{dZ}=0$, $\frac{dX_2}{dW}=1$, and $\frac{dX_2}{dZ}=-1$. Then the determinant of the Jacobian would be $|J| = 0\times1 - (-1)\times1=1$

Then we have that

\begin{align} f_{Z,W}(z,w) &=f_{X_1,X_2}(J_1(z,w),J_2(z,w))\times|J|\\ &=f_{X_1,X_2}(w,z-w)\\ &=f_{X_1}(w) f_{X_2}(z-w)\\ &=\text{Beta}(w;a_1,b_1)\times\text{Beta}(w-z;a_2,b_2)\\ &=\frac{(w)^{1-a_1}(1-w)^{1-b_1}}{\beta(a_1,b_1)}\times\frac{(w-z)^{1-a_2}(1-(w-z))^{1-b_2}}{\beta(a_2,b_2)} \end{align}

From there I could integrate out $W$ from $f_{Z,W}(z,w)$ to get the quantity of interest, i.e., the distribution of $Z=X_1-X_2$.

So now this is where I am stuck. I have the following:

$$f_Z(z)=\int f_{Z,W}(z,w)dw=\int \text{Beta}(w;a_1,b_1)\times\text{Beta}(w-z;a_2,b_2) dw$$

But I do not understand how to obtain the bounds for the integral, and if the integral needs to be broken into parts or not. Let me know also if any of the above steps are incorrect.

• it's not possible to differentiate with respect to random variables, at least not in the naive way being proposed. Also I don't understand the equality $$f_{X_1}(w) f_{X_2}(z-w)=\text{Beta}(w;a_1,b_1)\times\text{Beta}(w-z;a_2,b_2)$$ - do you mean the distribution function of a beta-distributed random variable with those parameters? Or the random variable itself? Because the latter interpretation does not seem to make sense to me. Also is $f_Z$ supposed to be the probability density function (PDF) or the cumulative distribution function (CDF)? – Chill2Macht Jun 14 '16 at 13:40
• For the last step, it should be \begin{align} f_{Z,W}(z,w) &=f_{X_1,X_2}(J_1(z,w),J_2(z,w))\times|J|\\ &=f_{X_1,X_2}(w,z-w)\\ &=f_{X_1}(w) f_{X_2}(z-w)\\ &=\text{Beta}(w;a_1,b_1)\times\text{Beta}(w-z;a_2,b_2)\\ &=\frac{(w)^{a_1-1}(1-w)^{b_1-1}}{\beta(a_1,b_1)}\times\frac{(w-z)^{a_2-1}(1-(w-z))^{b_2-1}}{\beta(a_2,b_2)} \end{align} – Julie Jul 30 '18 at 15:29

We have $0<x_1<1$ and $0<x_2<1$. Since $W=X_1$ and $X_2=W-Z$, we then have $0<w<1$ and $0<w-z<1\quad\longrightarrow\quad z<w<1+z$ after transformation. It is easy to see that these are equivalent to $w>0$, $w<1$, $z<w$, and $z>w-1$. To make it more clearly, let's plot these four inequalities
From $w$-axis viewpoint, the region $0<w<1$ is bounded by $z=w$ and $z=w-1$. On the other hand, from $z$-axis viewpoint, the region $-1<z<0$ is bounded by $w=1+z$ and $w=0$ and the region $0<z<1$ is bounded by $w=1$ and $w=z$. Hence, If we refer to figure above, it is seen that the marginal pdf of $W$ is given by $$f_W(w)=\left\{ \begin{array}{l} &\displaystyle\int_{w-1}^{w}f_{W,Z}(w,z)\ dz\qquad &0<w<1\\[10pt] &0\qquad &\text{elsewhere} \end{array} \right.$$ In a similar manner, the marginal pdf of $Z$ is given by $$f_Z(z)=\left\{ \begin{array}{l} &\displaystyle\int_{0}^{1+z}f_{W,Z}(w,z)\ dw\qquad &-1<z<0\\[10pt] &\displaystyle\int_{z}^{1}f_{W,Z}(w,z)\ dw\qquad &0<z<1\\[10pt] &0\qquad &\text{elsewhere} \end{array} \right.$$
• @RustyStatistician Seems correct to me. Finding the integration to obtain the marginal pdf of $Z$ wouldn't be easy, though. You may also use convolution to determine the joint pdf. – Sophie Agnesi Jun 21 '16 at 2:48