Disaggregate per-140 counts to per-158 counts (uniform-density)
Source:R/toronto_neighbourhoods.R
morie_tps_disaggregate_140_to_158.RdCake-cutting in the FORWARD direction. Given a data.frame of per-
historical-hood counts (one row per hood_140, one or more numeric
count columns), splits each 140's count across its 158-children in
proportion to pct_140_in_158 / 100. For 1:1 hoods the count is
passed through unchanged. For splits the count is partitioned
(e.g. 140-75 Church-Yonge Corridor's 100 incidents become 59.24 in
158-168 Downtown Yonge East and 40.76 in 158-167 Church-Wellesley).
Usage
morie_tps_disaggregate_140_to_158(
df,
hood_140_col = "HOOD_140",
count_cols = NULL,
crosswalk = NULL
)Arguments
- df
A
data.framekeyed on a 140-hood column.- hood_140_col
Name of the 140-hood column. Default
"HOOD_140".- count_cols
Character vector of numeric count columns to disaggregate. Default: every numeric column in
dfexcepthood_140_col.- crosswalk
Optional pre-loaded crosswalk; defaults to
morie_to_hood_crosswalk().
Value
A data.frame with columns hood_158, name_158,
hood_140, all chosen count_cols (now per-158 fractional
counts), and pct_140_in_158 (the cake-cut weight applied).
Details
This assumes UNIFORM SPATIAL DENSITY of the underlying events
inside each 140-hood – which is the best you can do without per-
incident lat/lon. If you have lat/lon, prefer re-binning from
points (via sf::st_join against
morie_to_neighbourhoods("158", offline = FALSE)) over this
uniform-density approximation.
Examples
df <- data.frame(HOOD_140 = c("075", "001"),
incidents = c(100, 42))
morie_tps_disaggregate_140_to_158(df)
#> hood_158 name_158 hood_140 incidents pct_140_in_158
#> 1 168 Downtown Yonge East 075 59.2433 59.2433
#> 2 167 Church-Wellesley 075 40.7567 40.7567
#> 3 001 West Humber-Clairville 001 42.0000 100.0000