# Compound of uniform and gamma probability distributions

I am trying to compute the distribution of a uniform distribution whose upper limit is drawn from a gamma distribution.

That is,

$$X \sim \Gamma(\alpha,\beta)$$
$$Y \sim U(0,X)$$

We know:

$$f_X(x)={\beta^\alpha \over \Gamma(\alpha)} x^{\alpha-1} e^{-\beta x}$$

and

$$f_{Y\mid X}(y\mid x) = \begin{cases} {1\over X} & 0 \le y \le X, \\ 0 & \text{otherwise}, \end{cases}$$

but I get lost at the integral

$$f_Y(y) = \int_{x=0}^\infty f_{Y\mid X}(y\mid x) f_X(x)\,dx$$

I'm embarrassed to ask because I think the answer must be simple. But it's been too long since I've done this. I get:

$$f_Y(y)=\int_{x=0}^{x=\Gamma^{-1}(y)} 1\, dx = \Gamma^{-1}(y)$$

but I don't think that's right. Please help! I'm a neuroscientist and I'm trying to understand a distribution I've measured.

• $$f_Y(y)=E(X^{-1}\mathbf 1_{X>y})=\int_y^\infty x^{-1}f_X(x)dx=\ldots$$
– Did
Commented Nov 8, 2015 at 18:10
• I'd have written $Y\mid X\sim\operatorname{Uniform}(0,X).$ I suppose one could argue that conditioning on $X$ is already clear from the fact that $X$ is seen in the distribution, but at some point one wants to write $Y\sim\cdots\cdots$ and have that represent the marginal distribution of $Y. \qquad$ Commented Nov 18, 2019 at 18:26

Write out the integrand: $$f_{Y \mid X}(y \mid x) f_X(x) = \frac{1}{x} \frac{\beta^\alpha x^{\alpha-1} e^{-\beta x}}{\Gamma(\alpha)}, \quad 0 \le y \le x.$$ So the marginal density of $Y$ is $$f_Y(y) = \int_{x = y}^\infty \frac{\beta^\alpha x^{\alpha-2} e^{-\beta x}}{\Gamma(\alpha)} \, dx.$$ Note two things: first, that the lower limit of the integral must be $x = y$, because if $x < y$, the conditional density of $Y \mid X$ is zero. Second, we simplified the integrand by writing $x^{\alpha-1}/x = x^{\alpha-2}$. Now we write $$f_Y(y) = \frac{\Gamma(\alpha-1)}{\Gamma(\alpha)} \beta \int_{x=y}^\infty \frac{\beta^{\alpha-1} x^{\alpha-2} e^{-\beta x}}{\Gamma(\alpha-1)} \, dx,$$ and recognize that $$\frac{\Gamma(\alpha-1)}{\Gamma(\alpha)} = \frac{1}{\alpha-1},$$ and the integrand is now a gamma density for shape parameter $\alpha^* = \alpha - 1$ and rate parameter $\beta^* = \beta$. Thus, $$f_Y(y) = \frac{\beta}{\alpha-1} \Pr[X^* > y],$$ where $X^* \sim \operatorname{Gamma}(\alpha^*, \beta^*)$.
• Thank you! So $f_Y(y)$ is $\beta\over{\alpha-1}$ multiplied by the cumulative distribution function of $\Gamma(\alpha-1,\beta)$. Commented Nov 9, 2015 at 18:05
• It is actually the survival function: $$\Pr[X^* > y] = 1 - \Pr[X^* \le y] = 1 - F_{X^*}(y).$$ Commented Nov 9, 2015 at 20:09
• Problems like this remind me of why I prefer to say the gamma DISTRIBUTION is $$\frac 1 {\Gamma(\alpha)} (\beta x)^{\alpha-1} e^{-\beta x} \big(\beta\,dx\big) \text{ for } x\ge0$$ instead of saying what the gamma DENSITY is, with that stray extra $\beta$ that then looks as if it lacks a companion $x. \qquad$ Commented Nov 18, 2019 at 18:36
The answer by @heropup needs adjustments when $$0 < \alpha < 1$$, as $$\alpha^*$$ then falls outside the domain for the Gamma's distribution shape parameter. Thankfully the recursive properties of both the incomplete gamma function, and the gamma function itself, allow us to circumvent this limitation. Using $$\bar{\text{F}}_X(x)$$ to denote a survival function : \begin{align}f_Y(y) &= \frac{\beta}{\alpha-1}\bar{\text{F}}_{X^*}(y)\\ &= \frac{\beta}{\alpha-1}\frac{\Gamma(\alpha-1,\beta y)}{\Gamma(\alpha-1)}\frac{(\alpha-1)}{(\alpha-1)}\\ &= \frac{\beta}{\alpha-1}\frac{(\alpha-1)\Gamma(\alpha-1,\beta y)}{\Gamma(\alpha)}\\ &= \frac{\beta}{\alpha-1}\frac{(\alpha-1)\Gamma(\alpha-1,\beta y)}{\Gamma(\alpha)}+\frac{\beta}{\alpha-1}\frac{(\beta y)^{\alpha-1}e^{-\beta y}}{\Gamma(\alpha)}-\frac{\beta}{\alpha-1}\frac{(\beta y)^{\alpha-1}e^{-\beta y}}{\Gamma(\alpha)}\\ &= \frac{\beta}{\alpha-1}\frac{(\alpha-1)\Gamma(\alpha-1,\beta y)+(\beta y)^{\alpha-1}e^{-\beta y}}{\Gamma(\alpha)}-\frac{\beta}{\alpha-1}\frac{(\beta y)^{\alpha-1}e^{-\beta y}}{\Gamma(\alpha)}\\ &= \frac{\beta}{\alpha-1}\frac{\Gamma(\alpha,\beta y)}{\Gamma(\alpha)}-\frac{\beta}{\alpha-1}\frac{(\beta y)^{\alpha-1}e^{-\beta y}}{\Gamma(\alpha)}\\ &= \frac{\beta}{\alpha-1}\bar{\text{F}}_{X}(y)-\frac{f_X(y)}{\alpha-1}\\ &= \frac{\beta\bar{\text{F}}_{X}(y)-f_X(y)}{\alpha-1} \end{align}
Which is perfectly equivalent to @heropup's answer, and now extends to the full domain of $$\alpha$$.