I am currently running a linear mixed model with a nested design and random slopes.
For example, let's imagine some monthly captures of wild rabbits in kilograms in 5 sites during 21 years:
site<- rep(rep(c("Golden Cave","Ringo's place","Damned Dam","Knockampton","Easy Fuzzy"),each=12),21) year <- rep(2000:2020, each=12*5) month <- rep(seq(1,12),21*5) rabbit_captures <- rnorm(12*21*5, 50, 10) dataset <- as.data.frame(cbind(site,year,month,rabbit_captures)) dataset$rabbit_captures <- as.numeric(dataset$rabbit_captures)
And the corresponding model:
library(nlme) library(MASS) model_lme <- lme(fixed = log(rabbit_captures) ~ site, random = ~ site|year/month, data = dataset, method = "ML", control = lmeControl(opt = 'optim'))
With this simulated distribution of rabbit_captures, the model does not converge, sorry I tried, but it still corresponds to the design of my experiment. In other words, with a more complex dataset, this model runs properly. However, I am uncomfortable doing spatial modeling without considering time autocorrelation...
So here is my question:
How to consider time autocorrelation within the model?
correlation = corAR1(value = 0.9, form = ~ site|year/month) is an incorrect formulation. Variable "Site" is made of factors and "A covariate for this correlation structure must be integer valued."
correlation = corAR1(value = 0.9, form = ~ 1|year/month) should work (with my example, it won't) but I really don't know if it makes sense statistically...
Thanks in advance!