Simulating known random effect correlations

I am attempting to simulate data from a multilevel model with known fixed effects and random effect correlations. Take a simple case such as

bf(y ~ x + (x|subject)) + gaussian()

It is straightforward to “fix” most of the parameters in the model with priors like e.g.

c(prior(normal(0.8,0.001), class=“b”, coef=“x”),
prior(normal(0.6,0.001), class=“sd”, coef=“Intercept”, group=“subject”),
prior(normal(0.2,0.001), class=“sd”, coef=“x”, group=“subject”) )

I can then simulate responses with posterior_predict().

Is it possible to also “fix” the correlation of the (x|subject) random slope and intercept effects in a brms model? It seems the only prior available for the random effect correlation is the lkj(), and it is unclear to me how I could specify e.g., r = 0.3 (with low uncertainty).

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

  • Operating System: Windows 10
  • brms Version: 2.10

I don’t think brms supports that directly. You might have some luck with accessing the Stan model generated by brms and use the fixed_param sampling method to rerun the generated quantities block for your given params. That would however involve some digging around, as this is IMHO not really documented anywhere.

I’ve also found it worthwhile to write a separate simulator in pure R and then check that brms recovers the parameters from the simulation - this way I can be sure that I completely understand what the brms model is doing. But it is some extra work.

Best of luck with your model!

2 Likes