I am currently modellingusing the 'mgcv' package in R. My response variable is called log.tr, representing the log of residence time. My data looks a little bit like this:
set.seed(123)
logtr <- seq(0.67, 4.29, length.out = 100)
day_ <- sample(1:365, 100, replace = TRUE) # Random day values
year_ <- sample(2000:2020, 100, replace = TRUE) # Random year values
TEMPERATURE <- rnorm(100, mean = 25, sd = 5) # Random temperature values
gam_tres_df <- data.frame(log.tr = logtr, day_ = day_, year_ = year_, TEMPERATURE = TEMPERATURE)
I am attempting to fit a generalized additive model (GAM) using the 'gam' function from 'mgcv'.
The model formula I am using is:
gam(log.tr ~ s(day_, k = 40, bs = 'cc') + s(year_, k = 12) + s(TEMPERATURE, k = 40) + s(day_, year_), method = 'REML', data = gam_tres_df)
In this formula, I have included smooth terms for the variables day_, year_, TEMPERATURE, and an interaction term between day_ and year_. I have chosen specific degrees of freedom (k) for each smooth term.
However, I suspect that the variables day_ and year_ may be dependant. I am considering adding a correlation structure to the model to account for this potential correlation. Specifically, I am thinking of using the corARMA
function with the form ~ 1|Year
and an autoregressive moving average (ARMA) model with a lag of 3 (p = 3).
My question is whether I should include this correlation structure (corARMA(form = ~ 1|Year, p = 3)
or maybe (form = ~ day | year)
) in my GAM model or if the current model specification without the correlation structure is appropriate. Also I wanted to know how to define this correlation structure for seasonal daily data; since i want to consider residual variation from year to year.
Please let me know if you need further information or have any additional questions!