I am trying to find an bayesian approach to the following problem:

  1. Image a bucket with 100 white balls and an unknown number of red balls
  2. During each year, one can take a sample with replacement of 40 balls
  3. However - the red balls have the ability to infect white balls with a fixed but unknown probability. As a result - the number of red balls grows each year.

i have written a short R script (per below) that performs a bayesian estimation on the number of red balls, but wiht a predefined growth probability (10%). I would like to have the growth probability be estimated through a bayesian process as well. Can anyone provide tips or help on how one can estimate these two parameters at the same time?

Graph: bayesian estimation over 4 years bayesian estimation over 4 years


pop=seq(1,100,1) #100 balls
par(mfrow=c(4,1),mar=c(2,2,1,1)) #set up graph

#define prior on # of red balls amongst 100 white balls
prior=c(rep(0.05,10),(rep((0.5)/90,90))) #prior of red balls

#observations of red balls on sample of 40 with repl. 

#assumed growth matrix
growth=0.2 #probability  of red ball multiplication
nextgen=matrix(data=0,ncol=100,nrow=100) #"next generation matrix"
for(i in 1:ncol(nextgen)){
  for(t in 1:nrow(nextgen)){
    nextgen[t,i]=dbinom(i-t,t,growth)  }

#bayesian update cycle
for(k in 1:length(obs)){

lik=dbinom(obs[k],40,(pop/100)) #likelihood of sampling of 40 balls
post=lik*prior/sum(lik*prior);sum(post) #posterior
nextprior=post%*%nextgen #posterior multiplied with next gen becomes prior of the next round

plot(lik,col="white",cex=0.01,xlim=c(0,100),xlab="red ball estimate",ylab="density") #initialize plot
lines(prior,col="red"); lines(lik,col="blue"); lines(post,col="green"); lines(as.vector(nextprior),col="orange") 
legend("topright",legend=c("prior","lik","posterior","next gen prior"),col=c("red","blue","green","orange"),bg="white",lwd=2)


1 Answer 1


That sounds like a kind of hierarchical structure, which might be easier to think of in terms of steps. At the first draw, the infection rate I will assume is irrelevant. Let $X_1$ denote the number of red balls when you start. Then, $$ p(X_1|Y_1)\propto p(Y_1|X_1)p(X_1). $$ Between samples $Y_1$ and $Y_2$, you have that some balls may be infected. The probability of this is $\theta$, so $$ X_2|X_1, \theta\sim Bin(N-X_1, \, \theta). $$ Now it gets messy, and I'm not very sure about the following, but I think this is a way to get started at least. The posterior is $$ p(X_{1:2}, \theta|Y_{1:2})\propto p(Y_{1:2}, X_{1:2}, \theta)=p(Y_{1:2}|X_{1:2}, \theta)p(X_{1:2}, \theta). $$ The first term may be split up: $$ p(Y_2|Y_1, X_{1:2}, \theta)p(Y_1|X_{1:2}, \theta)=p(Y_2|X_2)p(Y_1|X_1), $$ which follows from the number of infected balls sampled being independent of all parameters but the number of infected balls at that instance.

The second term may also be rewritten a little: $$ p(X_{1:2}, \theta)=p(X_2|X_1, \theta)p(X_1|\theta)p(\theta)=p(X_2|X_1, \theta)p(X_1)p(\theta). $$ Together, this yields $$ p(X_{1:2}, \theta|Y_{1:2})\propto p(Y_2|X_2)p(Y_1|X_1)p(X_2|X_1, \theta)p(X_1)p(\theta)\\ \propto p(Y_2|X_2)p(X_2|X_1, \theta)p(X_1|Y_1)p(\theta). $$ And if this is correct, you should be able to use the same strategy for subsequent years to update the inference.

  • $\begingroup$ Thanks hejseb! Quick question - what do you mean with the notation of Y1:2? do you refer to product of p(Y1) and p(Y2)? many thanks $\endgroup$ May 20, 2014 at 19:02
  • $\begingroup$ Sorry, I didn't say what I meant by that. $Y_{1:2}$ means $Y_1, Y_2$, so for example $p(X_{1:2}, \theta|Y_{1:2})=p(X_1, X_2, \theta|Y_1, Y_2)$. $\endgroup$
    – hejseb
    May 20, 2014 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .