
Composite per-neighbourhood crime-risk index across TPS categories
Source:R/tps_crime.R
morie_tps_composite_index.RdFor each TPS category, computes per-HOOD_158 counts, z-standardises across neighbourhoods, and sums (or weight-and-sums) the z-scores to yield a single composite per neighbourhood. Positive composite = neighbourhood with elevated incidence across many crime types; near-zero = average; negative = below-average exposure.
Arguments
- dfs
Named list of TPS data.frames keyed by category.
- categories
Optional character vector restricting categories.
- weights
Optional named numeric vector of per-category weights; defaults to 1.0 for every loaded category.
- top_n
How many top/bottom neighbourhoods to surface in the tables (default
25L).
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_composite_index(dfs))
if (!inherits(res, "try-error")) str(res, max.level = 1)
#> List of 8
#> $ title : chr "TPS -- composite crime-risk index per neighbourhood"
#> $ call : chr "morie_tps_composite_index(dfs)"
#> $ summary_lines :List of 5
#> $ tables :List of 2
#> $ warnings : chr(0)
#> $ interpretation: chr "Composite is the unweighted (or weighted) sum of z-standardised counts across all loaded TPS categories. Posit"| __truncated__
#> $ payload :List of 4
#> $ sections : list()
#> - attr(*, "class")= chr [1:3] "morie_tps_result" "morie_rich_result" "list"