Modeling group-level effects with a predictor

414 views
Skip to first unread message

Sachin Sridhara

unread,
Jul 5, 2017, 6:51:55 PM7/5/17
to brms-users
Hi Paul,

I was reading this post on a non-linear model and was wondering whether something similar can be implemented for linear models.

I'm unsure which of the following formulation is correct to model group-level effects in relation to the variable Z.

model1 <- brm(bf(response ~ predictor + (1+ predictor | Z + G1) +
                (1|G2), sigma ~ predictor),
                data = data, family = "gaussian",
                iter = 500, chains = 3, warmup = 250,
                cores = 2)

model2 <- brm(bf(response  ~ 0 + intercept + predictor, b ~ 1 + Z + (1|G1),
                       a ~ (1|G1) + (1|G2), sigma ~ predictor),
                  data = data, family = "gaussian",
                  iter = 500, chains = 3, warmup = 250,
                  cores = 4)

Your help will be greatly appreciated!

Regards
Sachin

Paul Buerkner

unread,
Jul 6, 2017, 11:52:35 AM7/6/17
to brms-users
formula = response ~ 1 + Z + (1+ Z | G1)

that should do the trick. To get for information about the multilevel syntax in brms, type

vignette("brms_overview")

or

vignette("brms_multilevel")

Paul Buerkner

unread,
Jul 6, 2017, 12:00:59 PM7/6/17
to brms-users
Just blug in b0 + b1 * Z[j] and b3 + b4 * Z[j] into the model formula, which leads to

y ~ 1 + Z*predictor + (1 + Z*predictor | group)

However, this will likely not work since Z does not vary within groups (as you say). As a general rule, a predictor can only be modeld as a varying effect, if there is variation of the predictor within groups.

So you most likely want to go for something like

y ~ 1 + Z*predictor + (1 + predictor | group)
 
Thanks for your response Paul.

I will take a step back in my question. I was following the thread of communication between you and the other user. I'll write out my model again, just to clarify what exactly I want to do at the group-level:

My first level is a gaussian linear model with group-level effects written as

y ~ predictor + (1 + predictor | group)

In this, separate intercepts and slopes are calculated for each group. Now, in the next-level I want to model these intercepts and slopes estimated for each group member as another linear model which is a function of a third predictor "Z" (using the terminology in your discussion).

Further, there is only one value of Z per group, i.e. Z does not vary for individuals within the groups. Thus, for j no.of groups:

slopes[j] = b0 + b1 * Z[j]
intercepts[j] = b3 + b4 * Z[j]

Based on Gelman & Hill, I want to try and model these two levels jointly (as done for the non-linear model in the linked thread). But, I am unable to figure out the syntax for this from the vignettes and examples therein. I know this can be set up in JAGS and examples from Gelman & Hill have been translated to Stan code. But, is this possible to set up via brms? 

Regards,
Sachin
Reply all
Reply to author
Forward
0 new messages