MyNixOS website logo
Description

Redistricting Metrics.

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.

redistmetrics

R-CMD-check CRANstatus CRANdownloads

redistmetrics is one of the R packages developed and maintained by the ALARM Project. redistmetrics provides the back-end for the computation of summary statistics for a redistricting plan. It provides a more direct access point to use methods in redist without requiring redist objects.

Installation

You can install the stable version of redistmetrics from CRAN with:

install.packages('redistmetrics')

You can install the development version of redistmetrics from GitHub with:

if (!requireNamespace('remotes')) install.packages('remotes')
remotes::install_github('alarm-redist/redistmetrics')

Example

library(redistmetrics)

redistmetrics offers support for 4 common input types and has examples of each, all based on New Hampshire:

data(nh)

This example is based on comp_polsby() for the Polsby Popper compactness, but comp_polsby() can be substituted for any implemented measure!

Single Plan:

For a single plan, we can pass the single plan to the input. We also pass an argument to shp which takes in an sf dataframe. r_2020 here is the Republican proposal for New Hampshire’s congressional districts.

comp_polsby(plans = nh$r_2020, shp = nh)
#> [1] 0.2324375 0.1582763

The output here is a numeric vector, where each entry is the output for a district. The first district here has a compactness of about 0.23 and the second district has a compactness of about 0.16.

Now, if you’re redistricting in R, we recommend using the R package redist. In which case, you would have a redist_map object.

We can load an example here with:

data(nh_map)

For redist maps, the workflow is identical!

comp_polsby(plans = nh_map$r_2020, shp = nh)
#> [1] 0.2324375 0.1582763

Multiple Plans:

For multiple plans, we can pass either a matrix of plans or a redist_plans object to plans. We will still need nh or nh_map to provide the shapes.

If we have a matrix, we can compare with nh_m a matrix of plans, where each column indicates a plan.

data(nh_m)

From there, the process is nearly identical. Here we compute the Polsby Popper compactness for the first two columns:

comp_polsby(plans = nh_m[, 1:2], shp = nh)
#> [1] 0.1844955 0.1796426 0.2324375 0.1582763

Now we got 4 outputs: 1 for each district x 2 for each plan x 2 plans.

If we are using redist, we likely have a redist_plans object which hides the matrix as an attribute to give a more familiar tidy workflow. With that, we can do a very similar process:

First, we load the plans object (included as an example):

data(nh_plans)

The benefit of using a redist_plans object is that we can cleanly mutate into it using the . shortcut:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
nh_plans <- nh_plans %>% mutate(polsby = comp_polsby(plans = ., shp = nh))
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE

Now our values are cleanly held in the redist_plans object:

head(nh_plans)
#> # A tibble: 6 × 4
#>   draw   district total_pop polsby
#>   <fct>     <int>     <dbl>  <dbl>
#> 1 d_2020        1    688739  0.184
#> 2 d_2020        2    688790  0.180
#> 3 r_2020        1    688676  0.232
#> 4 r_2020        2    688853  0.158
#> 5 1             1    688961  0.235
#> 6 1             2    688568  0.349

Detailed information on each measure are contained in the vignettes and references are contained in the function documentation.

Metadata

Version

1.0.7

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows