Title: | Redistricting Metrics |
---|---|
Description: | Reliable and flexible tools for scoring redistricting plans using common measures and metrics. These functions provide key direct access to tools useful for non-simulation analyses of redistricting plans, such as for measuring compactness or partisan fairness. Tools are designed to work with the 'redist' package seamlessly. |
Authors: | Christopher T. Kenny [aut, cre], Cory McCartan [aut], Ben Fifield [aut], Kosuke Imai [aut] |
Maintainer: | Christopher T. Kenny <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.8 |
Built: | 2024-11-04 04:50:29 UTC |
Source: | https://github.com/alarm-redist/redistmetrics |
If x
is repeated for each district, it returns a plan level value. Otherwise
it returns x
.
by_plan(x, ndists)
by_plan(x, ndists)
x |
summary statistic at the district level |
ndists |
numeric. Number of districts. Estimated as the gcd of the unique run length encodings if missing. |
x or plan level subset of x
by_plan(letters) by_plan(rep(letters, each = 2))
by_plan(letters) by_plan(rep(letters, each = 2))
Calculate Boyce Clark Ratio
comp_bc(plans, shp, epsg = 3857, ncores = 1)
comp_bc(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Boyce, R., & Clark, W. 1964. The Concept of Shape in Geography. Geographical Review, 54(4), 561-572.
data(nh) data(nh_m) # For a single plan: comp_bc(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_bc(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_bc(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_bc(plans = nh_m[, 3:5], shp = nh)
Box reock is the ratio of the area of the district by the area of the minimum bounding box (of any rotation). Scores are bounded between 0 and 1, where 1 is most compact.
comp_box_reock(plans, shp, epsg = 3857, ncores = 1)
comp_box_reock(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
#' data(nh) data(nh_m) # For a single plan: comp_box_reock(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_box_reock(plans = nh_m[, 3:5], shp = nh)
#' data(nh) data(nh_m) # For a single plan: comp_box_reock(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_box_reock(plans = nh_m[, 3:5], shp = nh)
Calculate Convex Hull Compactness
comp_ch(plans, shp, epsg = 3857, ncores = 1)
comp_ch(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: comp_ch(plans = nh$r_2020, shp = nh) # Or many plans: comp_ch(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_ch(plans = nh$r_2020, shp = nh) # Or many plans: comp_ch(plans = nh_m[, 3:5], shp = nh)
Calculate Edges Removed Compactness
comp_edges_rem(plans, shp, adj)
comp_edges_rem(plans, shp, adj)
plans |
A |
shp |
A |
adj |
Zero-indexed adjacency list. Not required if a |
A numeric vector. Can be shaped into a district-by-plan matrix.
Matthew P. Dube and Jesse Tyler Clark. 2016. Beyond the circle: Measuring district compactness using graph theory. In Annual Meeting of the Northeastern Political Science Association
data(nh) data(nh_m) # For a single plan: comp_edges_rem(plans = nh$r_2020, shp = nh, nh$adj) # Or many plans: comp_edges_rem(plans = nh_m[, 3:5], shp = nh, nh$adj)
data(nh) data(nh_m) # For a single plan: comp_edges_rem(plans = nh$r_2020, shp = nh, nh$adj) # Or many plans: comp_edges_rem(plans = nh_m[, 3:5], shp = nh, nh$adj)
Calculate Fryer Holden Compactness
comp_fh(plans, shp, total_pop, epsg = 3857, ncores = 1)
comp_fh(plans, shp, total_pop, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
total_pop |
A numeric vector with the population for every observation. |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
TRUE |
A numeric vector. Can be shaped into a district-by-plan matrix.
Fryer R, Holden R. 2011. Measuring the Compactness of Political Districting Plans. Journal of Law and Economics.
data(nh) data(nh_m) # For a single plan: comp_fh(plans = nh$r_2020, shp = nh, total_pop = pop) # Or many plans: comp_fh(plans = nh_m[, 3:5], shp = nh, pop)
data(nh) data(nh_m) # For a single plan: comp_fh(plans = nh$r_2020, shp = nh, total_pop = pop) # Or many plans: comp_fh(plans = nh_m[, 3:5], shp = nh, pop)
Calculate Fraction Kept Compactness
comp_frac_kept(plans, shp, adj)
comp_frac_kept(plans, shp, adj)
plans |
A |
shp |
A |
adj |
Zero-indexed adjacency list. Not required if a |
A numeric vector. Can be shaped into a district-by-plan matrix.
Matthew P. Dube and Jesse Tyler Clark. 2016. Beyond the circle: Measuring district compactness using graph theory. In Annual Meeting of the Northeastern Political Science Association
data(nh) data(nh_m) # For a single plan: comp_frac_kept(plans = nh$r_2020, shp = nh, nh$adj) # Or many plans: comp_frac_kept(plans = nh_m[, 3:5], shp = nh, nh$adj)
data(nh) data(nh_m) # For a single plan: comp_frac_kept(plans = nh$r_2020, shp = nh, nh$adj) # Or many plans: comp_frac_kept(plans = nh_m[, 3:5], shp = nh, nh$adj)
Calculate Log Spanning Tree Compactness
comp_log_st(plans, shp, counties = NULL, adj)
comp_log_st(plans, shp, counties = NULL, adj)
plans |
A |
shp |
A |
counties |
column name in shp containing counties |
adj |
Zero-indexed adjacency list. Not required if a |
A numeric vector. Can be shaped into a district-by-plan matrix.
Cory McCartan and Kosuke Imai. 2020. Sequential Monte Carlo for Sampling Balanced and Compact Redistricting Plans.
data(nh) data(nh_m) # For a single plan: comp_log_st(plans = nh$r_2020, shp = nh, counties = county, adj = nh$adj) # Or many plans: comp_log_st(plans = nh_m[, 3:5], shp = nh, counties = county, adj = nh$adj)
data(nh) data(nh_m) # For a single plan: comp_log_st(plans = nh$r_2020, shp = nh, counties = county, adj = nh$adj) # Or many plans: comp_log_st(plans = nh_m[, 3:5], shp = nh, counties = county, adj = nh$adj)
Calculate Length Width Compactness
comp_lw(plans, shp, epsg = 3857, ncores = 1)
comp_lw(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Harris, Curtis C. 1964. “A scientific method of districting”. Behavioral Science 3(9), 219–225.
data(nh) data(nh_m) # For a single plan: comp_lw(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_lw(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_lw(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_lw(plans = nh_m[, 3:5], shp = nh)
Calculate Polsby Popper Compactness
comp_polsby( plans, shp, use_Rcpp, perim_path, perim_df, epsg = 3857, ncores = 1 )
comp_polsby( plans, shp, use_Rcpp, perim_path, perim_df, epsg = 3857, ncores = 1 )
plans |
A |
shp |
A |
use_Rcpp |
If |
perim_path |
Path to perimeter tibble saved by |
perim_df |
Tibble of perimeters from |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Cox, E. 1927. A Method of Assigning Numerical and Percentage Values to the Degree of Roundness of Sand Grains. Journal of Paleontology, 1(3), 179-183.
Polsby, Daniel D., and Robert D. Popper. 1991. “The Third Criterion: Compactness as a procedural safeguard against partisan gerrymandering.” Yale Law & Policy Review 9 (2): 301–353.
data(nh) data(nh_m) # For a single plan: comp_polsby(plans = nh$r_2020, shp = nh) # Or many plans: comp_polsby(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_polsby(plans = nh$r_2020, shp = nh) # Or many plans: comp_polsby(plans = nh_m[, 3:5], shp = nh)
Calculate Reock Compactness
comp_reock(plans, shp, epsg = 3857, ncores = 1)
comp_reock(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Reock, E. 1961. A Note: Measuring Compactness as a Requirement of Legislative Apportionment. Midwest Journal of Political Science, 5(1), 70-74.
data(nh) data(nh_m) # For a single plan: comp_reock(plans = nh$r_2020, shp = nh) # Or many plans: comp_reock(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_reock(plans = nh$r_2020, shp = nh) # Or many plans: comp_reock(plans = nh_m[, 3:5], shp = nh)
Calculate Schwartzberg Compactness
comp_schwartz( plans, shp, use_Rcpp, perim_path, perim_df, epsg = 3857, ncores = 1 )
comp_schwartz( plans, shp, use_Rcpp, perim_path, perim_df, epsg = 3857, ncores = 1 )
plans |
A |
shp |
A |
use_Rcpp |
Logical. Use Rcpp? |
perim_path |
path to perimeter tibble saved by |
perim_df |
tibble of perimeters from |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Schwartzberg, Joseph E. 1966. Reapportionment, Gerrymanders, and the Notion of Compactness. Minnesota Law Review. 1701.
data(nh) data(nh_m) # For a single plan: comp_schwartz(plans = nh$r_2020, shp = nh) # Or many plans: comp_schwartz(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_schwartz(plans = nh$r_2020, shp = nh) # Or many plans: comp_schwartz(plans = nh_m[, 3:5], shp = nh)
Skew is defined as the ratio of the radii of the largest inscribed circle with the smallest bounding circle. Scores are bounded between 0 and 1, where 1 is most compact.
comp_skew(plans, shp, epsg = 3857, ncores = 1)
comp_skew(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
S.N. Schumm. 1963. Sinuosity of alluvial rivers on the Great Plains. Bulletin of the Geological Society of America, 74. 1089-1100.
data(nh) data(nh_m) # For a single plan: comp_skew(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_skew(plans = nh_m[, 3:5], shp = nh)
data(nh) data(nh_m) # For a single plan: comp_skew(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_skew(plans = nh_m[, 3:5], shp = nh)
X symmetry is the overlapping area of a shape and its projection over the x-axis.
comp_x_sym(plans, shp, epsg = 3857, ncores = 1)
comp_x_sym(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Aaron Kaufman, Gary King, and Mayya Komisarchik. 2021. How to Measure Legislative District Compactness If You Only Know it When You See It. American Journal of Political Science. 65, 3. Pp. 533-550.
#' data(nh) data(nh_m) # For a single plan: comp_x_sym(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_x_sym(plans = nh_m[, 3:5], shp = nh)
#' data(nh) data(nh_m) # For a single plan: comp_x_sym(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_x_sym(plans = nh_m[, 3:5], shp = nh)
Y symmetry is the overlapping area of a shape and its projection over the y-axis.
comp_y_sym(plans, shp, epsg = 3857, ncores = 1)
comp_y_sym(plans, shp, epsg = 3857, ncores = 1)
plans |
A |
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
ncores |
Integer number of cores to use. Default is 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Aaron Kaufman, Gary King, and Mayya Komisarchik. 2021. How to Measure Legislative District Compactness If You Only Know it When You See It. American Journal of Political Science. 65, 3. Pp. 533-550.
#' data(nh) data(nh_m) # For a single plan: comp_y_sym(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_y_sym(plans = nh_m[, 3:5], shp = nh)
#' data(nh) data(nh_m) # For a single plan: comp_y_sym(plans = nh$r_2020, shp = nh) # Or many plans: # slower, beware! comp_y_sym(plans = nh_m[, 3:5], shp = nh)
Compute Talismanic Redistricting Competitiveness Metric
compet_talisman(plans, shp, rvote, dvote, alpha = 1, beta = 1)
compet_talisman(plans, shp, rvote, dvote, alpha = 1, beta = 1)
plans |
A |
shp |
A |
rvote |
Unqouted name of column in |
dvote |
Unqouted name of column in |
alpha |
Numeric scaling value |
beta |
Numeric scaling value |
A numeric vector. Can be shaped into a district-by-plan matrix.
Wendy K. Tam Cho and Yan Y. Liu Toward a Talismanic Redistricting Tool. Election Law Journal. 15, 4. Pp. 351-366.
data(nh) data(nh_m) # For a single plan: compet_talisman(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: compet_talisman(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: compet_talisman(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: compet_talisman(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Euclidean Distances
dist_euc(plans, ncores = 1)
dist_euc(plans, ncores = 1)
plans |
A |
ncores |
Integer number of cores to use. Default is 1. |
matrix of plan distances
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_euc(plans = nh$r_2020) # Or many plans: dist_euc(plans = nh_m[, 3:5])
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_euc(plans = nh$r_2020) # Or many plans: dist_euc(plans = nh_m[, 3:5])
Calculate Hamming Distances
dist_ham(plans, ncores = 1)
dist_ham(plans, ncores = 1)
plans |
A |
ncores |
Integer number of cores to use. Default is 1. |
matrix of plan distances
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_ham(plans = nh$r_2020) # Or many plans: dist_ham(plans = nh_m[, 3:5])
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_ham(plans = nh$r_2020) # Or many plans: dist_ham(plans = nh_m[, 3:5])
Calculate Variation of Information Distances
dist_info(plans, shp, total_pop, ncores = 1)
dist_info(plans, shp, total_pop, ncores = 1)
plans |
A |
shp |
A |
total_pop |
Unqouted name of column in |
ncores |
Integer number of cores to use. Default is 1. |
matrix of plan distances
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_info(plans = nh$r_2020, shp = nh, total_pop = pop) # Or many plans: dist_info(plans = nh_m[, 3:5], shp = nh, total_pop = pop)
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_info(plans = nh$r_2020, shp = nh, total_pop = pop) # Or many plans: dist_info(plans = nh_m[, 3:5], shp = nh, total_pop = pop)
Calculate Manhattan Distances
dist_man(plans, ncores = 1)
dist_man(plans, ncores = 1)
plans |
A |
ncores |
Integer number of cores to use. Default is 1. |
matrix of plan distances
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_man(plans = nh$r_2020) # Or many plans: dist_man(plans = nh_m[, 3:5])
data(nh) data(nh_m) # For a single plan (distance is trivial, 0): dist_man(plans = nh$r_2020) # Or many plans: dist_man(plans = nh_m[, 3:5])
Count the number of incumbents paired with at least one other incumbent.
inc_pairs(plans, shp, inc)
inc_pairs(plans, shp, inc)
plans |
A |
shp |
A |
inc |
Unqouted name of logical column in |
vector of number of incumbents paired
data(nh) data(nh_m) # Use incumbent data: fake_inc <- rep(FALSE, nrow(nh)) fake_inc[3:4] <- TRUE # For a single plan: inc_pairs(plans = nh$r_2020, shp = nh, inc = fake_inc) # Or many plans: inc_pairs(plans = nh_m[, 3:5], shp = nh, inc = fake_inc)
data(nh) data(nh_m) # Use incumbent data: fake_inc <- rep(FALSE, nrow(nh)) fake_inc[3:4] <- TRUE # For a single plan: inc_pairs(plans = nh$r_2020, shp = nh, inc = fake_inc) # Or many plans: inc_pairs(plans = nh_m[, 3:5], shp = nh, inc = fake_inc)
This package uses prefixes for each function that correspond to the type of measure. This function returns the functions
list_fn(prefix)
list_fn(prefix)
prefix |
character prefix of functions to return |
character vector of functions
list_fn('part_')
list_fn('part_')
This data set contains demographic, election, and geographic information for the 326 voting tabulation districts in New Hampshire in 2020.
data("nh")
data("nh")
A tibble with 326 rows and 45 columns
GEOID20: 2020 VTD GEOID
state: state name
county: county name
vtd: VTD portion of GEOID
pop: total population
pop_hisp: Hispanic population
pop_white: White, not Hispanic population
pop_black: Black, not Hispanic population
pop_aian: American Indian and Alaska Native, not Hispanic population
pop_asian: Asian, not Hispanic population
pop_nhpi: Native Hawaiian and Pacific Islander, not Hispanic population
pop_other: other race, not Hispanic population
pop_two: multi-race, not Hispanic population
vap: total voting-age population
vap_hisp: Hispanic voting-age population
vap_white: White, not Hispanic voting-age population
vap_black: Black, not Hispanic voting-age population
vap_aian: American Indian and Alaska Native, not Hispanic voting-age population
vap_asian: Asian, not Hispanic voting-age population
vap_nhpi: Native Hawaiian and Pacific Islander, not Hispanic voting-age population
vap_other: other race, not Hispanic voting-age population
vap_two: multi-race, not Hispanic voting-age population
pre_16_rep_tru: Votes for Republican president 2016
pre_16_dem_cli: Votes for Democratic president 2016
uss_16_rep_ayo: Votes for Republican senate 2016
uss_16_dem_has: Votes for Democratic senate 2016
gov_16_rep_sun: Votes for Republican governor 2016
gov_16_dem_van: Votes for Democratic governor 2016
gov_18_rep_sun: Votes for Republican governor 2018
gov_18_dem_kel: Votes for Democratic governor 2018
pre_20_dem_bid: Votes for Democratic president 2020
pre_20_rep_tru: Votes for Republican president 2020
uss_20_dem_sha: Votes for Democratic senate 2020
uss_20_rep_mes: Votes for Republican senate 2020
gov_20_dem_fel: Votes for Democratic governor 2020
gov_20_rep_sun: Votes for Republican governor 2020
arv_16: Average Republican vote 2016
adv_16: Average Democratic vote 2016
arv_18: Average Republican vote 2018
adv_18: Average Democratic vote 2018
arv_20: Average Republican vote 2020
adv_20: Average Democratic vote 2020
nrv: Normal Republican vote
ndv: Normal Democratic vote
geometry: sf geometry, simplified for size using rmapshaper
r_2020: Republican proposed plan for 2020 Congressional districts
d_2020: Democratic proposed plan for 2020 Congressional districts
adj: zero-indexed adjacency graph
Voting and Election Science Team, 2020, "2020 Precinct-Level Election Results", https://doi.org/10.7910/DVN/K7760H, Harvard Dataverse, V23
Voting and Election Science Team, 2018, "2016 Precinct-Level Election Results", https://doi.org/10.7910/DVN/NH5S2I, Harvard Dataverse, V71
Voting and Election Science Team, 2019, "2018 Precinct-Level Election Results", https://doi.org/10.7910/DVN/UBKYRU, Harvard Dataverse, V48
Kenny & McCartan (2021, Aug. 10). ALARM Project: 2020 Redistricting Data Files. Retrieved from https://github.com/alarm-redist/census-2020/
data(nh)
data(nh)
matrix
This data set contains two reference plans (d_2020
and r_2020
) and
50 simulated plans for New Hampshire, based on 2020 demographics, simulated at
a population tolerance of 0.05%.
data("nh_m")
data("nh_m")
A matrix with 52 columns and 326 rows where each column is a plan
data(nh_m)
data(nh_m)
redist_map
This data set contains demographic, election, and geographic information for the 326 voting tabulation districts in New Hampshire in 2020.
data("nh_map")
data("nh_map")
A redist_map with 326 rows and 45 columns
GEOID20: 2020 VTD GEOID
state: state name
county: county name
vtd: VTD portion of GEOID
pop: total population
pop_hisp: Hispanic population
pop_white: White, not Hispanic population
pop_black: Black, not Hispanic population
pop_aian: American Indian and Alaska Native, not Hispanic population
pop_asian: Asian, not Hispanic population
pop_nhpi: Native Hawaiian and Pacific Islander, not Hispanic population
pop_other: other race, not Hispanic population
pop_two: multi-race, not Hispanic population
vap: total voting-age population
vap_hisp: Hispanic voting-age population
vap_white: White, not Hispanic voting-age population
vap_black: Black, not Hispanic voting-age population
vap_aian: American Indian and Alaska Native, not Hispanic voting-age population
vap_asian: Asian, not Hispanic voting-age population
vap_nhpi: Native Hawaiian and Pacific Islander, not Hispanic voting-age population
vap_other: other race, not Hispanic voting-age population
vap_two: multi-race, not Hispanic voting-age population
pre_16_rep_tru: Votes for Republican president 2016
pre_16_dem_cli: Votes for Democratic president 2016
uss_16_rep_ayo: Votes for Republican senate 2016
uss_16_dem_has: Votes for Democratic senate 2016
gov_16_rep_sun: Votes for Republican governor 2016
gov_16_dem_van: Votes for Democratic governor 2016
gov_18_rep_sun: Votes for Republican governor 2018
gov_18_dem_kel: Votes for Democratic governor 2018
pre_20_dem_bid: Votes for Democratic president 2020
pre_20_rep_tru: Votes for Republican president 2020
uss_20_dem_sha: Votes for Democratic senate 2020
uss_20_rep_mes: Votes for Republican senate 2020
gov_20_dem_fel: Votes for Democratic governor 2020
gov_20_rep_sun: Votes for Republican governor 2020
arv_16: Average Republican vote 2016
adv_16: Average Democratic vote 2016
arv_18: Average Republican vote 2018
adv_18: Average Democratic vote 2018
arv_20: Average Republican vote 2020
adv_20: Average Democratic vote 2020
nrv: Normal Republican vote
ndv: Normal Democratic vote
r_2020: Republican proposed plan for 2020 Congressional districts
d_2020: Democratic proposed plan for 2020 Congressional districts
adj: zero-indexed adjacency graph
geometry: sf geometry, simplified for size using rmapshaper
Voting and Election Science Team, 2020, "2020 Precinct-Level Election Results", https://doi.org/10.7910/DVN/K7760H, Harvard Dataverse, V23
Voting and Election Science Team, 2018, "2016 Precinct-Level Election Results", https://doi.org/10.7910/DVN/NH5S2I, Harvard Dataverse, V71
Voting and Election Science Team, 2019, "2018 Precinct-Level Election Results", https://doi.org/10.7910/DVN/UBKYRU, Harvard Dataverse, V48
Kenny & McCartan (2021, Aug. 10). ALARM Project: 2020 Redistricting Data Files. Retrieved from https://github.com/alarm-redist/census-2020/
data(nh_map)
data(nh_map)
redist_plans
This data set contains two reference plans (d_2020
and r_2020
) and
50 simulated plans for New Hampshire, based on 2020 demographics, simulated at
a population tolerance of 0.05%.
data("nh_plans")
data("nh_plans")
A redist_plans with 104 rows and 3 columns
draw: factor identifying the reference plans (d_2020
and r_2020
) and 50 simulted plans
district: district number (1
or 2
)
total_pop: total population in the district
data(nh_plans)
data(nh_plans)
Calculate Partisan Bias
part_bias(plans, shp, dvote, rvote, v = 0.5)
part_bias(plans, shp, dvote, rvote, v = 0.5)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
v |
vote share to calculate bias at. Numeric. Default is 0.5. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Jonathan N. Katz, Gary King, and Elizabeth Rosenblatt. 2020. Theoretical Foundations and Empirical Evaluations of Partisan Fairness in District-Based Democracies. American Political Science Review, 114, 1, Pp. 164-178.
data(nh) data(nh_m) # For a single plan: part_bias(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_bias(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_bias(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_bias(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Declination
part_decl(plans, shp, dvote, rvote, normalize = TRUE, adjust = TRUE)
part_decl(plans, shp, dvote, rvote, normalize = TRUE, adjust = TRUE)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
normalize |
Default is TRUE Translate score to an angle? |
adjust |
Default is TRUE. Applies a correction to increase cross-size comparison. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Gregory S. Warrington. 2018. "Quantifying Gerrymandering Using the Vote Distribution." Election Law Journal: Rules, Politics, and Policy. Pp. 39-57.http://doi.org/10.1089/elj.2017.0447
data(nh) data(nh_m) # For a single plan: part_decl(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_decl(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_decl(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_decl(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Simplified Declination
part_decl_simple(plans, shp, dvote, rvote)
part_decl_simple(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Jonathan N. Katz, Gary King, and Elizabeth Rosenblatt. 2020. Theoretical Foundations and Empirical Evaluations of Partisan Fairness in District-Based Democracies. American Political Science Review, 114, 1, Pp. 164-178.
data(nh) data(nh_m) # For a single plan: part_decl_simple(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_decl_simple(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_decl_simple(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_decl_simple(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Dilution Asymmetry
part_dil_asym(plans, shp, dvote, rvote)
part_dil_asym(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Sanford C. Gordon and Sidak Yntiso. 2024. Base Rate Neglect and the Diagnosis of Partisan Gerrymanders. Election Law Journal: Rules, Politics, and Policy. doi:10.1089/elj.2023.0005.
data(nh) data(nh_m) # For a single plan: part_dil_asym(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dil_asym(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_dil_asym(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dil_asym(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Democratic Seats
part_dseats(plans, shp, dvote, rvote)
part_dseats(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: part_dseats(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dseats(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_dseats(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dseats(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Democratic Vote Share
part_dvs(plans, shp, dvote, rvote)
part_dvs(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: part_dvs(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dvs(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_dvs(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_dvs(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Efficiency Gap
part_egap(plans, shp, dvote, rvote)
part_egap(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Nicholas O. Stephanopoulos. 2015. Partisan Gerrymandering and the Efficiency Gap. The University of Chicago Law Review, 82, Pp. 831-900.
data(nh) data(nh_m) # For a single plan: part_egap(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_egap(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_egap(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_egap(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Efficiency Gap (Equal Population Assumption)
part_egap_ep(plans, shp, dvote, rvote)
part_egap_ep(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Nicholas O. Stephanopoulos. 2015. Partisan Gerrymandering and the Efficiency Gap. The University of Chicago Law Review, 82, Pp. 831-900.
data(nh) data(nh_m) # For a single plan: part_egap_ep(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_egap_ep(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_egap_ep(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_egap_ep(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Lopsided Wins
part_lop_wins(plans, shp, dvote, rvote)
part_lop_wins(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Samuel S.-H. Wang. 2016. "Three Tests for Practical Evaluation of Partisan Gerrymandering." Stanford Law Review, 68, Pp. 1263 - 1321.
data(nh) data(nh_m) # For a single plan: part_lop_wins(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_lop_wins(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_lop_wins(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_lop_wins(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Mean Median Score
part_mean_median(plans, shp, dvote, rvote)
part_mean_median(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Michael D. McDonald and Robin E. Best. 2015. Unfair Partisan Gerrymanders in Politics and Law: A Diagnostic Applied to Six Cases. Election Law Journal: Rules, Politics, and Policy. 14. 4. Pp. 312-330.
data(nh) data(nh_m) # zero for the two district case: # For a single plan: part_mean_median(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_mean_median(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # zero for the two district case: # For a single plan: part_mean_median(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_mean_median(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Responsiveness
part_resp(plans, shp, dvote, rvote, v = 0.5, bandwidth = 0.01)
part_resp(plans, shp, dvote, rvote, v = 0.5, bandwidth = 0.01)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
v |
vote share to calculate bias at. Numeric. Default is 0.5. |
bandwidth |
Defaults to 0.01. A value between 0 and 1 for the step size to estimate the slope. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Jonathan N. Katz, Gary King, and Elizabeth Rosenblatt. 2020. Theoretical Foundations and Empirical Evaluations of Partisan Fairness in District-Based Democracies. American Political Science Review, 114, 1, Pp. 164-178.
data(nh) data(nh_m) # For a single plan: part_resp(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_resp(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_resp(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_resp(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Ranked Marginal Deviation
part_rmd(plans, shp, dvote, rvote)
part_rmd(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Gregory Herschlag, Han Sung Kang, Justin Luo, Christy Vaughn Graves, Sachet Bangia, Robert Ravier & Jonathan C. Mattingly (2020) Quantifying Gerrymandering in North Carolina, Statistics and Public Policy, 7:1, 30-38, DOI: 10.1080/2330443X.2020.1796400
data(nh) data(nh_m) # For a single plan: part_rmd(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_rmd(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_rmd(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_rmd(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Smoothed Seat Count Deviation
part_sscd(plans, shp, dvote, rvote)
part_sscd(plans, shp, dvote, rvote)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Gregory Herschlag, Han Sung Kang, Justin Luo, Christy Vaughn Graves, Sachet Bangia, Robert Ravier & Jonathan C. Mattingly (2020) Quantifying Gerrymandering in North Carolina, Statistics and Public Policy, 7:1, 30-38, DOI: 10.1080/2330443X.2020.1796400
data(nh) data(nh_m) # For a single plan: part_sscd(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_sscd(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_sscd(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_sscd(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Calculate Tau Gap
part_tau_gap(plans, shp, dvote, rvote, tau = 1)
part_tau_gap(plans, shp, dvote, rvote, tau = 1)
plans |
A |
shp |
A |
dvote |
Unqouted name of column in |
rvote |
Unqouted name of column in |
tau |
A non-negative numeric for calculating Tau Gap. Defaults to 1. |
A numeric vector. Can be shaped into a district-by-plan matrix.
Gregory S. Warrington. 2018. "Quantifying Gerrymandering Using the Vote Distribution." Election Law Journal: Rules, Politics, and Policy. Pp. 39-57.http://doi.org/10.1089/elj.2017.0447
data(nh) data(nh_m) # For a single plan: part_tau_gap(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_tau_gap(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
data(nh) data(nh_m) # For a single plan: part_tau_gap(plans = nh$r_2020, shp = nh, rvote = nrv, dvote = ndv) # Or many plans: part_tau_gap(plans = nh_m[, 3:5], shp = nh, rvote = nrv, dvote = ndv)
Replaces redist.prep.polsbypopper
prep_perims(shp, epsg = 3857, perim_path, ncores = 1)
prep_perims(shp, epsg = 3857, perim_path, ncores = 1)
shp |
A |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
perim_path |
A path to save an rds |
ncores |
Integer number of cores to use. Default is 1. |
tibble of perimeters and lengths
data(nh) prep_perims(nh)
data(nh) prep_perims(nh)
Compute Dissimilarity Index
seg_dissim(plans, shp, group_pop, total_pop)
seg_dissim(plans, shp, group_pop, total_pop)
plans |
A |
shp |
A |
group_pop |
Unqouted name of column in |
total_pop |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
Douglas Massey and Nancy Denton. 1987. The Dimensions of Social Segregation. Social Forces.
data(nh) data(nh_m) # For a single plan: seg_dissim(plans = nh$r_2020, shp = nh, group_pop = vap_hisp, total_pop = vap) # Or many plans: seg_dissim(plans = nh_m[, 3:5], shp = nh, group_pop = vap_hisp, total_pop = vap)
data(nh) data(nh_m) # For a single plan: seg_dissim(plans = nh$r_2020, shp = nh, group_pop = vap_hisp, total_pop = vap) # Or many plans: seg_dissim(plans = nh_m[, 3:5], shp = nh, group_pop = vap_hisp, total_pop = vap)
Compute Number of Administrative Units Split
splits_admin(plans, shp, admin)
splits_admin(plans, shp, admin)
plans |
A |
shp |
A |
admin |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: splits_admin(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_admin(plans = nh_m[, 3:5], shp = nh, admin = county)
data(nh) data(nh_m) # For a single plan: splits_admin(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_admin(plans = nh_m[, 3:5], shp = nh, admin = county)
Tallies the number of unique administrative unit-districts. An unsplit administrative unit will return an entry of 1, while each additional administrative unit-district adds 1.
splits_count(plans, shp, admin)
splits_count(plans, shp, admin)
plans |
A |
shp |
A |
admin |
Unqouted name of column in |
numeric matrix
data(nh) data(nh_m) # For a single plan: splits_count(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_count(plans = nh_m[, 3:5], shp = nh, admin = county)
data(nh) data(nh_m) # For a single plan: splits_count(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_count(plans = nh_m[, 3:5], shp = nh, admin = county)
Not all relevant geographies nest neatly into Census blocks, including communities of interest or neighborhood. For these cases, this provides a tabulation by district of the number of splits. As some geographies can be split multiple times, the sum of these splits may not reflect the total number of splits.
splits_district_fuzzy(plans, shp, nbr, thresh = 0.01, epsg)
splits_district_fuzzy(plans, shp, nbr, thresh = 0.01, epsg)
plans |
A |
shp |
A |
nbr |
Geographic neighborhood, community, or other unit to check splits for. |
thresh |
Percent as decimal of an area to trim away. Default is .01, which is 1%. |
epsg |
Numeric EPSG code to use to project the shapefile, if needed. Default is 3857. |
Beware, this requires a nbr
shape input and will be slower than checking splits in cases where
administrative unit nests cleanly into the geographies represented by shp
.
numeric matrix
data(nh) data(nh_m) # toy example, # suppose we care about the splits of the counties and they don't nest nh_cty <- nh %>% dplyr::group_by(county) %>% dplyr::summarize() # For a single plan: splits_district_fuzzy(plans = nh$r_2020, shp = nh, nbr = nh_cty) # Or many plans: splits_district_fuzzy(plans = nh_m[, 3:5], shp = nh, nbr = nh_cty)
data(nh) data(nh_m) # toy example, # suppose we care about the splits of the counties and they don't nest nh_cty <- nh %>% dplyr::group_by(county) %>% dplyr::summarize() # For a single plan: splits_district_fuzzy(plans = nh$r_2020, shp = nh, nbr = nh_cty) # Or many plans: splits_district_fuzzy(plans = nh_m[, 3:5], shp = nh, nbr = nh_cty)
Compute Number of Administrative Units Split More than Once
splits_multi(plans, shp, admin)
splits_multi(plans, shp, admin)
plans |
A |
shp |
A |
admin |
Unqouted name of column in |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: splits_multi(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_multi(plans = nh_m[, 3:5], shp = nh, admin = county)
data(nh) data(nh_m) # For a single plan: splits_multi(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_multi(plans = nh_m[, 3:5], shp = nh, admin = county)
Compute Number of Sub-Administrative Units Split
splits_sub_admin(plans, shp, sub_admin)
splits_sub_admin(plans, shp, sub_admin)
plans |
A |
shp |
A |
sub_admin |
Unqouted name of column in shp with numeric identifiers for subsidiary administrative units. |
A numeric vector. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) # For a single plan: splits_sub_admin(plans = nh$r_2020, shp = nh, sub_admin = county) # Or many plans: splits_sub_admin(plans = nh_m[, 3:5], shp = nh, sub_admin = county)
data(nh) data(nh_m) # For a single plan: splits_sub_admin(plans = nh$r_2020, shp = nh, sub_admin = county) # Or many plans: splits_sub_admin(plans = nh_m[, 3:5], shp = nh, sub_admin = county)
Tallies the number of unique sub-administrative unit-districts. An unsplit administrative unit will return an entry of 1, while each additional sub-administrative unit-district adds 1.
splits_sub_count(plans, shp, sub_admin)
splits_sub_count(plans, shp, sub_admin)
plans |
A |
shp |
A |
sub_admin |
Unqouted name of column in shp with numeric identifiers for subsidiary administrative units. |
numeric matrix
data(nh) data(nh_m) # For a single plan: splits_sub_count(plans = nh$r_2020, shp = nh, sub_admin = county) # Or many plans: splits_sub_count(plans = nh_m[, 3:5], shp = nh, sub_admin = county)
data(nh) data(nh_m) # For a single plan: splits_sub_count(plans = nh$r_2020, shp = nh, sub_admin = county) # Or many plans: splits_sub_count(plans = nh_m[, 3:5], shp = nh, sub_admin = county)
Counts the total number of administrative splits.
splits_total(plans, shp, admin)
splits_total(plans, shp, admin)
plans |
A |
shp |
A |
admin |
Unqouted name of column in |
numeric matrix
data(nh) data(nh_m) # For a single plan: splits_total(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_total(plans = nh_m[, 3:5], shp = nh, admin = county)
data(nh) data(nh_m) # For a single plan: splits_total(plans = nh$r_2020, shp = nh, admin = county) # Or many plans: splits_total(plans = nh_m[, 3:5], shp = nh, admin = county)
Helper function to aggregate a vector by district. Can be used to calculate total population, group percentages, and more.
tally(plans, shp, x)
tally(plans, shp, x)
plans |
A |
shp |
A |
x |
The numeric vector to tally. |
A numeric vector with the tallies. Can be shaped into a district-by-plan matrix.
data(nh) data(nh_m) tally(nh_m, nh, pop) # total population tally(nh_m, nh, vap_hisp) / tally(nh_m, nh, vap) # HVAP
data(nh) data(nh_m) tally(nh_m, nh, pop) # total population tally(nh_m, nh, vap_hisp) / tally(nh_m, nh, vap) # HVAP