Random effects structure of nested (gam) BRMS model with binomial outcome in R

513 Views Asked by At

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!

0

There are 0 best solutions below