Can the variable "year" be both a continuous and factor variable?

Hello,

I need some help justifying my choice of syntax in mgcv for a gam model.

As I understand it, there are 2 schools of thought: 1. time (year) can either be a continuous trend or a factor, but not both (it’s basically representing the same effect twice). 2. One CAN use both versions in the same model, because one term can represent the smooth annual trend while an additional factor year random effect captures the high year-to-year variation. Is there some way to determine (residual plots, examine variance components, etc.) which method is correct?

If it’s a reasonable model to assume, is this the proper syntax in mgcv?
abundance ~ s(year) + s(fsite, fyear, bs="re") + s(fsite,bs="re")

fsite = repeated measures per site
fyear = factor year (15 years)
year = continious year (trend)

Original post: https://stats.stackexchange.com/questions/651397/use-year-as-a-factor-or-a-continuous-variable-in-a-gamm-with-autocorrelation-f

Hi, @Nate_L, and welcome to the Stan forums!

The short answer is “yes,” thought I don’t know mgcv syntax.

@andrewgelman discusses this approach in a blog post, Can the variable “year” be both a continuous and factor variable?.

Thanks, Bob! No problem, I’m not well versed in mgcv syntax either! Maybe you can help me with this one: Would you also have a fixed effect for a year x season interaction, as well as a random effect of that interaction for the same reason (capture main trend and the random variation)? Or would that be redundant - even it explained a large portion of the variance? Just trying to get a handle on when to include a variable more than once.

Bob may be referring to this blog post from 2024: What to do with age? (including a regression predictor linearly and also in discrete steps), but the question has come up often enough that I wouldn’t be surprised to learn that I’d blogged it earlier too.

Thanks @andrewgelman—I meant to link that post but obviously didn’t. I wish there was a warning when you post an empty link!