# Geometric distribution with a capped number of trials - finding expectation and prior predictive distribution

So I am modeling a random variable which follows a geometric distribution with probability $$\theta$$ except that the total number of trials is capped at some value $$n$$. I.e., the probability mass function is given by:

$$f(x)=\begin{cases} (1-\theta)^{x-1}\theta & 1 \leq x < n \\ (1-\theta)^{n-1} & x = n \\ 0 & x > n \end{cases}$$

This could represent an experiment in which one flips a coin until the first heads or until $$n$$ flips whichever comes first.

Firstly, I am interested in knowing the expectation of x when $$\theta$$ is known: $$\mathbb{E}(x | \theta)$$

Further, suppose $$\theta$$ is unknown and I have a prior distribution: $$\theta$$ ~ $$Beta(a,b)$$.

I would like to find the marginal expectation of $$\mathbb{E}(x)$$ over all values of $$\theta$$ which is given by,

$$\mathbb{E}(x) = \int_0^1 \mathbb{E}(x | \theta) p(\theta) d\theta$$

As well as the prior predictive distribution for $$x$$:

$$p(x) = \int_0^1 p(x | \theta) p(\theta) d\theta$$

It seems like this would have been studied somewhere before, but searches for "truncated geometric distribution" or "capped geometric distribution" aren't finding anything.

• Is this for a class? It seems like a routine textbook style question. Aug 12, 2019 at 0:18
• Not for a class - I see why it seems that way though, which is also why I was suprised not to find any examples on this particularly type of random variable!
– LoLa
Aug 13, 2019 at 1:37

First, the expectation is a sum, not an integral. \begin{align*} \mathbb{E}(x | \theta) &= \sum_{x=1}^n x f(x) \\ &= \sum_{x=1}^{n-1} x (1-\theta)^{x-1}\theta + n(1-\theta)^{n-1} \\ &= \frac{\theta + \theta n (1 - \theta)^n - \theta (1 - \theta)^n + (1 - \theta)^n - 1 + n(1-\theta)^{n-1}(\theta-1)\theta}{(\theta - 1) \theta} \\ &= \frac{\theta + \theta n (1 - \theta)^n - \theta (1 - \theta)^n + (1 - \theta)^n - 1 - n(1-\theta)^{n}\theta}{(\theta - 1) \theta} \\ &= \frac{\theta - \theta (1 - \theta)^n + (1 - \theta)^n - 1 }{(\theta - 1) \theta} \\ &= \frac{\theta + (1 - \theta)^n(1 - \theta) - 1 }{(\theta - 1) \theta} \\ &= \frac{(1 - \theta)^n(1 - \theta) - (1-\theta) }{(\theta - 1) \theta} \\ &= \frac{(1 - \theta)\{(1 - \theta)^n- 1 \} }{-(1- \theta) \theta} \\ &= \frac{ 1-(1 - \theta)^n }{\theta} , \end{align*}
Second, if $$\theta \sim \text{Beta}(a,b)$$ then $$\mathbb{E}(x ) = \mathbb{E}\left[\mathbb{E}(x | \theta)\right]$$ where the outer expectation is an integral, not a sum.
So, if $$\alpha > 1$$, we could use $$\mathbb{E}(\theta^{-1}) = \frac{1}{\text{B}(a,b)}\int_0^1\theta^{a-2}(1-\theta)^{b-1}d\theta = \frac{\text{B}(a-1,b)}{\text{B}(a,b)}$$ and $$\mathbb{E}(\theta^{-1}(1-\theta)^n) = \frac{1}{\text{B}(a,b)}\int_0^1\theta^{a-2}(1-\theta)^{b+n-1} d\theta= \frac{\text{B}(a-1,b+n)}{\text{B}(a,b)}.$$
We are using the fact that a beta density integrates to $$1$$.