match_numbers: Renumber districts to match an existing plan

View source: R/numbering.R

match_numbersR Documentation

Renumber districts to match an existing plan

Description

District numbers in simulated plans are by and large random. This function attempts to renumber the districts across all simulated plans to match the numbers in a provided plan, using the Hungarian algorithm.

Usage

match_numbers(
  data,
  plan,
  total_pop = attr(data, "prec_pop"),
  col = "pop_overlap"
)

Arguments

data

a redist_plans object.

plan

a character vector giving the name of the plan to match to (e.g., for a reference plan), or an integer vector containing the plan itself.

total_pop

a vector of population counts. Should not be needed for most redist_plans objects.

col

the name of a new column to store the vector of population overlap with the reference plan: the fraction of the total population who are in the same district under each plan and the reference plan. Set to NULL if no column should be created. renumbering options in any plan.

Value

a modified redist_plans object. New district numbers will be stored as an ordered factor variable in the district column. The district numbers in the plan matrix will match the levels of this factor.

Examples

data(iowa)

iowa_map <- redist_map(iowa, existing_plan = cd_2010, pop_tol = 0.05)
plans <- redist_smc(iowa_map, 100, silent = TRUE)
match_numbers(plans, "cd_2010")


redist documentation built on June 24, 2024, 9:10 a.m.