Skip to contents

Performs a statistical test for spatial autocorrelation using Moran's I. Returns the test statistic, expected value, standard deviation, and p-value.

Usage

moranI_test(
  x,
  W,
  alternative = c("greater", "less", "two.sided"),
  standardize = TRUE
)

Arguments

x

Numeric vector of values.

W

Square numeric matrix of spatial weights.

alternative

Character string specifying the alternative hypothesis. One of "greater" (default), "less", or "two.sided".

  • "greater": Test for positive spatial autocorrelation (similar values cluster together)

  • "less": Test for negative spatial autocorrelation (dissimilar values are neighbors)

  • "two.sided": Test for any spatial autocorrelation

standardize

Logical. If TRUE (default), row-standardize weights.

Value

A named numeric vector with components:

  • observed: Observed Moran's I

  • expected: Expected Moran's I under null

  • sd: Standard deviation under null

  • p.value: P-value from normal approximation

Examples

set.seed(42)
x <- rnorm(100)
coords <- cbind(runif(100), runif(100))
W <- buildSpatialNetwork(coords, method = "knn", k = 6)
result <- moranI_test(x, W)
print(result)
#>     observed     expected           sd      p.value 
#>  0.001644026 -0.010101010  0.052004378  0.410660185