knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This vignette introduces some of the most common measures of some basic measures of the distance between plans. This offers a quick look at how similar or different a pair of plans are. See the vignette "Using redistmetrics
" for the bare-bones of the package.
We first load the redistmetrics
package and data from New Hampshire. For any function, the shp
argument can be swapped out for your data, pop
for your population, and the plans
argument can be swapped out for your redistricting plans (be it a single plan, a matrix of plans, or a redist_plans
object).
library(redistmetrics) data(nh)
Note that, when computing distance between plans, you always want to provide more than one plan. For that reason, we will also load nh_m
, a matrix of plans for New Hampshire.
data(nh_m) nh_m <- nh_m[, 1:4]
We subset it to its first four columns (the first four plans).
The recommended distance between plans is the variation of information. This considers the distance between plans by looking at the joint distributions of people across plans.
The Variation of Information can be computed with:
dist_info(plans = nh_m, shp = nh, total_pop = pop)
The Hamming distance is a simpler metric which just considers how many units are assigned to different districts between pairs of plans.
The Hamming distance can be computed with:
dist_ham(plans = nh_m)
The Manhattan distance measures how many "blocks" you would need to move to get between plans. This is most useful in MCMC contexts, rather than general contexts.
The Manhattan distance can be computed with:
dist_man(plans = nh_m)
The Euclidean distance measures the square root of the summed distances you would need to move to get between plans. This is most useful in MCMC contexts, rather than general contexts.
The Euclidean distance can be computed with:
dist_euc(plans = nh_m)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.