Compute Moran's I or Geary's C measures of global spatial autocorrelation in a RasterLayer, or compute the the local Moran or Geary index (Anselin, 1995).

Geary(x, w=matrix(c(1,1,1,1,0,1,1,1,1), 3,3))
Moran(x, w=matrix(c(1,1,1,1,0,1,1,1,1), 3,3))
MoranLocal(x, w=matrix(c(1,1,1,1,0,1,1,1,1), 3,3))
GearyLocal(x, w=matrix(c(1,1,1,1,0,1,1,1,1), 3,3))

## Arguments

x

RasterLayer

w

Spatial weights defined by or a rectangular matrix with odd length (3, 5, ...) sides (as in focal)

## Value

A single value (Moran's I or Geary's C) or a RasterLayer (Local Moran or Geary values)

## Details

The default setting uses a 3x3 neighborhood to compute "Queen's case" indices. You can use a filter (weights matrix) to do other things, such as "Rook's case", or different lags.

The spdep package for additional and more general approaches for computing indices of spatial autocorrelation

## Author

Robert J. Hijmans and Babak Naimi

## Examples

r <- raster(nrows=10, ncols=10)
values(r) <- 1:ncell(r)

Moran(r)
#>  0.8353565
# Rook's case
f <- matrix(c(0,1,0,1,0,1,0,1,0), nrow=3)
Moran(r, f)
#>  0.8929367

Geary(r)
#>  0.04739631

x1 <- MoranLocal(r)

# Rook's case
x2 <- MoranLocal(r, w=f)