Examples for 'terra::autocor'


Spatial autocorrelation

Aliases: autocor autocor,numeric-method autocor,SpatRaster-method

Keywords: spatial

### ** Examples

### raster
r <- rast(nrows=10, ncols=10, xmin=0)
values(r) <- 1:ncell(r)

autocor(r)
   lyr.1 
1.117188 
# rook's case neighbors
f <- matrix(c(0,1,0,1,0,1,0,1,0), nrow=3)
autocor(r, f)
lyr.1 
 1.25 
# local 
rc <- autocor(r, w=f, global=FALSE)

### numeric (for vector data)
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
w <- relate(v, relation="touches")

# global
autocor(v$AREA, w)
[1] -0.1531971
# local
v$Gi <- autocor(v$AREA, w, "Gi")
plot(v, "Gi")
plot of chunk example-terra-autocor-1

[Package terra version 1.5-34 Index]