[R-sig-ME] 3-way interaction in random structure using gam

Rudi Reiner rud|@re|ner @end|ng |rom boku@@c@@t
Tue May 25 09:14:28 CEST 2021

Hi there,

my actually trying to fit a non-linear mixed model (with a random 
structure) and am not sure how to do this correct using "gam" or "bam" 
from the mgcv package. My supervisor suggested me to ask R-sig.

My Data:

b.mass = body mass (continuous) - dependent variable
__predictor variables_
age = continuous; lon-linear relationship with b.mass
area.forest = continuous
period =  factor; 2 levels

_random variables
_year = continuous (1993-2019)
pop = factor (28 different populations)

First I fitted a linear model with quadratic age which seems to give me 
the "correct" results (biologically the results make sense). Especially 
I am interested in the 3-way interaction age x area.forest x period but 
also want/have to add all 2-way interactions:

*/LM <- lmer(b.mass ~ ns(age,2)*area.forest*period + (1|pop)+ (1|year), 
data = data)/*

Now I want to have the corresponding model using gam (or bam). I tried:

*/gam <- gam(b.mass ~ period+s(age)+area.forest+s(age, by = 
area.forest)+s(age, by=period)+te(area.forest, by=period)+te(age, 
area.forest, by = period), data = data, random = list(pop=~1, year=~1))/*

The results (plot age~b.mass for different area.forest) look different 
to the lmer approach. Do have an idea, if my model (gam) is fitted 
correct, i.e., is it the "same" like the model I fitted using /`lmer`?/

Thank you,

	[[alternative HTML version deleted]]

More information about the R-sig-mixed-models mailing list