# Am I wanting to perform a random walk?

I am trying to determine the best method to obtain a probability distribution that describes the likelihood of flipping only heads for a number of successive coin tosses with a coin that has an unknown probability of landing heads.

I have a prior for the probability of the coin landing heads, described by a beta distribution:

$$\beta(a,b)$$

I am updating this distribution according to the number of successes ('heads') $$y$$ from trials $$n$$:

$$\beta(a+y, b+n-y)$$

What is the best way to do this, or at least a relatively efficient way?

My lazy (and potentially incorrect) way of doing this has been to arbitrarily choose some upper bound of trials I will consider, say $$n = 20$$, update the probability distribution for each $$n$$, e.g. $$n = 1,2,3,...,20$$, and then aggregate the distributions. However, I'm not happy with this approach.

I have started looking into markov chains (and random walks) and associated sampling methods e.g. gibbs sampling which seem relevant but I'm not sure if they are or how to apply them.

• It's hard to understand what you're asking for, but it seems that you want to know the probability of all heads for some number of future trials $M$ given the posterior distribution from a prior and some observed data. Is this correct? Or are you asking for something else? Please edit to clarify.
– Sycorax
Commented Feb 9, 2022 at 3:36
• Sorry that was a poor description, let me try and rephrase it. I will edit the original post. Commented Feb 9, 2022 at 5:26

Let's assume the following:

• The distribution of heads out of N coin flips follows a binomial $$\text{Bin}(N, \pi)$$ distribution conditional on the unknown probability of heads $$\pi$$.
• You have a belief about the probability $$\pi$$ that can be captured either by a beta distribution or can be approximated by a mixture of beta distributions.

In that case, the probability of getting $$Y=N$$ heads out of $$N$$ coin flips is given by the probability mass function of the beta-binomial distribution (or a mixture of beta-binomials with the same weights as the mixture weights for the beta-mixture describing your belief about $$\pi$$) evaluated at $$y=N$$.

Most other quantities I can think of should have nice closed-form solutions (e.g. via the pmf or cumulative distribution function of the beta-binomial, or e.g. via the beta-negative-binomial), so sampling based solutions (e.g. Markov-Chain-Monte-Carlo) are unnecessary (and will take a good bit longer). But, of course you can also take a sampling approach, if you cannot easily find a closed form solution.

• The key term for OP to research is "posterior predictive distribution."
– Sycorax
Commented Feb 9, 2022 at 13:42
• Thank you for the answer This is what I have done, however, I have calculated this for multiple $y = 1,2,3,4,...N$ and want to know the most appropriate way to determine an 'average' across all of these trials is. What I don't understand is that after each flip of heads the posterior $N+1$ has a different probability of heads as compared to the prior $N$, so as one continues to flip coins the probability is continually updated, as we are only considering examples with just heads, any time a tail is flipped the trial is ended. So we are less likely to see the $p(y= 20)$ as opposed to $p(y=1)$. Commented Feb 10, 2022 at 3:35
• What question do you want to answer? Distribution of coin flips until you get a tails? Expected number? If so, the beta-negative-binomial distribution gives you all the answers. Or are you trying to answer some other question? Commented Feb 11, 2022 at 10:19
• I need to know the distribution for the probability of the coin landing heads, as this will be the input for a model. I do not know the true probability for the coin (I use a beta distribution to represent this). I can gain information about the coin by flipping it, i.e. each successive head updates my beta distribution to a lower probability of heads, however, If the coin lands tails I will not flip the coin anymore (say the coin is attached to a doomsday device). I want to know the distribution that describes the probability of heads taking into account this survival updating dynamic. Commented Feb 14, 2022 at 21:35
• I think I am wanting to do what is described in this text phys.libretexts.org/Bookshelves/… Commented Feb 14, 2022 at 21:40