BRMS: Priors in multi-variate hierarchical models

Heya,
I am trying to fit a multivariate (multiple-outcome) hierarchical model in brms.
The data and most of the code was taken from:

https://cran.r-project.org/web/packages/brms/vignettes/brms_multivariate.html#more-complex-multivariate-models

I just created random binary data for y1, y2. Wish to test this model before using my data.

I am having a hard time figuring out how to set priors - apparently something is wrong with the correspondence between prior and variables. I have checked out get_priors(), however the error persists even when including all possible “class”, “coef” and “group” arguments.

ERROR:
The following priors do not correspond to any model parameter:
sd ~ normal(0, 1)
b_hatchdate ~ normal(0, 1.5)
b_good_food_share ~ normal(0, 1.5)
b_sexMale ~ normal(0, 1.5)
b_sexUNK ~ normal(0, 1.5)
sd_fosternest__good_food_share ~ exponential(1)

CODE:

priors <- c(
  # Priors for fixed effects (intercept and slopes)
  prior_string("normal(0, 1)", class = "Intercept"),
  prior_string("normal(0, 1)", class = "sd"),
  
  prior_string("normal(0, 1.5)", class = "b",coef="hatchdate"),#numeric
  prior_string("normal(0, 1.5)", class = "b",coef="good_food_share"),#numeric
  prior_string("normal(0, 1.5)", class = "b",coef="sexMale"),#factor
  prior_string("normal(0, 1.5)", class = "b",coef="sexUNK"),#factor
  
  
  # Priors for random effects (variance of random intercepts and slopes)
  prior_string("exponential(1)", class = "sd", group = "fosternest"),  # Random intercept
  prior_string("exponential(1)", class = "sd", group = "fosternest", coef = "good_food_share"),  # Random slope for good_food_share
  
  # Prior for correlation between random intercept and random slope
  prior_string("lkj(2)", class = "L", group = "fosternest")
)

model = brm(mvbind(y1,y2)~sex+hatchdate+good_food_share+(1+good_food_share|p|fosternest), 
            data = data, 
            family = bernoulli(link = "logit"),
            prior = priors,
            cores=getOption("mc.cores", 4), 
            iter=1000)

Checking out this paper by @paul.bruecker (https://arxiv.org/pdf/1905.09501)
something like this:

prior = set_prior("normal(0, 3)", class = "b") +
set_prior("normal(2, 3)", class = "b", coef = "item1")

should be possible.

Would really appreciate a pointer to solve this!
Thanks

Hi, @Alessiolo and welcome to the Stan forums. Sorry that nobody answered this yet, despite giving us all the info we needed. I’m afraid I don’t know brms, so I can’t even decode what good_food_share|p|fosternest means, even after looking at @paul.buerkner’s vignette (I’ve never learned brms and Paul’s vignette assumes you already know the expression syntax).

My general advice is to start with the simplest thing that works, then add one thing at a time to see where things go wrong—it’s usually a lot easier than trying to write your final product and getting a lot of interacting errors.

You need to replace terms like

prior_string("normal(0, 1.5)", class = "b",coef="hatchdate")

with terms like

prior_string("normal(0, 1.5)", class = "b",coef="hatchdate", resp = "y1") # (or resp = "y2")

In the multivariate response setting, you need to specify which element of the response the prior is meant to apply to.

2 Likes

I cannot see the OP currently as I cannot access the discourse forums right now. The syntax good_food_share|p|fosternest, specifically, the inner |p| is described in more detail in my second brms paper: https://arxiv.org/abs/1705.11123

As for the rest, I have to wait until I can access the forums again.

Thank you all for your replies!

I have marked the correct solution from @jsocolar - for multivariate models its indeed necessary to define both response variable as well as class and coefficient.

Ive been working on a research project using multivariate correlated binary responses, which is somewhat different from @paul.buerkner s example mentioned above, mainly due to the GLM.

Residual correlations are not a thing here and for some reason I get no “significant” posterior correlations on my intercepts, although responses are univariate correlated.

Trying to wrap my head around this class of models and experimenting a lot - really interesting stuff!

Thank you for the responses, might make the code for my publication open access and will then link my workflow here.