View source: R/spatial_autocorrelation.R
compute_spatial_autocorr | R Documentation |
Computes global and local Moran’s I to assess spatial autocorrelation and classifies observations into spatial cluster types (e.g., High-High).
compute_spatial_autocorr(sf_data, values, signif = 0.05)
sf_data |
An |
values |
A numeric vector or column name with the variable to test. |
signif |
Numeric significance level threshold for clusters (default 0.05). |
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.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.