I am working with a dataset it which I am interested in modeling an age*sex interaction in the GAMM framework. From examples I have seen and documentation I have read, this is typically accomplished by setting sex as an ordered factor and testing the following model:
y ~ ordered_sex + s(age, by = ordered_sex)
When done this way, the smooth term is significant and the effect is strong. However, there is a very strong effect of age itself, and I am not sure if this is driving the factor smooth effect as well, since the variance explained by age is not accounted for anywhere else (y ~ s(age)
is wildly significant).
When I run the model this way, accounting for the age effect,
y ~ ordered_sex + s(age) + s(age, by = ordered_sex)
the factor smooth term is no longer significant.
Is this second model a valid way of accounting for variance explained by age? Given the difference in the significance of the factor smooth term in these two models, is it correct to assume that the age effect was driving the factor smooth effect in model 1?
Note all models are being run with gamm
(there are repeated measures) in R
.
ordered_sex
might not make much difference. Side-question: isordered_sex
actually an ordered factor? Probably doesn’t make a difference in your model, but it would have an effect with some tools. $\endgroup$