Beta binomial model¶
A sequence of coinflips from which we try to infer the probability of heads can be viewed as an analogy to the beta binomial model.
Likelihood¶
The full probability of observing an given sequence of coin flips is:
Here we observe \(k\) heads in \(n\) flips. In general we do not care about the exact order thus we can ommit \(\binom{n}{k}\) thus we can simply it to:
\(N_1\) - number of heads
\(N_0\) - number of tails
Prior¶
The Beta distribution has support over the interval [0,1] and is proportional to the likelihood:
The full distribution is:
\(\frac{1}{B(a,b)}\) where \(B(a,b)\)
Posterior¶
The posterior is just a compromise between the prior and the empirical parameters. With \(a\) and \(b\) being hyper parameters controlling the strength of the prior.
Posterior Mode¶
The mode is the mode of a Beta distribution
If we use an uniform prior (\(Beta(1,1)\)) than the MAP estimate is the same as MLE estimate.
Which is just the empirical fraction of heads.
Where the posterior mean is:
and it can be expressed as a convex combination of the prior mean and the MLE. This captures the intuition that the posterior is a compromise between what we believe and what the data is telling us.
If we let:
\(\alpha_0 = a + b\) which is the sample size of the prior, and control its strength. And let the prior mean be \(m_1 = \alpha / \alpha_0\) then:
where:
\(\lambda = \frac{\alpha_0}{N + \alpha_0}\) is the ration of prior to posterior sample size. So the weaker the prior the smaller this ration is. Hence the estimation is closer to MLE.
Posterior Variance¶
These are point estimates but they still gives us a sence how much we can trust our posterior distribution.
or if \(N >> a,b\) we can simply it to:
Where:
\(\bar{\theta}\) is the MLE.
Now we can calculate the error bars, we can just take the sqare root of the variance.
Predicting the outcome of a single event¶
Now we have a posterior that is essentially a beta distribution. Now we want to infer the probability of heads in a single trial.
Hence it is equal to:
Predicting the outcome of multiple events¶
We want to predict x heads in M future trials this is given by:
Where the Integral is just the Normalization constant for \(Beta(a+x , M -x + b)\)
Nw the posterior predictive distribution is known as the (combound) beta-binomial distribution:
Here the distribution has the following mean and variance:
Here if we set \(M=1\) we get the same thing as the predicions for a single variable.