# Beta Binomial Inverse CDF

There are p groups of size $n_1, n_2, ... , n_p$ each with number of successes $x_1, x_2, ... x_p$ and number of failures $n_1 - x_1, n_2 - x_2, ... , n_p - x_p$.

$X_i$ ~ $Binom( n_i, p_i)$, where $P_i$ ~ $Beta( a, b)$.

This implies that $\frac{1}{p}\sum_{1}^{p} X_i$ ~ BetaBinom( a, b).

Each $P_i$ can be interpreted as a rate, the number of successes over the number of total trials.

https://en.wikipedia.org/wiki/Beta-binomial_distribution#example

I have fit a beta binomial to just such a distribution using the VGAM package in R. This allows me to find a percentile rate out of each of the groups.

My Question:

Take the wiki example if this were the wiki example of families and percentage of males, I could say "the 90th percentile of the true population proportion is 0.55558" after I've fit a beta binomial. But how do I find a probability score for a specific group?

Say family Q has 9 boys and 1 girls. Then $n_Q = 10, X_Q = 9, p_Q = 0.9$.

Say family R has 1 boy and 0 girls. Then $n_R = 1, X_R = 1, p_R = 1$.

How do we compare family Q with family R? Or rather, $p_Q$ with $p_R$?

For normal distributions, we can find InverseNormal( 0.9) = 1.96.

For family Q, how do I find the probability of their rate $p_Q$ being less than 0.9?

$$Q(p)\,=\,\inf\left\{ x\in \mathbb{R} : p \le F(x) \right\}$$
There is no closed-form quantile function for beta-binomial distribution, but you can easily find it numerically. To do this, for every $x = 0,1,2,\dots,n$ calculate the cumulative probabilities $p_0,p_1,p_2,\dots,p_n$ for them. Next, given some $p$ find the greatest value of $p_i$ that is less or equal to $p$ and take $x=i$.