I’m using brms to fit poisson models to count data that are truncated at some lower interval, but having convergence problems when I specify a formula using the trunc()
function.
For example, if I generate a data set in which the zeros are snipped out:
obs <- rpois(300, lambda = 1.5)
dat2 <- data.frame(obs)
dat2_filt = data.frame(obs = dat2[dat2$obs > 0, ])
and then fit a truncated poisson model as follows:
formula.truncpois = brmsformula(obs | trunc(lb=1) ~ 1, family = poisson())
fit_truncpois <- brm(formula.truncpois, data = dat2_filt)
I am unable to get a fit that correctly estimates the value of lambda that I used to generate the data. In this case, I can work around the issue by fitting a hurdle model and fixing the hurdle probability to zero:
formula.hpois = brmsformula(obs ~ 1, hu = 0, family = hurdle_poisson())
fit_hpois <- brm(formula.hpois, data = dat2_filt)
And this works fine. I get a good estimate from this model.
I may be confused, but I understand these two models to be functionally equivalent to one another. I examined the generated stan code, and though I’m still learning how to read its syntax, was able to see that brms has generated different code for each situation. I’ve posted the full code for both models in this gist for completeness.
The workaround has been functional for me so far, but I’d like to eventually adjust the truncation bound to some value other than 1.
Am I using the trunc()
function improperly, or in the wrong context? Thank you for your help.
- Operating System: macOS 10.12.6
- brms Version: 2.7.2 and 2.7.0