I am trying to fit 4 hierarchical GAMs to my dataset and compare them to determine the best-fit model. I have been relying on Pedersen et al 2019 to help me specify these models, but I don't think I fully grasp setting m
for each smooth.
My dataset has the following variables: year, region, site, and mass. Sites are nested under region.
In the first two models, I'm interested in comparing the trend in mass across sites with the same smoothness/wiggliness and the with the same smoothness, but different wiggliness. In these models, the global trend is across all sites. These are basically taken exactly out of Pedersen et al 2019, so I'm pretty confident that they are correct.
# 1. a) Global trend across all sites, same wiggliness [equivalent to GS in Pederson et al. 2019]
mGS <- gam(mass ~ s(year, bs = "tp", k = 10, m = 2) + # global trend, m = 2
s(year, site, bs = "fs", k = 10, m = 2), # site trend, m = 2
data = df, method = "ML", control = gam.control(nthreads = 4)) # used ML instead of REML for model comparison
# 1. b) Global trend across all sites, different wiggliness [equivalent to GI in Pederson et al. 2019]
mGI <- gam(mass ~ s(year, bs = "tp", k = 10) + # global trend
s(year, by = site, bs = "tp", k = 10, m = 1) + # site trend, m = 1
s(site, bs = "re"), # random effect for site
data = df, method = "ML", control = gam.control(nthreads = 4))
However, for the second set of models, instead of the global trend across all sites, I want to set a regional trend, and I'm not entirely sure I've set the m
parameter correctly, especially in 2b) where m = 1
for both the regional and site smooths.
# 2. a) Regional trend for nested sites, same wiggliness
mRS <- gam(mass~ s(year, by = region, bs = "tp", k = 10, m = 1) + # regional smooth, m = 1 similar to site trend in model 1b)
s(region, bs = "re") + # random effect for region similar to 1b)
s(year, site, bs = "fs", k = 10, m = 2), # site trend, m = 2 similar to site trend in model 1a)
data = means, method = "ML", control = gam.control(nthreads = 4))
# 2. b) Regional trend for nested sites, different wiggliness
mRI <- gam(mass ~ s(year, by = region, bs = "tp", k = 10, m = 1) + # regional smooth, m = 1 similar to site trend in model 1b)
s(region, bs = "re") + # random effect for region similar to model 1b)
s(year, by = site, bs = "tp", k = 10, m = 1) + # site trend, m = 1 similar to site trend in model 1b)
s(site, bs = "re"), # random effect for site
data = means, method = "ML", control = gam.control(nthreads = 4))