Hi Perry and Chris,
Thanks for your responses. Chris, I've hard-coded the normalizing constant in the nimble function and that did indeed solve the "bad parameters" problem.
Perry, this is a relief. The model runs much more slowly after adding the dcmp via nimbleRcall compared to the built-in dpois so I'm glad to know there's still hope once the nimble function is running.
I've re-coded the d and r functions but have encountered this other error before the MCMC starts sampling (i.e. as the model is compiling):
Error in rle(isScalar) : 'x' must be a vector of an atomic type
I've checked the return types and and it all appears fine to me. I am suspecting the issue is actually with the random number function because the model compiles and runs fine when I use the nimbleFunction distribution function and use nimbleRcall for the random number sampler.
Any suggestions about where I am going wrong would be greatly appreciated!