Skip to contents

Mirrors morie_tps_csi_per_year but groups by neighbourhood ID rather than fiscal year. Population is not divided in here because TPS open data does not ship a per-ward population table; callers are expected to merge in the City of Toronto Open Data NeighbourhoodCrimeRates per-ward population for per-capita rates. Returns the un-normalised weighted sum + total count.

Usage

morie_tps_csi_per_neighbourhood(
  counts_per_hood,
  variant = c("total", "violent"),
  weights = NULL
)

Arguments

counts_per_hood

Long data.frame (columns HOOD_158, category, count) or nested list [[hood]][[category]] = count.

variant

One of "total" or "violent".

weights

Optional override vector of weights.

Value

A data.frame with one row per neighbourhood.

Examples

counts <- data.frame(HOOD_158 = rep(sprintf("%03d", 1:4), 2),
                     category = rep(c("Assault", "Robbery"), each = 4),
                     n = rpois(8, 50))
res <- try(morie_tps_csi_per_neighbourhood(counts))
#> Error : long-format data.frame must have columns HOOD_158, category, count
if (!inherits(res, "try-error")) str(res, max.level = 1)