# Binomial testing with probability estimated from sample

If I have a sample of k successes and n-k failures, there are standard techniques (Agresti-Coull, Clopper, etc.) for finding a confidence interval of the probability of an individual success. What if I want to find a confidence interval for the probability of getting at least k' out of n' instead? Obviously it can be approximated by the usual $$\sum_{j\ge k'}{n'\choose j}(k/n)^j(1-k/n)^{n'-j}$$ but this does not take into account the uncertainty of the initial sample, which may be important (the samples are small).

I believe you are looking for the beta binomial distribution, which reduces the pdf of of interest ($\pi(k\prime)$) to
$\pi(k\prime|n\prime,n,k) = {n\prime \choose k\prime} \frac{B(k\prime+k+1,n\prime-k\prime+n-k+1)}{B(k+1,n-k+1)}$
For motivation, remember that you do not know $p$ of the process, but you need to estimate $p$ as the posterior after making observation of $k$ successes out of $n$ trials. So
$\pi(p|k,n) = \frac{p^k(1-p)^{(n-k)}}{\int x^k(1-x)^{(n-k)} dx}$