I am new to Generalized additive mixed models (GAMM) and I'm trying to model a behavioral response variable (time spent shading eggs by a nesting bird in minutes timeCS) in relation to several predictor variables: maximum temperature (maxT), species (categorical), the day of the year (jdate) and the age of the nest (ca). My data was based on repeated observations at several nests of shorebirds.

I have three random effects: nest id (nest), location (rm) and year. Nest is nested within rm and year; while rm and year are crossed.

Since I have multiple random effects, I plan to use gamm4 in R as my software package to conduct the GAMM. So far I believe the correct code to run this analysis with my data is

 gamm4 <- (timeCS~s(maxT)+ species + s(jdate) + s(ca), 
           data=Dataset, family=gaussian(link ="identity"))

Is this correct? Should I specify smooth terms for my predictor variables? Can I run model selection based on AICc on GAMM?

  • $\begingroup$ I have the same question - did you feel this was the correct model specification for your random effects? $\endgroup$
    – Kodiakflds
    Apr 9, 2021 at 17:24
  • $\begingroup$ "Can I run model selection based on AICc on GAMM" in general, using the cross-validation error that AIC (sometimes) approximates would be better $\endgroup$
    – wzbillings
    Mar 31 at 15:49

1 Answer 1


Specifying random effect terms in gamm4 is different to mgcv. The syntax I show is provided in this book.

Two random effect terms in gamm4 is:

random = ~(1|xr1 + 1|xr2)

If they are nested, it is:

random = ~(1|xr1/xr2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.