redist.mcmc is used to simulate Congressional redistricting plans using Markov Chain Monte Carlo methods.

redist.flip(
  adj,
  total_pop,
  nsims,
  ndists = NULL,
  init_plan = NULL,
  constraints = redist_constr(),
  loopscompleted = 0,
  nloop = 1,
  warmup = 0,
  nthin = 1,
  eprob = 0.05,
  lambda = 0,
  pop_tol = NULL,
  temper = FALSE,
  betaseq = "powerlaw",
  betaseqlength = 10,
  betaweights = NULL,
  adjswaps = TRUE,
  rngseed = NULL,
  maxiterrsg = 5000,
  adapt_lambda = FALSE,
  adapt_eprob = FALSE,
  exact_mh = FALSE,
  savename = NULL,
  verbose = TRUE
)

Arguments

adj

adjacency matrix, list, or object of class "SpatialPolygonsDataFrame."

total_pop

A vector containing the populations of each geographic unit

nsims

The number of simulations run before a save point.

ndists

The number of congressional districts. The default is NULL.

init_plan

A vector containing the congressional district labels of each geographic unit. If not provided, random and contiguous congressional district assignments will be generated using redist_smc. To use the old behavior of generating with redist.rsg, provide init_plan = 'rsg'.

constraints

A redist_constr list.

loopscompleted

Number of save points reached by the algorithm. The default is 0.

nloop

The total number of save points for the algorithm. The default is 1. Note that the total number of simulations run will be nsims * nloop. savename must be non-null.

warmup

The number of warmup samples to discard. The default is 0.

nthin

The amount by which to thin the Markov Chain. The default is 1.

eprob

The probability of keeping an edge connected. The default is 0.05.

lambda

The parameter determining the number of swaps to attempt each iteration of the algorithm. The number of swaps each iteration is equal to Pois(lambda) + 1. The default is 0.

pop_tol

The strength of the hard population constraint. pop_tol = 0.05 means that any proposed swap that brings a district more than 5% away from population parity will be rejected. The default is NULL.

temper

Whether to use simulated tempering algorithm. Default is FALSE.

betaseq

Sequence of beta values for tempering. The default is powerlaw (see Fifield et. al (2015) for details).

betaseqlength

Length of beta sequence desired for tempering. The default is 10.

betaweights

Sequence of weights for different values of beta. Allows the user to upweight certain values of beta over others. The default is NULL (equal weighting).

adjswaps

Flag to restrict swaps of beta so that only values adjacent to current constraint are proposed. The default is TRUE.

rngseed

Allows the user to set the seed for the simulations. Default is NULL.

maxiterrsg

Maximum number of iterations for random seed-and-grow algorithm to generate starting values. Default is 5000.

adapt_lambda

Whether to adaptively tune the lambda parameter so that the Metropolis-Hastings acceptance probability falls between 20% and 40%. Default is FALSE.

adapt_eprob

Whether to adaptively tune the edgecut probability parameter so that the Metropolis-Hastings acceptance probability falls between 20% and 40%. Default is FALSE.

exact_mh

Whether to use the approximate (0) or exact (1) Metropolis-Hastings ratio calculation for accept-reject rule. Default is FALSE.

savename

Filename to save simulations. Default is NULL.

verbose

Whether to print initialization statement. Default is TRUE.

Value

redist.mcmc returns an object of class "redist". The object redist is a list that contains the following components (the inclusion of some components is dependent on whether tempering techniques are used):

plans

Matrix of congressional district assignments generated by the algorithm. Each row corresponds to a geographic unit, and each column corresponds to a simulation.

distance_parity

Vector containing the maximum distance from parity for a particular simulated redistricting plan.

mhdecisions

A vector specifying whether a proposed redistricting plan was accepted (1) or rejected (0) in a given iteration.

mhprob

A vector containing the Metropolis-Hastings acceptance probability for each iteration of the algorithm.

pparam

A vector containing the draw of the p parameter for each simulation, which dictates the number of swaps attempted.

constraint_pop

A vector containing the value of the population constraint for each accepted redistricting plan.

constraint_compact

A vector containing the value of the compactness constraint for each accepted redistricting plan.

constraint_segregation

A vector containing the value of the segregation constraint for each accepted redistricting plan.

constraint_vra

A vector containing the value of the vra constraint for each accepted redistricting plan.

constraint_similar

A vector containing the value of the similarity constraint for each accepted redistricting plan.

constraint_partisan

A vector containing the value of the partisan constraint for each accepted redistricting plan.

constraint_minority

A vector containing the value of the minority constraint for each accepted redistricting plan.

constraint_hinge

A vector containing the value of the hinge constraint for each accepted redistricting plan.

constraint_qps

A vector containing the value of the QPS constraint for each accepted redistricting plan.

beta_sequence

