makecrosswalk vignette
Estimate 2016 census populations on the 2021 boundaries of Orangeville, Caledon and Mono. This example uses data bundled with the development package.
Load the census data
library(makecrosswalk)
folder <- system.file("extdata", "ontario", package = "makecrosswalk")
d <- readRDS(file.path(folder, "toronto_2016_2021.rds"))
crs <- sf::st_crs(d$blocks)The file contains the census layers, block-to-CSD links, land-cover areas and adjusted counts for validation. CSD stands for census subdivision.
Select N for GWEM
For your own data,
select_gwem_n(blocks, source_year = 2016) pairs blocks
automatically. The search picks the N that best recovers the original
block populations. The bundled example uses two pairs to focus on
boundary splits.
fit <- select_gwem_n(
d$blocks, focal_ids = d$focal_ids, landcover = d$landcover,
source_year = d$source_year, area_crs = crs
)Selected N = 73 neighbours.
Estimate population
M1 uses land area. M2 uses 2016 dissemination block populations, and M3 uses land area within populated 2016 blocks. EM fits a study-wide population density for each land-cover class. GWEM uses the selected N to fit local densities.
methods <- c("area", "population", "binary", "em", "gwem")
cw <- crosswalk_direct(
d$source, d$target, auxiliary = d$blocks, correspondence = d$correspondence,
landcover = d$landcover, methods = methods, em_control = fit$control,
source_year = d$source_year, target_year = d$target_year, area_crs = crs
)
population <- estimate_population(cw)Compare methods
d$observed contains the official 2016 counts adjusted to
the 2021 CSD boundaries. These counts share census inputs with the
estimates. You can record that with the optional
reference_role = "shared_inputs" argument, which leaves the
error calculations unchanged.
validation <- validate_estimates(population, d$observed)
knitr::kable(validation$summary[c("method", "n_compared", "MAE", "RMSE")],
digits = 2)| method | n_compared | MAE | RMSE |
|---|---|---|---|
| area | 3 | 573.61 | 702.49 |
| population | 3 | 287.25 | 351.70 |
| binary | 3 | 626.46 | 767.23 |
| em | 3 | 102.72 | 125.27 |
| gwem | 3 | 102.66 | 125.19 |
GWEM had the lowest MAE and RMSE for these three CSDs. Both metrics are in people, and RMSE gives more weight to large errors.
Export the shapefile
Run this line to save the target polygons with the five estimates. Keep the shapefile components together.
Boundary change near Toronto
The orange area was inside Orangeville’s 2016 boundary and appears within Caledon’s 2021 boundary.
See the Vancouver boundary map · See the land-cover maps for both regions
