Fixed or hierarchical prior for matrix terms in brms?

I have a model with a matrix term of predictors: y ~ X + g1 + g2, where the matrix X is of size n x k , and the k predictors variable and numerous enough to make using a more explicit formula inconvenient. I would like to set up a hierarchy such that coefficients of the model corresponding to columns of X would be N(0, \sigma^2), with \sigma either estimated or fixed. Is this kind of priors possible to set in brms?

Writing this in pure Stan is relatively trivial, but again, using brms would allow easier experimentation.

Addition: set_prior() seems to be good at least for setting fixed priors for all fixed effects simultaneously. Thatâ€™s almost sufficient for my current purposes, for I can make all other effects random in my model. I donâ€™t see a way to limit a prior only to fixed-effect terms derived from X (which are many), except by listing all the termsâ€¦

https://github.com/paul-buerkner/brms/issues/459 seems related.

I donâ€™t think thatâ€™s directly possible, but Iâ€™ve previously generated formulas for brms in code (the simplest way is probably to construct it as a string and then convert via as.formula). This makes creating a formula with many predictors easy.

Hope that helps you move forward.

1 Like

You should be able to do this by using the stanvars argument to pass additional stuff (your sigma in this case to the parameters block) to the Stan code and then specify the prior accordingly via set_prior.

You can split the fixed effects into two additive parts using brmsâ€™ non-linear syntax, that is, something like bf(y ~ a + b, a ~ x, b ~ g1 + g2, nl = TRUE)

1 Like

Thanks for both. I ended up using bare Stan. The nl trick is nice, didnâ€™t come to my mind.