I am trying to fit a nested non-linear MLM using brms. I’ve worked through much of the (helpfully detailed) documentation and vignettes to arrive at what I think the correct syntax should be, but brms is throwing an error that I can’t seem to resolve.
The model I am trying to fit has three levels, with level 1 nested in level 2, and level 2 nested in level 3 (there is a separate level 1 nesting that is also included). There are level 3 covariates that I want to incorporate only in the estimation of the level 3 parameters.
Notationally, this is a rough sketch of the model I am trying to fit:
(Approximate number of observations per level: N=300,000, J=25,000, K=90, T=25)
Ultimately, I am interested in the interactive effect of z_1 and the level-1 covariates for which I specify varying slopes (x_2 through x_4), which I can recover through the nesting which links the slopes for those covariates to z_1.
The formula I am providing to brm is :
y ~ b1x1 + b2x2 + b3x3 + b4x4 + gamma + alpha,
alpha ~ (1|alpha_groupings),
gamma ~ (1 | lev2cor | gamma_groupings) + mu_gamma,
b1 ~ 1,
b2 ~ (1 | lev2cor | gamma_groupings) + mu_b2,
b3 ~ (1 | lev2cor | gamma_groupings) + mu_b3,
b4 ~ (1 | lev2cor | gamma_groupings) + mu_b4,
mu_gamma ~ (1| lev3cor | mu_groupings) + z1,
mu_b2 ~ (1| lev3cor | mu_groupings) + z1,
mu_b3 ~ (1| lev3cor | mu_groupings) + z1,
mu_b4 ~ (1| lev3cor | mu_groupings) + z1
I keeping getting the following error: “Error: The parameter ‘mu_gamma’ is not a valid distributional or non-linear parameter. Did you forget to set ‘nl = TRUE’?”
So, at this point, I have the following three questions:
To verify, does the model formula I have specified mirror the model I wrote out above in the screenshot?
I’ve consulted this previous question that dealt with the same issue, and tried a few tweaks, but can’t seem to figure out how to get around this error. How should I adjust the model code?
My plan for examining the interactive effect of z_1 on the level 1 covariates is to generated predicted quantities on data for new observations, and compare those quantities across different values of z_1. Because z_1 is a level 3 predictor, I think I would need to sample new level 3 parameters (and by consequence level 2 parameters) for each new value of z_1 in order for my predicted quantities to be comparable (i.e., “leave all but z_1 fixed,” though the level 2 and 3 offsets will not be technically fixed).
Looking through the documentation, I think I can do this by using the “sample_new_levels” argument in brms’ fit function; given the specified z_1, it would sample new level 2 and 3 parameters for an observation with “new” IDs for those levels (i.e., IDs not included in the model), and the resulting predicted quantities would include the effect of z_1 on the level 1 covariates.
Does that sound 1) like a reasonable way to make those inferences, and 2) feasible using brms in the way I described?
Thank you in advance for your help!
Please also provide the following information in addition to your question:
- Operating System: macOS Mojave 10.14.4
- brms Version: 2.9