My friends asked me two Bayes questions a while ago. Due to the rapid spread of COVID-19 in US, I’ve been at home for five days. So I decide to put my solutions here for references. The first question is as follows.

There are five balls in a bag. Each ball is colored either black or white with equal chance. Now suppose that someone have already drawn the ball 4 times with replacements, among which he/she got 1 white ball and 3 black balls as a result. Find the probability distribution of the number of white balls in that bag.

This problem is a straightforward application of Bayes’ Rule. The only tricky part is to formulate the problem statement with math language.

Let X be the number of white balls and let event A=[1 white ball and 3 black balls among 4 trials]. The prior distribution of X is simply the binomial distribution B(5,12). Actually, we are interested in finding the posterior probability P(X=x|A). Note that

P(A|X=x)={b(1;5,x5),   x=1,2,3 or 40,   x=0 or 5,

where b(x;n,p) is the pmf at x for a B(n,p) r.v.

We use Bayes’s Rule as follows:

P(X=x|A)=P(X=x,A)P(A)=P(A|X=x)P(X=x)iP(A|X=i)P(X=i)=(43)(x5)1(5x5)3(5x)(12)5i=14(43)(i5)1(5i5)3(5i)(12)5,   x=1,...,4.

I used R to compute the above quantity:

> x <- rep(0,4)
> for (i in 1:4){
+     x[i] <- 4 * (i/5) * ((5-i)/5)^3 * choose(5, i) / 2^5
+ }
> y <- x/sum(x)
> y
[1] 0.28571429 0.48214286 0.21428571 0.01785714

Thus, we have

P(X=x|A)={0.28571429,   x=10.48214286,   x=20.21428571,   x=30.01785714,   x=40,   x=0 or 5.

When we are asked to give a point estimate of the number of white balls, we typically use the posterior mode, which is also known as the MAP (maximum a posteriori) estimation. In this case, it is 2.