Result and comparison with JAGS

The pdf of $p$, given the set of conditions $I$, to which we have added $r_0$ and $s_0$ in order to remind that it also depends on the chosen family for the prior, is finally
$\displaystyle f(p\,\vert\,I,r_0,s_0)$ $\displaystyle =$ $\displaystyle \frac{1}{N_f}\cdot \Large [ p^{r_0-1}\cdot (1-p)^{s_0-1}\Large ]\...
...{P_I}} \cdot \binom{n_s-n_I} {n_P-n_{P_I}} \cdot
\binom{n_s}{n_I} \cdot \right.$  
    $\displaystyle p^{n_I} \cdot (1-p)^{n_s-n_I} \cdot
\frac{\Gamma (n_{P_I}+r_1)\cdot \Gamma(n_I-n_{P_I}+s_1)}
{\Gamma(r_1 + n_I+s_1)} \cdot$ (101)
$\displaystyle %\hspace{1.8cm}\, \mbox{(C.7)} \\
$   $\displaystyle \left.\frac{\Gamma (n_P-n_{P_I}+r_2)\cdot \Gamma(n_s-n_I-n_P+n_{P_I}+s_2)}
{ \Gamma(n_s-n_I+s_2+r_2)} \right] \,.$  

So, although we have not been able to get an analytic solution, which for problems of this kind is out of hope, we have got an expression for $f(p\,\vert\,I,r_0,s_0)$, that we can compute numerically and check against the JAGS results seen in Sec. [*]. For the purpose of this work, we did not put particular effort in trying to speed up the calculation of Eqs. ([*])-([*]) and therefore the comparison concerns only the result, and not the computer time or other technical issues. The agreement is excellent, even when we are dealing with numbers as large as 10000 for $n_s$ (and a few thousands for $n_P$). For example, the comparison using the same values of $n_P=2010$ and $n_s=10000$ of Sec. [*] is shown in the upper plot of Fig. [*]:
Figure: Direct computation of Eq. ([*]) (solid lines) vs JAGS results (histograms) for the flat prior (magenta dashed line) and for a Beta$(57,38)$ (magenta dotted line). Upper plot: $n_P=2010$ and $n_s=10000$. Lower plot: $n_P=201$ and $n_s=1000$.
\begin{figure}\begin{center}
\epsfig{file=figure_appendix_C_2010_10000.eps,clip...
...ter}\mbox{}\vspace{-0.9cm}\mbox{}\\\mbox{}\vspace{-0.5cm}\mbox{}
\end{figure}
Then we repeat the game with a sample ten times smaller, that is $n_s=1000$, and assuming $n_P=201$ (lower plot in the same figure). Again the agreement between direct calculation and MCMC sampling is excellent.

It is worth noting that the possibility to write down an expression for the pdf of interest for an inferential problem with several nodes, after marginalization over six variables, has to be considered a lucky case, thanks also to the approximation of modeling the sampling by a binomial rather than a hypergeometric and to the use of conjugate priors. The purpose of this section is then mainly didactic, being the valuation of the pdf's of other variables (and of several variables all together) and of their moments prohibitive. It is then clear the superiority of estimates based on MCMC methods, whose advent several decades ago has been a kind of revolution, which have given a boost to Bayesian methods for `serious' multidimensional applications, tasks before not even imaginable.58