Deriving Marginal Distribution of Poisson How do you find the marginal distribution of a Poisson distribution given a gamma(a,b) prior?
 A: Let $X \mid \lambda \sim \mathcal P(\lambda)$, that is for all $k \in \mathbb N$:
$$
\mathbb P(X=k \mid \lambda) = e^{-\lambda}\frac{\lambda^k}{k!}
$$
and $\lambda \sim \mathcal G(a,b)$, i.e.:
$$
f_{a,b}(\lambda) = \lambda^{a-1}\frac{e^{-\lambda b} b^a}{\Gamma(a)}I_{\lambda \geq 0}
$$
The marginal distribution of $X$ is:
\begin{align*}
\mathbb{P}(X=k) &= \int_{\mathbb R^+} \mathbb P(X=k \mid \lambda) f_{a,b}(\lambda) d\lambda \\
&= \int_{\mathbb R^+}  e^{-\lambda}\frac{\lambda^k}{k!}  \lambda^{a-1}\frac{e^{-\lambda b} b^a}{\Gamma(a)} d\lambda \\
&= \frac{b^a}{\Gamma(a) k!} \int_{\mathbb R^+}  e^{-\lambda(b+1)}\lambda^{k+a-1} d\lambda  \\
&=\frac{b^a}{\Gamma(a) k! (b+1)^{k+a}} \int_{\mathbb R^+}  e^{-u}u^{k+a-1} d\lambda  \quad ( u \leftarrow \lambda(b+1))\\ 
&= \frac{\Gamma(k+a)}{k!\Gamma(a)} \frac{b^a}{(b+1)^{k+a}} \\
&= \frac{\Gamma(k+a)}{k!\Gamma(a)} \Big (\frac{b}{b+1} \Big )^a \Big ( \frac{1}{b+1} \Big )^k
\end{align*}
The last line is the probability mass function of a negative-binomial distribution. 
