I know this type of question has been asked many times before, so I apologize for re-posting about it. I bring it up again because it's been taught in one of my courses of study and I want to make sure I'm learning the correct methods. I can't share the data, but this is the part of the code that I'm confused by:
M1 <- gam(y ~ s(x, bs = "cr") + s(Year, bs ="cr") +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M2 <- gam(y ~ s(x, bs = "cr") + s(Year, bs ="cr") +
factor_A * factor_B,
method = "REML",
select = TRUE,
data = df)
M3 <- gam(y ~ s(x, bs = "cr", by = factor_B) + s(Year, bs ="cr") +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M4 <- gam(y ~ s(z, bs = "cr", by = factor_B) + s(Year, bs ="cr") +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M5 <- gam(y ~ s(x, bs = "cr", by = factor_B) + s(Year, bs ="cr", by = factor_B) +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M6 <- gam(y ~ s(x, bs = "cr") + s(z, bs = "cr") + s(Year, bs ="cr", by = factor_B) +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M7 <- gam(y ~ te(x, Year) +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M8 <- gam(y ~ s(x, by = fYear) +
fYear + factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
M9 <- gam(y ~ s(Year, by = factor_B) +
factor_A + factor_B,
method = "REML",
select = TRUE,
data = df)
AIC(M1, M2, M3, M4, M5, M6, M7, M8, M9)
y = continuous response, and x, z = continuous covariates.
GAM models specifically (not glm) fit by REML can be compared with AIC, so that seems fine. As I understand it though, models shouldn't be compared if they were fitted by REML and have different fixed effects. This seems to be the case with model M4 and M6 as they contain an extra z
term. Also, select
is set to TRUE
in every model before being compared in AIC. I took this option to be a separate method of selection (not to be used in combination with the AIC method). Select=TRUE
can only be used on a single (final) model AFTER using AIC, as a form of variable selection. Am I mistaken here? Thank you!
References:
Pedersen, E. J., Miller, D. L., Simpson, G. L., & Ross, N. (2019). Hierarchical generalized additive models in ecology: An introduction with mgcv. PeerJ, 7, e6876. https://doi.org/10.7717/peerj.6876