I have temporal blocks in my data frame, so I took the effect of time dependency through a random intercept in a glmer model. Now I want to test the spatial autocorrelation in the residuals but I’m not sure if the test procedure based on the residual is the same as for the fixed-effect models since now I have time dependency. As follow, I show how I proceeded:
library(lme4)
library(ape)
GLMM_MODEL <- glmer(P_A ~ Tmax + (1 | year) ,
data = Data, family=binomial(link="logit"),
control=glmerControl(optimizer="bobyqa",
optCtrl=list(maxfun=150000)))
#SPATIAL AUTOCORRELATION TEST
Data.dists <- as.matrix(dist(cbind(Data$X, Data$Y))) #IN UTM
Data.dists.inv <- 1/Data.dists
diag(Data.dists.inv) <- 0
RESIDUAL <- residuals(GLMM_MODEL, type="deviance")
MORAN_TEST <- Moran.I(RESIDUAL, Data.dists.inv)