View source: R/classify_compare.R
compare_plans | R Documentation |
This function provides one way to identify the structural differences between two sets of redistricting plans. It operates by computing the precinct co-occurrence matrix (a symmetric matrix where the i,j-th entry is the fraction of plans where precinct i and j are in the same district) for each set, and then computing the first eigenvalue of the difference in these two matrices (in each direction). These eigenvalues identify the important parts of the map.
compare_plans(
plans,
set1,
set2,
shp = NULL,
plot = "fill",
thresh = 0.1,
labs = c("Set 1", "Set 2"),
ncores = 1
)
plans |
a redist_plans object |
set1 |
|
set2 |
|
shp |
a shapefile for plotting. |
plot |
If |
thresh |
the value to threshold the eigenvector at in determining the relevant set of precincts for comparison. |
labs |
the names of the panels in the plot. |
ncores |
the number of parallel cores to use. |
The co-occurrence matrices are regularized with a Beta(1/ndists, 1-1/ndists)
prior, which is useful for when either set1
or set2
is small.
If possible, makes a comparison plot according to plot
. Otherwise
returns the following list:
eigen1 |
A numeric vector containing the first eigenvector of
|
eigen2 |
A numeric vector containing the first eigenvector of
|
group_1a , group_1b |
Lists of precincts. Compared to |
group_2a , group_2b |
Lists of precincts. Compared to |
cooccur_sep_1 |
The difference in the average co-occurrence of precincts
in |
cooccur_sep_2 |
The difference in the average co-occurrence of precincts
in |
data(iowa)
iowa_map <- redist_map(iowa, ndists = 4, pop_tol = 0.05)
plans1 <- redist_smc(iowa_map, 100, silent = TRUE)
plans2 <- redist_mergesplit(iowa_map, 200, warmup = 100, silent = TRUE)
compare_plans(plans1, plans2, shp = iowa_map)
compare_plans(plans2, as.integer(draw) <= 20,
as.integer(draw) > 20, shp = iowa_map, plot = "line")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.