inverting the binomial distribution: probability distribution for number of trials necessary to have a given number of successes The binomial distribution gives me a distribution for the number of successes in several Bernoulli trials,  k, given parameters  N the total number of trials and q, the success  probability for one trial. This probability can be thought of as P(k|N,q).
Assuming that q is known I would be interested in P(N|k,q), which should follows from Bayes rule, and I am not sure which prior should be used for N. I also wonder if a classical distribution exists in the literature that is what I am looking for.
 A: From a foundational perspective, there is no "good" or "classical" prior. Whatever the sampling distribution, any prior that does not clash with the observation(s) is acceptable. The corresponding posterior is simply conditional or relative to this prior (and never reflects an overall reality or meta-reality!). 
When building one's prior, consider the likelihood function
$$\ell(N|k,q)={N \choose k} q^k (1-q)^{N-k}\propto \dfrac{N!}{(N-k)!} (1-q)^{N}\mathbb{I}_{N\ge k}$$
which is not from an exponential family wrt to $N$. Hence does not allow for the so-called conjugate priors which are often used because of their rather simple features, rather than for theoretical reasons. This means that the prior on $N$ has to be constructed from prior information on the possible size of the population, $N$. If this information is found missing, an alternative is to consider the marginal distribution on $k$
$$m(k)=\sum_{N=k}^{\infty} \pi(N) \ell(N|k,q)$$
as the shape of this posterior may help comparing different choices of priors.
If nothing else works, a default (but not the default) prior is the non-informative $$\pi(N)\propto 1/N \mathbb{I}_{\mathbb{N}^+}(N)$$ which stems from the notion that $N$ is a form of scale parameter, $k$ being of order $qN$.
A: The Negative Binomial Distribution gives the #trials before observing the desired number of success $k$ of #failures $r$. It always under-estimate the answer to the question "What is the #trials knowing that there were k successes". You can clearly see that if you take $k=0$ and $p>0$
I tried to compute below the answer, using Bayesian thinking with an Exponential prior...
WARNING: I have huge doubt about the validity of the outcome of this. I anyone wants to help me, feel free :) (cf. Note 2)


*

*We consider that N is a random variable describing the # of trials (# of Bernoulli trials). Let's assume that N is following an Exponential Distribution $ N \thicksim Exp(\lambda) $

*We then consider that X is a random variable describing the number of successes after N=n trials, following a Binomial distribution $ N \thicksim Binom(p, N) $
Let's compute $ P(n|k) $ thanks to the Bayes formula :
$$ \frac{1}{P(N=n|X=k)} = \frac{P(X=k)}{P(X=k|N=n)P(N=n)} $$
And by writing $ P(k) = \sum_{m=k}^{\infty}{P(X=k|N=m)P(N=m)} $
$$ = \sum_{m=k}^{\infty}\frac{P(X=k|N=m)P(N=m)}{P(X=k|N=n)P(N=n)} $$
And because $P(X=k|N=n)$ and $P(X=k|N=m)$ are just Binomial distributions :
$$ = \sum_{m=k}^{\infty}\frac{m!k!(n-k)!}{n!k!(m-k)!} \frac{p^k}{p^k} \frac{(1-p)^{m-k}}{(1-p)^{n-k}} \frac{e^{-\lambda.m}}{e^{-\lambda.n}}$$
$$ = \sum_{m=k}^{\infty}{[e^{-\lambda}(1-p)]^{m-n}}$$
And by re-indexing the Serie with $l=m-k <=> m=l+k$
$$ = \sum_{l=0}^{\infty}{[e^{-\lambda}(1-p)]^{l+k-n}}$$
$$ \frac{1}{P(N=n|X=k)} = \frac{[e^{-\lambda}(1-p)]^{k-n}}{1 - e^{-\lambda}(1-p)}$$
$$ P(N=n|X=k) = \frac{1 - e^{-\lambda}(1-p)}{[e^{-\lambda}(1-p)]^{k-n}}$$
Note 1: We can easily show that the sum of P(N|k) is 1, which is always reassuring...
Note 2: /!\ I'm very surprised of the result as it would mean that $P(r|k)$ (with r=N-k, r: #fails, k: #success) does NOT depend on k anymore... I really have doubts on the calculation but I do not find anything wrong here above...
Note 3: The choice of the prior (Exponential) is totally arbitrary and leads to a lot of simplifications. If anyone wants to attempt the calculation with another prior, feel free :-)
