Bayesian Hierarchical Poisson model


Could someone help me how to build Bayesian Hierarchical Poisson model (two level) in RStudio?
I have got count of events and one explanatory variable and want model it using:

  1. Jeffreys' prior
  2. Empirical Bayes



Hello @teketo - there are many options for fitting Bayesian models in R that offer alternatives to writing custom MCMC code. A very flexible option is Stan and it's R interface Rstan. There is a bit of a learning curve but the syntax is very similar to how we typically write models on paper - which is a great advantage (above and beyond the efficiency Stan provides). There is plenty of documentation to get started (see the link).

The package rstanarm interfaces with Stan but has syntax similar to lm/glm/lmer which may make it easier for you to work with to start. There is a tutorial here that can help you decide if it fits your needs.

There are of course other options too - however, I'd check out rstanarm first and if you need more flexibility move to rstan.


Between rstanarm and rstan, lies the vast land of brms - much more flexibility than offered by rstanarm, without the need to write Stan code yourself as with rstan. The price to pay is that you need to wait for your Stan model to be compiled - rstanarm avoids that by providing precompiled models, but that forces you to use only the included precompiled models.

To fit multilevel models with brms see

while for a generic intro see

A two-level Poisson model is pretty simple, so I reckon you shouldn't have issues fitting it with brms, but if course if it's already included in the default rstanarm models, using rstanarm will be faster.


Many thanks. Very much helpful responses I have got.

1 Like