SpatialDependence

The package SpatialDependence.jl is a Julia package for exploratory spatial data analysis (ESDA), including functions for spatial weights matrices creation, testing for spatial dependence (spatial autocorrelation), and choropleth mapping.

Installation

The package can be installed with the Julia package manager:

julia> using Pkg; Pkg.add("SpatialDependence")

Example

The following example reads Guerry's Moral statistics of France data, builds a spatial contiguity matrix from the polygons, and calculates the Morans' I global spatial autocorrelation statistic:

# Load packages
using Plots
using SpatialDependence
using SpatialDatasets
using StableRNGs

# Guerry's Moral statistics of France data from the SpatialDatasets.jl package
guerry = sdataset("Guerry");

# Plot Litercy variable
plot(guerry, :Litercy, NaturalBreaks(), legend = :topleft, title = "Litercy")
Example block output
# Build polygon contiguity matrix
W = polyneigh(guerry.geometry);
Spatial Weights 
Observations: 85 
Transformation: row
Minimum nunmber of neighbors: 2
Maximum nunmber of neighbors: 8
Average number of neighbors: 4.9412
Median number of neighbors: 5.0
Islands (isloated): 0
Density: 5.8131% 
# Global Moran test of Spatial Autocorrelation of the Litercy variable
moran(guerry.Litercy, W, permutations = 9999, rng = StableRNG(1234567))
Moran's I test of Global Spatial Autocorrelation
--------------------------------------------

Moran's I: 0.7176053
Expectation: -0.0119048

Randomization test with 9999 permutations.
 Mean: -0.0125941
 Std Error: 0.0707896
 zscore: 10.3150637
 p-value: 0.0001
# Moran Scatterplot of the Litercy variable
plot(guerry.Litercy, W, xlabel = "Litercy")
Example block output
# Local Indicators of Spatial Association (LISA) - Local Moran
lmguerry = localmoran(guerry.Litercy, W, permutations = 9999, rng = StableRNG(1234567))
Local Moran test of Spatial Autocorrelation
--------------------------------------------

Randomization test with 9999 permutations.
Interesting locations at 0.05 significance level:
       High-High: 18
         Low-Low: 20
        Low-High: 0
        High-Low: 0
# LISA Cluster Map
plot(guerry, lmguerry, sig = 0.05, adjust = :fdr)
Example block output

Documentation index

Authors

SpatialDependence.jl is being developed by Javier Barbero.