Learn R Programming

mlspatial (version 0.1.1)

compute_spatial_autocorr: 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)

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.

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).

Examples

Run this code
# \donttest{
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
# }

Run the code above in your browser using DataLab