# Expected number of trials - Bayesian

ref: 2.11 Question 2. Gelman et al.: Bayesian Data Analysis 2nd ed

Consider two coins, $C_{1} \text{ and } C_{2}$ with the following characteristics: $Pr(heads|C_{1}) = 0.6$ and $Pr(heads|C_{2})$ = 0.4. Choose one of the coins at random and imagine spinning it repeatedly. Given that the first two spins from the chosen coin are tails, what is the expectation of the number of additional spins until a head shows up?

The solution manual states: "If we knew the coin that was chosen, then the problem would be simple: if a coin has probability $\pi$ of landing heads, and N is the number of additional spins required until a head, then $$E[N|\pi] = \pi + 2 *(1-\pi)\pi + 3 * (1-\pi)^{2}\pi + ... = \frac{1}{\pi}$$

The rest of the author's approach makes sense to me, save this initial setup -

I don't understand where the author derived this expected value. To my eyes $N \sim \text{Geom(}\pi)$ and $E[N|\pi] = \frac{1-\pi}{\pi}$

Any assistance that can steer me in the right direction would be greatly appreciated!

There are two versions of the geometric distribution depending on whether you count the spin that results in a head or not. If you count that spin, then the expected value is $1/\pi$ , but if you don't count that spin, then the expected value is $(1-\pi)/\pi$. So the solutions are assuming you count the spin that resulted in a head.
\begin{aligned} \mathbb{E}[N|\pi] &= \pi + 2(1-\pi)\pi + 3(1-\pi)^{2}\pi + \cdots \\[6pt] &= \pi \sum_{i=0}^\infty (i+1) (1-\pi)^i \\[6pt] &= -\pi \sum_{i=0}^\infty \frac{d}{d \pi} (1-\pi)^{i+1} \\[6pt] &= -\pi \frac{d}{d \pi} \sum_{i=0}^\infty (1-\pi)^{i+1} \\[6pt] &= -\pi \frac{d}{d \pi} \frac{1-\pi}{1-(1-\pi)} \\[6pt] &= -\pi \frac{d}{d \pi} \frac{1-\pi}{\pi} \\[6pt] &= -\pi \Big(- \frac{1}{\pi^2} \Big) \\[6pt] &= \frac{1}{\pi}. \end{aligned}