I would like to estimate a hierarchical mediation model where both the IV of interest (X) and the mediator (M) are level 2 variables and the DV (Yij) is a repeated measures variable with i measurements for each j subject.
So, breaking this into separate models, I’d have something like:
Y ~ X + (1 | id) Y ~ X + M + (1 | id) M ~ X
In the past, I’ve used brms’s capacity for handling multivariate outcomes to estimate the second and third models simultaneously; however, in this case, I am not sure that this is possible due to the structure of the data required for these models.
Y ~ X + M + (1 | id) requires long format data where each subject is represented across j rows and the entries for X and M are identical across j rows for each subject. However, if this data is naively used to estimate M ~ X, the sample size is inflated by a factor of j. That is, for M ~ X, we need each measurement of M and X to be uniquely represented in the data (rather than repeated).
So, I am wondering if there is a trick for dealing with this in brms; for instance, can I specify different data for each formula? Or, perhaps is there is another way to get around this issue?
The other option, of course, is to just estimate separate models. But, I thought that (1) this might be a common problem and (2) there might be an established way to do this.
I did search around quite a bit (on discourse and brms’s support material), but I haven’t found anything helpful.