Using group-level parameters as predictors

70 views
Skip to first unread message

John Flournoy

unread,
Jan 4, 2018, 9:40:21 PM1/4/18
to brms-users
Hi all,

I was hoping to be able to use the group-level estimates of a parameter from the model of one variable as predictors in the model of a second variable. This seems to have some relation to the idea of using variables without measurement error (i.e., the `se` function) but with the added bonus (?) that the predictor is shrunk a bit toward the population mean.

I'm envisioning something like:

```
m1 <- brm(y1 ~ 1 + x1 + (1 + x1 | g))
m2 <- brm(y2 ~ 1 + bx1 + (1 | g))
```

Where bx1 is the vector of per-group parameters for the relation between y1 and x1.

Thanks for your help, and thanks for pardoning my somewhat noob-ish phrasing of the question.

~J

Paul Buerkner

unread,
Jan 5, 2018, 3:44:48 AM1/5/18
to John Flournoy, brms-users
Hi John,

this is certainly possible in a two-step approach you seem to have in mind. Consider the following sample code:

```R
m1 <- brm(y1 ~ 1 + x1 + (1 + x1 | g))
bx1 <- coef(m1)$g[, "Estimate", "x1"]
# or ranef instead of coef to get the centered estimates
<put bx1 into your data.frame>
m2 <- brm(y2 ~ 1 + bx1 + (1 | g))
```

If you want to include the measurement / estimation error in bx1, add:

```R
sdbx1 <- coef(m1)$g[, "Est.Error", "x1"]
<put sdbx1 into your data.frame>
m2 <- brm(y2 ~ 1 + me(bx1, sdbx1) + (1 | g))
```

All the best,
Paul

--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/cef2a359-0284-493c-a8d0-03c8fb994c74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Flournoy

unread,
Jan 6, 2018, 5:11:31 PM1/6/18
to brms-users
Hi Paul,

Thank you very much for the quick reply. Your solution will work nicely, I think. I was hoping to find a way to do it in a one-step process, though I'm not sure if I gain much from that except perhaps aesthetically. I have a sense of how I could accomplish this by either modifying or writing some Stan code from scratch, but again, perhaps without much potential gain.

Thanks again,
~j
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+...@googlegroups.com.

Paul Buerkner

unread,
Jan 6, 2018, 5:37:06 PM1/6/18
to John Flournoy, brms-users
I think it would be slightly better to model it in a one-step approach, but by how much will depend on the particular data and model.

In any case, the Stan code generated by brms should allow you making it a one-step approach with not too much effort.

-Paul

To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.

To post to this group, send email to brms-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages