7

GitHub - alarm-redist/redist: Simulation methods for legislative redistricting.

 2 years ago
source link: https://github.com/alarm-redist/redist/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

redist: Simulation Methods for Legislative Redistricting

This R package enables researchers to sample redistricting plans from a pre-specified target distribution using Sequential Monte Carlo and Markov Chain Monte Carlo algorithms. The package supports various constraints in the redistricting process, such as geographic compactness and population parity requirements. Tools for analysis, including computation of various summary statistics and plotting functionality, are also included.

Authors:

Contributors:

Papers:

Installation Instructions

redist is available on CRAN and can be installed using:

install.packages("redist")

You can also install the most recent development version of redist using the `remotes`` package.

if (!require(remotes)) install.packages("remotes")
remotes::install_github("alarm-redist/redist", dependencies=TRUE)

Getting started

A basic analysis has two steps. First, you define a redistricting plan using redist_map. Then you simulate plans using one of the algorithm functions: redist_smc, redist_flip, and redist_mergesplit.

library(redist)
library(dplyr)

data(iowa)

# set a 0.01% population constraint
iowa_map = redist_map(iowa, existing_plan=cd_2010, pop_tol=0.0001, total_pop = pop)
# simulate 250 plans using the SMC algorithm
iowa_plans = redist_smc(iowa_map, nsims=250, verbose=FALSE)
#> SEQUENTIAL MONTE CARLO
#> Sampling 250 99-unit maps with 4 districts and population between 761513 and 761665.
#> Making split 1 of 3
#> Note: maximum hit; falling back to naive k estimator.
#> Resampling effective sample size: 246.051 (98.4206 efficiency).
#> Making split 2 of 3
#> Resampling effective sample size: 245.859 (98.3437 efficiency).
#> Making split 3 of 3
#> Resampling effective sample size: 246.756 (98.7022 efficiency).

After generating plans, you can use redist’s plotting functions to study the geographic and partisan characteristics of the simulated ensemble.

library(ggplot2)
library(patchwork) # for plotting

redist.plot.plans(iowa_plans, draws=c("cd_2010", "1", "2", "3"),
                  geom=iowa_map)
dev_comp = iowa_plans %>%
    mutate(comp = distr_compactness(iowa_map)) %>%
    group_by(draw) %>%
    summarize(`Population deviation` = max(abs(total_pop/get_target(iowa_map) - 1)),
              Compactness = comp[1])

hist(dev_comp, `Population deviation`) + hist(dev_comp, Compactness) +
    plot_layout(guides="collect") +
    plot_annotation(title="Simulated plan characteristics")
redist.plot.scatter(dev_comp, `Population deviation`, Compactness) +
    labs(title="Population deviation and compactness by plan")
iowa_plans %>%
    mutate(`Democratic vote` = group_frac(iowa_map, dem_08, tot_08)) %>%
    plot(`Democratic vote`, size=0.5, color_thresh=0.5) +
    scale_color_manual(values=c("tomato2", "dodgerblue")) +
    labs(title="Democratic vote share by district")

A more detailed introduction to redistricting methods and the package can be found in the Get Started page. The package vignettes contain more detailed information and guides to specific workflows.

Recommended Workflows

In some cases, there are two functions with the same purpose that operate on different inputs. For most users, we recommend working with the versions that operate on redist_map and redist_plan objects.

Recommended Alternate Options Notes redist_smc redist.smc

redist_mergesplit redist.mergesplit

redist_flip redist.flip (Formerly called redist.mcmc)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK