Skip to contents

Builds a k-NN spatial weights matrix from neighbourhood centroids (mean LAT/LONG of incidents in each hood) and computes the global Moran's I on the count vector. The Cliff-Ord normal-assumption variance is used for the z-score and two-sided p-value.

Usage

morie_tps_morans_i_neighbourhood(
  df,
  hood_col = "HOOD_158",
  ds_name = "?",
  k_neighbours = 5L,
  lat_col = "LAT_WGS84",
  lon_col = "LONG_WGS84",
  use_spdep = FALSE
)

Arguments

df

Incident-level data.frame.

hood_col

Character. Neighbourhood id column (default "HOOD_158").

ds_name

Character. Tag for the result title.

k_neighbours

k for the k-NN spatial weights graph (default 5).

lat_col, lon_col

WGS84 column names (default "LAT_WGS84" / "LONG_WGS84").

use_spdep

If TRUE and spdep is installed, delegate the test to spdep::moran.test (with a row- standardised listw). Default FALSE.

Value

A named list with classes morie_tps_spatial_result, morie_rich_result, list. Numeric outputs include moran_I, expected_I, var_I, z_score, p_value, n.

Examples

set.seed(2026)
n_inc <- 400
df <- data.frame(
  HOOD_158 = sample(letters[1:20], n_inc, replace = TRUE),
  LAT_WGS84 = 43.6 + runif(n_inc, 0, 0.2),
  LONG_WGS84 = -79.4 + runif(n_inc, 0, 0.2)
)
morie_tps_morans_i_neighbourhood(df)
#> Moran's I (global) -- ?
#> =======================
#> Call: morie_tps_morans_i_neighbourhood(df=<400r>, hood_col=HOOD_158, k=5) 
#> 
#>   Spatial unit           HOOD_158
#>   Neighbourhoods         20
#>   k-nearest neighbours   5
#>   Moran's I              0.03
#>   Expected I under null  -0.052632
#>   Variance(I)            0.00049457
#>   z-score                3.7156
#>   p-value (two-sided)    0.0002027
#>   Backend                internal Cliff-Ord normal approximation
#> 
#> Global Moran's I = +0.030 on 20 neighbourhood(s) with a k=5-NN weights matrix (backend: internal Cliff-Ord normal approximation). z = +3.72, two-sided p = 0.0002027. Positive I means nearby neighbourhoods share similar incident counts (spatial clustering); negative indicates a checkerboard pattern; near zero is consistent with spatial randomness.