compute_spatial_autocorr: Compute Moran's I & LISA, classify clusters

View source: R/spatial_autocorrelation.R

compute_spatial_autocorrR Documentation

Compute Moran's I & LISA, classify clusters

Description

Computes global and local Moran’s I to assess spatial autocorrelation and classifies observations into spatial cluster types (e.g., High-High).

Usage

compute_spatial_autocorr(sf_data, values, signif = 0.05)

Arguments

sf_data

An sf object containing spatial features.

values

A numeric vector or column name with the variable to test.

signif

Numeric significance level threshold for clusters (default 0.05).

Value

A named list with elements:

  • data: An sf object with added columns for standardized values, spatial lag, local Moran's I values, z-scores, p-values, and cluster classification.

  • moran: An object of class htest with global Moran's I test results.

Examples


library(sf)
library(spdep)
library(dplyr)

#Load and prepare spatial data
mapdata <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
mapdata <- st_make_valid(mapdata)

#Variable to analyze
values <- rnorm(nrow(mapdata))

#Run function
result <- compute_spatial_autocorr(mapdata, values, signif = 0.05)

#Inspect results
head(result$data)
result$moran



mlspatial documentation built on Aug. 27, 2025, 1:09 a.m.