
Bivariate Moran's I between two TPS categories
Source:R/tps_crime.R
morie_tps_bivariate_morans_i.RdTests whether category A's per-neighbourhood count co-varies with category B's count in NEIGHBOURING neighbourhoods (spatial spillover). Builds a k-NN row-standardised spatial weights matrix from per-hood centroids derived from category A's WGS84 latitude/longitude. Reports Pearson r alongside as a non-spatial baseline.
Examples
set.seed(1)
df <- data.frame(OCC_YEAR = rep(2014:2023, each = 30),
OCC_MONTH = sample(month.name, 300, TRUE),
HOOD_158 = sample(sprintf("%03d", 1:20), 300, TRUE),
LAT_WGS84 = runif(300, 43.6, 43.8),
LONG_WGS84 = runif(300, -79.5, -79.2))
dfs <- list(a = df, b = df)
res <- try(morie_tps_bivariate_morans_i(dfs, "a", "b"))
if (!inherits(res, "try-error")) str(res, max.level = 1)
#> List of 8
#> $ title : chr "Bivariate Moran's I -- a vs b"
#> $ call : chr "morie_tps_bivariate_morans_i(dfs, ‘a’, ‘b’)"
#> $ summary_lines :List of 6
#> $ tables : list()
#> $ warnings : chr(0)
#> $ interpretation: chr "I_AB=+0.055, Pearson r=+1.000. Positive I_AB means a counts in a hood track b counts in NEIGHBOURING hoods (sp"| __truncated__
#> $ payload :List of 7
#> $ sections : list()
#> - attr(*, "class")= chr [1:3] "morie_tps_result" "morie_rich_result" "list"