Skip to content

A global autocorrelation statistic for categorical data?

2 messages · Pedro Perez, Roger Bivand

#
Hello everybody!

Sorry for the dumb question, I have very limited experience with regards to
spatial autocorrelation. I have a lot of spatial points for which I
measured both continuous and categorical variables. I need to calculate
*global* measures of spatial autocorrelation for both kinds of variables. I
know that this task is relatively easy for continuous ones, here an example
using the package elsa:

rm(list = ls())
library(raster)
library(elsa)

dta <- data.frame(Lon = (runif(60)*100),
                              Lat = (runif(60)*100),
                              Cat = sample(LETTERS[1:5], 60, replace = T),
                              Cont = (runif(60)*100))
coordinates(dta) <- ~Lon + Lat
# Moran's I global index:
moran(dta[,2], d1=0, d2=2000)
[1] -0.01694915 # The value varies given that seed was not set
# Geary's c global index:
geary(dta[,2], d1=0, d2=2000)
[1] 1

That is, I need something like the moran or geary commands in the previous
example, but applicable to categorical covariates. I have been googleing
for a while, but I have not been able to find a solution. Any idea?


Thanks in advance!


Perep
ResponderReenviar
#
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