paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.28k stars 182 forks source link

Inconsistency in zero-inflated Poisson models? #692

Closed zbinney closed 5 years ago

zbinney commented 5 years ago

Hi,

First of all, thanks for a great package. I'm pretty new to Bayesian stuff and this is my first time ever posting a question on Github, so I apologize in advance if the answer is obvious or I do anything dumb.

I'm trying to get comfortable with zero-inflated Poisson models in brms, and I'm working through the example in Statistical_rethinking_recoded. What's confusing me is why the following two models aren't yielding exactly the same results:

`prob_drink <- 0.2 # 20% of days drinking -> 0 manuscripts rate_work <- 1 # average 1 manuscript per day (lambda)

#Sample one year of production
n <- 365
set.seed(11)
drink <- rbinom(n, 1, prob_drink)
y <- (1 - drink) * rpois(n, rate_work) #number of manuscripts completed

d <-
  tibble(Y = y) %>%
  arrange(Y) %>% 
  mutate(zeros = c(rep("zeros_drink", times = sum(drink)),
                   rep("zeros_work",  times = sum(y == 0 & drink == 0)),
                   rep("nope",        times = n - sum(y == 0))
  ))

b11.4a <- brm(data = d, family = zero_inflated_poisson, Y ~ 1, prior = c(prior(normal(0, 10), class = Intercept), prior(beta(2, 2), class = zi)), # the brms default is beta(1, 1) cores = 4, seed = 11, inits = "random")

b11.4_b <- brm(data = d, family = zero_inflated_poisson(link_zi = "identity"), bf(Y ~ 1, zi ~ 1), prior = c(prior(normal(0, 10), class = Intercept), prior(beta(2, 2), class = Intercept, dpar = zi)), # the brms default is beta(1, 1) iter = 2000, warmup = 1000, chains = 4, cores = 4, seed = 11)`

The results are effectively the same (within simulation error), but the n_eff is different. I compared the stan code produced by both these models and do see some differences, but I'm not skilled enough to know exactly what I'm looking at.

Regardless of why they're different, would model b11.4_b be a good basis for future zero-inflated Poisson models?

Thank you!

I'm on Windows 10, brms v. 2.9.0

paul-buerkner commented 5 years ago

Welcome to Bayesian statistics! :-)

In general, I prefer brms related questions being asked on https://discourse.mc-stan.org (with the Interfaces - brms tag) rather than on github as they have much better visibility on discourse. Github issues are reserved for feature requests and bug reports. Thus, would you mind reposting your questions on discourse?

zbinney commented 5 years ago

You bet. Thanks for the clarification. I was agonizing over the best place to put this. Heading over there now!