# Sum of $N$ Gamma distributed random variables being $N$ a Gamma distribution random variable

Let $X$ a gamma-distributed random variable having scale $θ$ and shape $k$:

$$X \sim \Gamma(k, \theta) \equiv \textrm{Gamma}(k, \theta)$$

with its probability density function is: $$f(x;k,\theta) = \frac{x^{k-1}e^{-\frac{x}{\theta}}}{\theta^k\Gamma(k)} \quad \text{ for } x > 0 \text{ and } k, \theta > 0$$

The sum of $N$ independent variables $X_i$ with Gamma distribution will be another Gamma distribution $$\sum_{i=1}^N X_i \sim\mathrm{Gamma} \left( \sum_{i=1}^N k_i, \theta \right)$$

My question

What would be the distribution of $Z$?, being $Z$ $$Z = \sum_{i=1}^N X_i$$ if $N$ is a gamma distributed random variable and $X$ is another gamma distribution random variable $$X \sim \Gamma(k_1, \theta_1) \equiv \textrm{Gamma}(k_1, \theta_1)$$ $$N \sim \Gamma(k_2, \theta_2) \equiv \textrm{Gamma}(k_2, \theta_2)$$

I have the numerical approach but I do not know how to get to an analytical solution

• What is $\displaystyle \sum_{i=1}^N X_i$ intended to mean when $N$ is not an integer? $\qquad$ – Michael Hardy May 30 '18 at 18:03
• If $$X_i \sim \text{Gamma}(k_1,\theta_1)$$ $$Z = \sum_{i=1}^N X_i \sim \text{Gamma}(Nk_1,\theta_1)$$ $$N \sim \text{Gamma}(k_2,\theta_2)$$ You can change this into (using math.stackexchange.com/questions/1009938/…): $$Z = \sum_{i=1}^N X_i \sim \text{Gamma}(N^\prime,\theta_1)$$ $$N^\prime \sim \text{Gamma}(k_2,\theta_2/k_1)$$ So basically you are compounding two Gamma distributions where the prior for the shape parameter of the one Gamma distributed variable is given by another Gamma distributed variable? – Martijn Weterings Jul 4 '18 at 16:54
• and indeed your sum $\sum_{i=1}^N X_i$ is actually not gonna work (as Michael Hardy noted, because N is not an integer) but you can work with the $Z \sim \text{Gamma}(Nk_1,\theta_1)$ expression. – Martijn Weterings Jul 4 '18 at 16:55