mjskay / tidybayes

Bayesian analysis + tidy data + geoms (R package)
http://mjskay.github.io/tidybayes
GNU General Public License v3.0
712 stars 59 forks source link

Predicted counts for multinomial models #219

Closed IvanUkhov closed 4 years ago

IvanUkhov commented 4 years ago

I have a multinomial model in brms and use predicted_draws and add_predicted_draws to conveniently pack together the input data and posterior draws. I was expecting to see counts for individual categories in the output, and I thought they would appear in .prediction next to .category. However, .prediction is always NA. Is there something I am missing?

data <- tribble(
    ~a,   ~b,   ~c, ~total,
  3000, 3000, 7000,  13000,
)
data$counts <- with(data, cbind(a, b, c))
formula <- brmsformula(counts | trials(total) ~ 1)
fit <- brm(formula, data, multinomial(), seed = 42)
predicted_draws(fit, tibble(total = 1000))
mjskay commented 4 years ago

Ah yup I see the problem. Turns out there was a pull request with a possible solution from @aammd awhile back (#176) that I hadn't gotten around to looking at in more detail (sorry Andrew!).

This should be fixed on master now.