How to get both of between- and within subject correlation?

Hello, I have a simple question just written in the title.

How to get both of between- and within subject correlation?

below is my code.

m.1 ← bf(y1 ~x+(1|subject))
m.2 ← bf(y2 ~ x+ (1|subject))

model ← brm(m.1+m.2)+set_rescor(TRUE),
** data = data,**
** family = gaussian)**

VarCorr(model1)

VarCorr function gave me estimated value and confidence interval for correlation of y1 and y2, but i can’t believe this value represents one of the between- or within- subject correlation.

So, how can i get two different levels of correlation terms?

Thank all you for taking the time to help me

You are currently only modeling the residual correlation. To also model the correlation in the subject means of y1 and y2, use:

m.1 ← bf(y1 ~ x + (1 | g | subject))
m.2 ← bf(y2 ~ x + (1 | g | subject))
m <- m.1 + m.2 + set_rescor(TRUE)

Also see the Group-level terms section in ?brmsformula

5 Likes

Thanks for your kind answer!

1 Like