# Marginal pmf of Hierarchical model

Suppose $X\mid P=p\sim\mathrm{binomial}(n,p)$ and $P\sim \mathrm{beta}(1,2)$. Find the marginal pmf of $X$ $(f_X(x))$ and verify that it is a valid pmf.

I set this up as $$f_{X,P}(x,p) = f_{X\mid P}(x\mid p)f_X(x) = \int_0^1 {{n}\choose{x}}p^x (1-p)^{n-x}\frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\Gamma(\beta)}p^{\alpha-1}(1-p)^{\beta-1}dp.$$

I simplify this and simplify a $\mathrm{Beta}(x+\alpha, n-x+\beta)$ pdf to $1$ and am just left with $${{n}\choose{x}}\frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\Gamma(\beta)}\frac{\Gamma(x+\alpha)\Gamma(n-x+\beta)}{\Gamma(\alpha+n+\beta)}.$$

When I plug in my given beta values I get $${{n}\choose{x}}\frac{\Gamma(1+2)}{\Gamma(1)\Gamma(2)}\frac{\Gamma(x+1)\Gamma(n-x+2)}{\Gamma(1+n+2)}={{n}\choose{x}}2\frac{\Gamma(x+1)\Gamma(n-x+2)}{\Gamma(n+3)}=2\frac{n!}{x!(n-x)!}\frac{x!(n-x+1)!}{(n+2)!}=2\frac{(n-x+1)}{(n+1)(n+2)}.$$ I'm guessing I should have left the variables and tried to simplify a different way. Any help is greatly appreciated.

-
Is section 2.7 in this note of any use to you? – jerad Dec 15 '12 at 19:17