0

I am running a fairly complex model in BRMS in R and would love to get your input and comments on my model specifications and interpretation.

I have a nested design in which children (ID) are nested in classes, which are nested in 2 schools. Each child has 4 observations in two conditions, so a total of 8. Condition is thus a within subjects factor with 2 levels. Age is the child's age, which thus varies within classes and schools. My outcome variable is reciprocity, which is coded as 0 or 1.

My research question is whether there are (non-linear) differences in reciprocity over age, and whether this differs between conditions.

Now I am struggling to find the right model specifications.

model_brms_1 <- brm(reciprocity ~ poly(s_age,3) * condition + (1+condition*poly(s_age,3)|school/class) + (1+condition|ID), data = df, family=bernoulli, chains = 4, cores = 4, iter = 4000, warmup = 2000)


model_brms_2 <- brm(reciprocity ~ s(s_age, by=condition, k=8) + s(ID, bs="re") + s(class, bs="re") + s(school, bs="re") + s(school, age, condition, bs="re") + s(class, age, condition, bs="re") + s(ID, condition, bs="re"), data = df, family=bernoulli, chains = 4, cores = 4, iter = 4000, warmup = 2000, control=list(adapt_delta=0.99))

The first structure follows more a linear mixed model specification, while the second follows a GAMM structure.

I am struggling to understand which is the better one to go with and why. I am also unsure about the structure of my random effects.

Any thoughts are highly appreciated! Also please let me know if you spot something incorrect.

Thanks a lot!

Luca
  • 43
  • 4
  • 1
    Random effects are drawn from a distribution which is not very well-defined if you only have 2 cases, so you probably might want to drop school as a random factor. – danlooo May 03 '22 at 07:39
  • Also, you almost certainly don't want to be using the spline version of random effects in a brms model, use the native syntax for random effects in brms models – Gavin Simpson May 04 '22 at 09:28

0 Answers0