Sampler for missing beta-binomial data producing non-integer values

110 views
Skip to first unread message

Oliver Stoner

unread,
Sep 3, 2018, 12:35:08 PM9/3/18
to nimble-users
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

Oliver Stoner

unread,
Sep 3, 2018, 12:59:13 PM9/3/18
to nimble-users
Update: The embarrassingly simple solution was to register the distribution explicitly using registerDistributions and set discrete=TRUE. Hopefully somebody will have the same problem one day and see this...

Now that my post is mostly pointless, I should say keep an eye out for our article on correcting under-reporting in count data (using NIMBLE for all the MCMC) which will be on arXiv tomorrow and hopefully published in the next few months if they are happy with the revisions...

Thanks,

Oliver

Daniel Turek

unread,
Sep 3, 2018, 1:42:24 PM9/3/18
to Oliver Stoner, nimble-users
Oliver, thanks for the follow-up.  And that's great to hear about the upcoming paper using NIMBLE.


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To post to this group, send email to nimble...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/beafa630-ee83-415a-886b-a679180334b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages