Geometric-binomial posterior is shifted negative binomial (source code)

= Geometric-binomial posterior is shifted negative binomial
{title2=$X-k\mid Y=k\sim\operatorname{NegBin}(k+1,p+q-pq)$}

Let $\mathbb P(X=n)=p(1-p)^n$ for $n\geq0$ and $Y\mid X=n\sim\operatorname{Binomial}(n,q)$, with $0<p,q<1$. Write $D=p+q-pq$. Summing the joint <probability mass function> with the differentiated <geometric series> identity $\sum_{n=k}^\infty\binom nk t^{n-k}=(1-t)^{-k-1}$ gives $\mathbb P(Y=k)=(p/D)((1-p)q/D)^k$. By <Bayes' theorem>,
$$
\mathbb P(X=n\mid Y=k)=\binom nk D^{k+1}(1-D)^{n-k},\qquad n\geq k.
$$
Thus $X-k$, given $Y=k$, has the failure-count <negative binomial distribution> for $k+1$ successes and success parameter $D$. Its <conditional expectation> is $k+(k+1)(1-D)/D$ for $X$ itself. The shift by $k$, the number of retained successes, must be retained when identifying the posterior <distribution>.