A vector containing the value of beta for each iteration of the algorithm. Returned when tempering is being used.

mhdecisions_beta

A vector specifying whether a proposed beta value was accepted (1) or rejected (0) in a given iteration of the algorithm. Returned when tempering is being used.

mhprob_beta

A vector containing the Metropolis-Hastings acceptance probability for each iteration of the algorithm. Returned when tempering is being used.

Details

This function allows users to simulate redistricting plans using Markov Chain Monte Carlo methods. Several constraints corresponding to substantive requirements in the redistricting process are implemented, including population parity and geographic compactness. In addition, the function includes multiple-swap and simulated tempering functionality to improve the mixing of the Markov Chain.

References

Fifield, Benjamin, Michael Higgins, Kosuke Imai and Alexander Tarr. (2016) "A New Automated Redistricting Simulator Using Markov Chain Monte Carlo." Working Paper. Available at http://imai.princeton.edu/research/files/redist.pdf.

Examples

# \donttest{
data(fl25)
data(fl25_enum)
data(fl25_adj)

## Code to run the simulations in Figure 4 in Fifield, Higgins, Imai and Tarr (2015)

## Get an initial partition
init_plan <- fl25_enum$plans[, 5118]

## Run the algorithm
alg_253 <- redist.flip(adj = fl25_adj, total_pop = fl25$pop,
    init_plan = init_plan, nsims = 10000)
#> Warning: Please use `redist_flip`. This will be gone in 4.1.
#> 
#> ==================== 
#> redist.flip(): Automated Redistricting Simulation Using
#>          Markov Chain Monte Carlo
#> 
#> Preprocessing data.
#> 
#> Starting swMH().
#>    0% | ETA:10s
#> ■■                                 2% | ETA: 7s
#> ■■■                                5% | ETA: 6s
#> ■■■                                8% | ETA: 6s
#> ■■■■                              11% | ETA:  6s | MH Acceptance: 0.96
#> ■■■■■                             14% | ETA:  6s | MH Acceptance: 0.96
#> ■■■■■■                            17% | ETA:  6s | MH Acceptance: 0.96
#> ■■■■■■■                           20% | ETA:  6s | MH Acceptance: 0.96
#> ■■■■■■■■                          22% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■                         26% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■                        29% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■                        32% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■■                       35% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■                      38% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■                     41% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■                    44% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■                   47% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■                  50% | ETA:  3s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■                 53% | ETA:  3s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■                56% | ETA:  3s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■               59% | ETA:  3s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■               61% | ETA:  3s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■              64% | ETA:  2s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■             68% | ETA:  2s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  2s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■           73% | ETA:  2s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■          76% | ETA:  2s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■         79% | ETA:  1s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■        82% | ETA:  1s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■       85% | ETA:  1s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■       88% | ETA:  1s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      91% | ETA:  1s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■     94% | ETA:  0s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    97% | ETA:  0s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s | MH Acceptance: 0.96
#> 

## You can also let it find a plan on its own!
sims <- redist.flip(adj = fl25_adj, total_pop = fl25$pop,
    ndists = 3, nsims = 10000)
#> Warning: Please use `redist_flip`. This will be gone in 4.1.
#> 
#> ==================== 
#> redist.flip(): Automated Redistricting Simulation Using
#>          Markov Chain Monte Carlo
#> 
#> Preprocessing data.
#> 
#> Starting swMH().
#>    0% | ETA:10s
#> ■■                                 3% | ETA: 7s
#> ■■■                                6% | ETA: 7s
#> ■■■■                               8% | ETA: 6s
#> ■■■■                              11% | ETA:  6s | MH Acceptance: 0.95
#> ■■■■■                             14% | ETA:  6s | MH Acceptance: 0.95
#> ■■■■■■                            17% | ETA:  6s | MH Acceptance: 0.95
#> ■■■■■■■                           21% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■                          24% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■                         27% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■                        30% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■■                       33% | ETA:  5s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■                      36% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■                     39% | ETA:  4s | MH Acceptance: 0.96
#> ■■■■■■■■■■■■■                     41% | ETA:  4s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■                    44% | ETA:  4s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■                   47% | ETA:  4s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■                  50% | ETA:  3s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■                 53% | ETA:  3s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■                56% | ETA:  3s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■               59% | ETA:  3s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■              62% | ETA:  3s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■             65% | ETA:  2s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■             68% | ETA:  2s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■            71% | ETA:  2s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■           74% | ETA:  2s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■          77% | ETA:  2s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■         80% | ETA:  1s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■        83% | ETA:  1s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■       86% | ETA:  1s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      89% | ETA:  1s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■     92% | ETA:  1s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■     95% | ETA:  0s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    98% | ETA:  0s | MH Acceptance: 0.97
#> ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s | MH Acceptance: 0.97
#> 
# }