Hello I am using brms package and I have a question about interactions between predictors.
I would like to include the interactive effect between sex and age, and I am expecting non-linear effect of age on response.
Does “s(age, by=sex)” indicate the interaction effect?
brm(res~ s(z.age) + sex + s(z.age,by=sex) +(1|subjID),
family=Beta(link = “logit”, link_phi=“log”),
prior = prior.s,
Does it make sense? Thank you very much in advance :)
I think it should be
brm(res ~ z.age + sex + s(z.age, by = sex) + (1 | subjID), ...)
This means a linear main effect of
sex with a non-linear interaction between the two. But make sure that
sex is coded as a factor rather than an integer.
Thank you very much for your kind reply.
but what if I also expect non linear effect of age as the main effect?
then can I use:
brm(res ~ s(z.age) + sex + s(z.age, by = sex) + (1 | subjID), …) ?
I think that is legal syntax, but
s(z.age, by = sex) already allows the effect of
z.age to be non-linear; it is just a different non-linear function for men and women.
How do you handle the priors with interactions? Do you need a separate prior for the interaction or the prior used for in this case z.age and sex individually are fine.