Skip to content

Commit

Permalink
Merge pull request #191 from alarm-redist/HI_cd_2010
Browse files Browse the repository at this point in the history
2010 Hawaii Congressional Districts (use VTD not tract)
  • Loading branch information
CoryMcCartan committed Jul 15, 2024
2 parents d6feae2 + eabac51 commit 4ae4ed5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
75 changes: 41 additions & 34 deletions analyses/HI_cd_2010/01_prep_HI_cd_2010.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ cli_process_start("Downloading files for {.pkg HI_cd_2010}")

path_data <- download_redistricting_file("HI", "data-raw/HI", year = 2010, type = "block", overwrite = TRUE)

# download the enacted plan.
url <- "https://redistricting.lls.edu/wp-content/uploads/hi_2010_congress_2011-09-26_2021-12-31.zip"
path_enacted <- "data-raw/HI/HI_enacted.zip"
download(url, here(path_enacted))
unzip(here(path_enacted), exdir = here(dirname(path_enacted), "HI_enacted"))
file.remove(path_enacted)
path_enacted <- "data-raw/HI/HI_enacted/congress11.shp"

cli_process_done()

# Compile raw data into a final shapefile for analysis -----
Expand All @@ -46,36 +38,32 @@ if (!file.exists(here(shp_path))) {
# add municipalities
d_muni <- get_baf_10("HI", "INCPLACE_CDP")[[1]] %>%
rename(GEOID = BLOCKID, muni = PLACEFP)
# add cd
d_cd <- get_baf_10("HI", "CD")[[1]] %>%
rename(GEOID = BLOCKID, cd_2000 = DISTRICT)
hi_shp <- left_join(hi_shp, d_muni, by = "GEOID") %>%

hi_shp <- hi_shp %>%
left_join(d_muni, by = "GEOID") %>%
left_join(d_cd, by = "GEOID") %>%
left_join(read_baf_cd113("HI") %>% rename(GEOID = BLOCKID), by = "GEOID") %>%
# left_join(d_vtd, by = "GEOID") %>%
mutate(county_muni = if_else(is.na(muni), county, str_c(county, muni))) %>%
relocate(muni, county_muni, cd_2000, .after = county)

# add the enacted plan by geomatching Honolulu County
# (the rest of the state is in District 2)
cd_shp <- st_read(here(path_enacted))
honolulu <- hi_shp %>% filter(county == "003") %>%
mutate(cd_2010 = as.integer(cd_shp$USDist)[
geo_match(honolulu, cd_shp, method = "area")],
.after = cd_2000)
rest_shp <- hi_shp %>%
filter(county != "003") %>%
mutate(cd_2010 = 2, .after = cd_2000)
hi_shp <- rbind(rest_shp, honolulu)
relocate(muni, county_muni, cd_2000, cd_2010, .after = county)

# group from block-level to tract-level

hi_shp <- hi_shp %>%
mutate(tract = str_sub(GEOID, 1, 11)) %>%
group_by(tract) %>%
summarize(cd_2000 = Mode(cd_2000),
censable::breakdown_geoid() %>%
group_by(state, county, tract) %>%
summarize(
cd_2000 = Mode(cd_2000),
cd_2010 = Mode(cd_2010),
muni = Mode(muni),
state = unique(state),
county = unique(county),
across(where(is.numeric), sum)
across(where(is.numeric), sum),
.groups = "drop"
) %>%
mutate(
GEOID = str_c(state, county, tract),
state = censable::match_abb(unique(state))
)

# Create perimeters in case shapes are simplified
Expand All @@ -102,15 +90,34 @@ if (!file.exists(here(shp_path))) {
"15009031503", "15009031601",
"15009031601", "15009031700",
"15009031801", "15003000110",
"15003009904", "15007040500",
"15003990001", "15007040500",
"15007040900", "15007041200",
"15007041200", "15003981200"
"15003990001", "15003981200"
)

island_codes$v1 <- match(island_codes$v1, hi_shp$GEOID)
island_codes$v2 <- match(island_codes$v2, hi_shp$GEOID)

hi_shp$adj <- hi_shp$adj %>%
add_edge(island_codes$v1, island_codes$v2, zero = TRUE)

# handle the Honolulu boundary tract

hi_shp$adj <- hi_shp$adj |>
remove_edge(v1 = rep(294L, length(hi_shp$adj[[294]])), hi_shp$adj[[294]] + 1L)

honolulu_boundary <- tribble(
~v1, ~v2,
"15003990001", "15007040500",
"15003990001", "15003981200",
"15003990001", "15003010303"
)

island_codes$v1 <- which(hi_shp$tract %in% island_codes$v1)[order(na.omit(match(hi_shp$tract, island_codes$v1)))]
island_codes$v2 <- which(hi_shp$tract %in% island_codes$v2)[order(na.omit(match(hi_shp$tract, island_codes$v2)))]
honolulu_boundary$v1 <- match(honolulu_boundary$v1, hi_shp$GEOID)
honolulu_boundary$v2 <- match(honolulu_boundary$v2, hi_shp$GEOID)

hi_shp$adj <- hi_shp$adj %>% add_edge(island_codes$v1, island_codes$v2, zero = TRUE)
hi_shp$adj <- hi_shp$adj %>%
add_edge(honolulu_boundary$v1, honolulu_boundary$v2, zero = TRUE)

hi_shp <- hi_shp %>%
fix_geo_assignment(muni)
Expand Down
3 changes: 1 addition & 2 deletions analyses/HI_cd_2010/02_setup_HI_cd_2010.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ cli_process_start("Creating {.cls redist_map} object for {.pkg HI_cd_2010}")
map <- redist_map(hi_shp, pop_tol = 0.005,
existing_plan = cd_2010, adj = hi_shp$adj)

# Create sub-map for Honolulu County (excluding its Northwestern Hawaiian Islands)
# Create sub-map for Honolulu County
map_honolulu <- map %>%
slice(-291) %>%
filter(county == "003") %>%
`attr<-`("pop_bounds", attr(map, "pop_bounds"))

Expand Down
2 changes: 1 addition & 1 deletion analyses/HI_cd_2010/03_sim_HI_cd_2010.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plans_honolulu <- redist_smc(
)

plans <- matrix(data = 0, nrow = nrow(map), ncol = 5001)
plans[map$tract %in% map_honolulu$tract, ] <- get_plans_matrix(plans_honolulu)
plans[map$GEOID %in% map_honolulu$GEOID, ] <- get_plans_matrix(plans_honolulu)
plans[plans == 0] <- 2

plans <- redist_plans(
Expand Down
2 changes: 1 addition & 1 deletion analyses/HI_cd_2010/doc_HI_cd_2010.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 2010 Hawaii Congressional Districts

## Redistricting requirements
Per Hawaii Revised Statutes 25-2(b)(1)-(4) and (6), [as in force for the 2010 cycle](https://www.ncsl.org/Portals/1/Documents/Redistricting/Redistricting_2010.pdf), districts must:
Per Hawaii Revised Statutes 25-2(b)(1)-(4) and (6), [as in force for the 2010 cycle](https://law.justia.com/codes/hawaii/2011/division1/title3/chapter25/25-2/), districts must:

1\. not unduly favor any person or party;

Expand Down

0 comments on commit 4ae4ed5

Please sign in to comment.