Skip to content
Prev 28556 / 29559 Next

A global autocorrelation statistic for categorical data?

On Tue, 16 Feb 2021, Pedro Perez wrote:

            
set.seed(1)
dta <- data.frame(Lon = (runif(60)*100),
                               Lat = (runif(60)*100),
                               Cat = sample(LETTERS[1:5], 60,
                                            replace = TRUE),
                               Cont = (runif(60)*100))
coordinates(dta) <- ~Lon + Lat
library(spdep)
nb <- dnearneigh(dta, 0, 50) # 2000 was far too big, all neighbours of all
moran.test(dta$Cont, nb2listw(nb, style="B"))$estimate[1]
elsa::moran(dta[,2], d1=0, d2=50)
geary.test(dta$Cont, nb2listw(nb, style="B"))$estimate[1]
elsa::geary(dta[,2], d1=0, d2=50)
joincount.multi(factor(dta$Cat), nb2listw(nb, style="B"))["Jtot",]

Jtot summarises all the k-colour matches.

Hope this clarifies,

Roger