Nested versus crossed random effect brms

Please share your Stan program and accompanying data if possible.


I have a data set consisting of 12 conditions to which participants were randomly assigned. There are between 8-11 participants per condition. I have modeled the group-level effects in brms as participant nested within condition. There is a possible complication, however, which is that each condition consists of 2 values of a 2x2x2 set of population-level effects. The population-level effects are all factors. They are labeled V, F, D, and their values are V1 versus V2, etc. The population-level structure thus intersects with the group-level structure as displayed below. The notation X1 vs X2 before the semi-colon indicates that that contrast between values was tested in that condition, while the notation Y1 or Y2, Z1 or Z2 after the semi-colon indicates that those values of those contrasts were held constant in that condition. The code I’ve used to model the results is shown schematically below the list (a number of population-level effects that are common to all conditions have been omitted). The dependent is binary, and the outcome of interest is the relative probability of the two outcomes. The priors were weak and regularizing, and I treated the group-level effects as uncorrelated.

Condition number is listed first, followed by the contrast for that condition, followed by the values of the other contrasts that were held constant in that condition. Across the 12 conditions, all possible contrasts are tested with all possible combinations of constant values for the other contrasts.

1 V1 vs V2; F1, D1

2 D1 vs D2; V1, F1

3 F1 vs F2; V1, D1

4 V1 vs V2; F2, D2

5 F1 vs F2; V1, D2

6 D1 vs D2; V1, F2

7 F1 vs F2; V2, D1

8 D1 vs D2; V2, F2

9 V1 vs V2; F2, D1

10 D1 vs D2; V2, F1

11 F1 vs F2; V2, D2

12 V1 vs V2; F1, D2

model ← brm(data = data,
family = bernoulli,
prior = priors,
formula = outcome ~ V + F + D +
(1 + V + F + D || conditionFact/participantFact),
warmup = 1000, iter = 5000, chains = 4, cores = 8, threads = threading(2),
save_pars = save_pars(all = TRUE),
control = list(adapt_delta = 0.99,
max_treedepth = 15),
seed = 12,
file = “file”,
file_refit = “on_change”,
backend = “cmdstanr”)

My question is whether I’m using the right specification of the group-level effects, given that each participant was exposed to just one contrast and the value of the other two contrasts was held constant. Any advice and reactions would be welcome.

Hello @JKingston!

So, V1 vs V2 was tested in one group of participants when F1,D1 and a completely different group of participants when F1,D2 and another when F2,D1 etc?

If I am reading this right, there is no group level structure in your data. Each observation is independent.

Hey @JKingston it really depends on the design - at what level are V, F, and D being manipulated (they’re all manipulated variables, right?).

Here is a little guide I put together for specifying random effects structures.

If you’re not sure about your design, you can also use performance::check_group_variation() for a post-hoc analysis of the design.