Dear all,
Thank you for your help with my previous issues. I'm now working on a model where my response is Binomial with a Beta distributed probability of success. Sometimes the response is missing so I need to sample it.
I'm trying to make the chains mix better and one thing I'm trying is to model the response directly as Beta-Binomial, so that I don't have to sample the probabilities as well.
I've written the beta-binomial as a custom distribution, parametrised in terms of the mean mu and dispersion parameter phi:
dbetabin=nimbleFunction(run=function(x=double(0),mu=double(0),phi=double(0),size=double(0),log=integer(0)){
returnType(double(0))
if(x>=0&x<=size){
return(lgamma(size+1)+lgamma(x+mu*phi)+lgamma(size-x+(1-mu)*phi)+lgamma(phi)-
lgamma(size+phi)-lgamma(mu*phi)-lgamma((1-mu)*phi)-lgamma(size-x+1)-lgamma(x+1))
}else{
return(-Inf)
}
})
rbetabin=nimbleFunction(run=function(n=integer(0),mu=double(0),phi=double(0),size=double(0)){
pi=rbeta(1,mu*phi,(1-mu)*phi)
returnType(double(0))
return(rbinom(1,size,pi))
})
The density function matches up with the rbetabinom in the rmutil package and the random generator function can only generate integer values, owing to the rbinom call. However, for some reason the slice sampler which is assigned to the missing values seems to sample non-integer values (e.g. 100.33 when the initial value was 100), which causes the MCMC to fail. I am giving the model integer initial values and the log probabilities are all sensible.
Please could you point me in the right direction?
Thanks,
Oliver