Non-linear mixed effect model?

Hi all,
I have 4 different plant combinations of plantA and plantB (AA, AB, BA, BB) that were treated either with Treatment T1 or T2 (with 4 replicates per treatment and plant combinations). Per replicate i have the weight gain of two insects over 6 timepoints.

Now i want to look at the influence of plant a, plant b, treatment, time on the insect weight gain. As the growth is not linear I should probably use a non-linear mixed effect model? Is that correct? I would like to adress the influences statistically but also visually for each plant combination.

Which package should I use? lme4? I am really struggling with the R Code and i get always error warnings. So maybe someone could give me a jump start?

gain~PlantA+PlantB+Treatment+time (+ Replicate/Insect as random factor?)

Would appreciate any input
thanks in advance

Do you have an example of your data? I would start with the rstanarm package here

Maybe start with the stan_glmer and then move onto the stan_gamm4 (non-linear).

Thank you so much I will definitely try that! Do I have to include a temp. autocorrelation in a non linear model as well?

Attached you find an example of my data, I would like to analyze the relative weight gain.Data.csv (6.0 KB)

You may also want to look at the non-linear features of brms. See


So I tried both

For the glmm4 I did this:

br <- gamm4(weightgain ~ Treatment + PlantA+PlantB + time, data = mydata, random = ~ (1 | Replicate/Insect))
summary(br$gam) ## summary of gam

How do I now plot 4 different plots, one for each plant combination (AA,AB,BA,BB)?

For the brms what do I have to include after the poisson distribution?
fit1 <- brm(weightgain ~ Treatment + PlantA+PlantB + time+ (1|Replicate/Insect),
data = data, family=poisson())

Thanks for all your help!