Post-processing com_poisson model in brms

Hi all,

I have a few underdispersed count responses that I have been modeling. When I started ~1 year ago, the Conway-Maxwell distribution in STAN/brms was only just starting to be implemented. As an interim solution, I decided to apply conditional logit mixed models, which worked well enough, but seemed a bit wonky – for example, the range of plausible responses gets truncated at the highest observed value – and statistically inefficient. I am now circling back to these analyses to see if I can gain some additional insight with the experimental implementation of the brms_family(‘com_poisson’). Working with the first data set, the model runs with apparently good convergence properties and the parameter estimates pass the initial smell test. However, when I try to use higher-level model post-processing functions, e.g. posterior_predict(…), pp_check(…), etc., I get the following error:

Error: ‘n’ must match the maximum length of the parameter vectors.

Is there a (hopefully quick) solution for this error? Or is this a product of the experimental nature of the distributional family? I am guessing the error emerges somewhere out of the structure of the brmsfit object, since ‘n’ is not an argument to any of the methods I am calling as far as I can tell.

Update: I gave this family a trial run with a second data set and post-processing seems to work as expected. Might the previous errors have something to do with a truncation boundary I applied? With the problematic data set, I know that the response count cannot exceed seven, so I specified trunc(ub=7) as additional response information. I now recall that I felt the most comfortable with the conditional logit model structure/assumptions for this particular data set, so perhaps this error serves as tacit confirmation of my suspicion?

Thanks for your help,
Joshua

Please also provide the following information in addition to your question:

  • Operating System: macOS 10.14.6
  • brms Version: 2.10.0
3 Likes

That looks like a bug to me. Do you have a minimal reproducible example for me that I can try out myself?

I agree. I’m working through a couple of additional datasets that look like good applications of Conway-Maxwell Poisson distribution, but will together a reproducible example as soon as my machine is free. I will update and post any additional insights from the next couple of models as well. Thanks!

I don’t know if this has changed since I last tried this (and obviously Paul would have the definitive response) but at the time, post processing on truncated responses was not directly possible through brms.

Though I was able to do it by drawing yrep values directly for the basic post fitting checks.

1 Like

Paul, sorry for the delay. The code below reproduces the error I encountered.

set.seed(123)

dat = data.frame(counts = rpois(60,1.8), fac1 = factor(rep(c(1,2),each=30)),group = factor(rep(1:6,10)))

model = brm(formula = counts|trunc(ub=7)~fac1+(1|group), data=dat, family = brmsfamily(‘com_poisson’,link=‘log’), prior=c(set_prior(‘normal(0,1)’, class=‘b’), set_prior(‘student_t(3,0,1)’, class=‘sd’)), iter=1000, warmup=500)

yrep = posterior_predict(model)
pp_check(model, type=‘stat’, stat=‘sd’)

Meg, if my understanding of the current brms documentation is correct, post-processing of truncated responses should be possible directly with more specific user control of truncation handling enabled by the ntrys argument. That being said, I can certainly see how one could draw values directly. Would you mind sharing your code for doing so? I thought about pursuing that solution, but let sloth get the better of me.

Cheers,
Josh

1 Like

Thanks! Should now be fixed on github.

1 Like