I am trying to find an bayesian approach to the following problem:
- Image a bucket with 100 white balls and an unknown number of red balls
- During each year, one can take a sample with replacement of 40 balls
- 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
R-script
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
nextprior=NULL
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.
obs=c(3,5,8,10)
#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)
prior=as.vector(nextprior)
}