Local Getis-Ord Gi* statistic per neighbourhood
Source:R/tps_spatial_advanced.R
morie_tps_getis_ord_g_star.RdReturns Gi* per neighbourhood (count vector aggregated from the incident data.frame), using a binary k-NN spatial weights matrix with self-inclusion (Gi* convention). z-score interpretation: Gi*1.96 = significant hot spot at alpha=0.05; Gi* < -1.96 =significant cold spot.
Usage
morie_tps_getis_ord_g_star(
df,
ds_name = "?",
hood_col = "HOOD_158",
k_neighbours = 5L,
top_n = 20L,
lat_col = "LAT_WGS84",
lon_col = "LONG_WGS84"
)Value
A named list with Gi* per hood, the top hot/cold spot tables, and tallies of hot/cold spots at alpha=0.05.
Examples
set.seed(2026)
df <- data.frame(
HOOD_158 = sample(letters[1:20], 400, replace = TRUE),
LAT_WGS84 = 43.6 + runif(400, 0, 0.2),
LONG_WGS84 = -79.4 + runif(400, 0, 0.2)
)
morie_tps_getis_ord_g_star(df)
#> Getis-Ord Gi* -- ?
#> ==================
#> Call: morie_tps_getis_ord_g_star(df=<400r>, hood_col=HOOD_158, k=5)
#>
#> Spatial unit HOOD_158
#> Neighbourhoods 20
#> k-NN (incl. self) 6
#> Hotspots (Gi* > 1.96) 2
#> Cold spots (Gi* < -1.96) 0
#> Max Gi* 2.3321
#> Min Gi* -1.1154
#>
#> Across 20 neighbourhood(s) with a binary k=6-NN weights matrix (self-inclusive), Gi* identifies 2 hot spot(s) (Gi* > 1.96) and 0 cold spot(s) (Gi* < -1.96) at alpha=0.05. Max Gi* = +2.33 at 'm'; min Gi* = -1.12 at 'q'.