| Title: | Download, Merge, and Process Redistricting Data |
| Version: | 0.2.4 |
| Description: | Utility functions to download and process data produced by the ALARM Project, including 2020 redistricting files Kenny and McCartan (2021) https://alarm-redist.org/posts/2021-08-10-census-2020/ and the 50-State Redistricting Simulations of McCartan, Kenny, Simko, Garcia, Wang, Wu, Kuriwaki, and Imai (2022) <doi:10.7910/DVN/SLCD3E>. The package extends the data introduced in McCartan, Kenny, Simko, Garcia, Wang, Wu, Kuriwaki, and Imai (2022) <doi:10.1038/s41597-022-01808-2> to also include states with only a single district. The package also includes the Japanese 2022 redistricting files from the 47-Prefecture Redistricting Simulations of Miyazaki, Yamada, Yatsuhashi, and Imai (2022) <doi:10.7910/DVN/Z9UKSH>. |
| Depends: | R (≥ 4.1.0) |
| Imports: | rlang, cli, curl, dplyr, readr, stringr, sf, dataverse, censable, geomander (≥ 2.1.0), tidyselect, redist (≥ 4.2.0), redistmetrics, tinytiger, rappdirs |
| Suggests: | rstudioapi, rmapshaper, testthat (≥ 3.0.0), spelling |
| License: | MIT + file LICENSE |
| URL: | https://github.com/alarm-redist/alarmdata/, https://alarm-redist.org/alarmdata/ |
| BugReports: | https://github.com/alarm-redist/alarmdata/issues/ |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Language: | en-US |
| NeedsCompilation: | no |
| Packaged: | 2025-12-12 14:10:38 UTC; chris |
| Author: | Cory McCartan |
| Maintainer: | Christopher T. Kenny <ctkenny@proton.me> |
| Repository: | CRAN |
| Date/Publication: | 2025-12-12 15:50:12 UTC |
alarmdata: Download, Merge, and Process Redistricting Data
Description
Utility functions to download and process data produced by the ALARM Project, including 2020 redistricting files Kenny and McCartan (2021) https://alarm-redist.org/posts/2021-08-10-census-2020/ and the 50-State Redistricting Simulations of McCartan, Kenny, Simko, Garcia, Wang, Wu, Kuriwaki, and Imai (2022) doi:10.7910/DVN/SLCD3E. The package extends the data introduced in McCartan, Kenny, Simko, Garcia, Wang, Wu, Kuriwaki, and Imai (2022) doi:10.1038/s41597-022-01808-2 to also include states with only a single district. The package also includes the Japanese 2022 redistricting files from the 47-Prefecture Redistricting Simulations of Miyazaki, Yamada, Yatsuhashi, and Imai (2022) doi:10.7910/DVN/Z9UKSH.
Author(s)
Maintainer: Christopher T. Kenny ctkenny@proton.me (ORCID)
Authors:
Cory McCartan mccartan@psu.edu (ORCID)
Tyler Simko tsimko@g.harvard.edu (ORCID)
Michael Zhao michaelzhao@college.harvard.edu (ORCID)
Sho Miyazaki shomiya@stanford.edu (ORCID)
Kosuke Imai imai@harvard.edu (ORCID)
See Also
Useful links:
Report bugs at https://github.com/alarm-redist/alarmdata/issues/
Download maps and plans from the 50-State Simulation Project
Description
These functions will download redist_map and
redist_plans objects for the 50-State Simulation
Project from the ALARM Project's Dataverse. alarm_50state_doc() will
download documentation for a particular state and show it in a browser.
alarm_50state_stats will download just the summary statistics for a state.
Usage
alarm_50state_map(state, year = 2020, refresh = FALSE)
alarm_50state_plans(
state,
stats = TRUE,
year = 2020,
refresh = FALSE,
compress = "xz"
)
alarm_50state_stats(state, year = 2020, refresh = FALSE)
alarm_50state_doc(state, year = 2020)
Arguments
state |
A state name, abbreviation, FIPS code, or ANSI code. |
year |
The redistricting cycle to download. Currently only |
refresh |
If |
stats |
If |
compress |
The compression level used for caching redist_plans objects. |
Details
Every decade following the Census, states and municipalities must redraw districts for Congress, state houses, city councils, and more. The goal of the 50-State Simulation Project is to enable researchers, practitioners, and the general public to use cutting-edge redistricting simulation analysis to evaluate enacted congressional districts.
Evaluating a redistricting plan requires analysts to take into account each state’s redistricting rules and particular political geography. Comparing the partisan bias of a plan for Texas with the bias of a plan for New York, for example, is likely misleading. Comparing a state’s current plan to a past plan is also problematic because of demographic and political changes over time. Redistricting simulations generate an ensemble of alternative redistricting plans within a given state which are tailored to its redistricting rules. Unlike traditional evaluation methods, therefore, simulations are able to directly account for the state’s political geography and redistricting criteria.
Value
For alarm_50state_map(), a redist_map. For
alarm_50state_plans(), a redist_plans. For
alarm_50state_doc(), invisibly returns the path to the HTML documentation,
and also loads an HTML file into the viewer or web browser.
For alarm_50state_stats(), a tibble.
Examples
# requires Harvard Dataverse API key
alarm_50state_map("WA")
alarm_50state_plans("WA", stats = FALSE)
alarm_50state_stats("WA")
alarm_50state_doc("WA")
map <- alarm_50state_map("WY")
pl <- alarm_50state_plans("WY")
Add a reference plan to a set of plans
Description
Facilitates comparing an existing (i.e., non-simulated) redistricting plan to a set of simulated plans.
Usage
alarm_add_plan(
plans,
ref_plan,
map = NULL,
name = NULL,
calc_polsby = FALSE,
GEOID = "GEOID",
year = 2020
)
Arguments
plans |
A |
ref_plan |
An |
map |
A |
name |
A human-readable name for the reference plan. Defaults to the name of |
calc_polsby |
A logical value indicating whether a Polsby-Popper compactness score should be calculated for the reference plan. Defaults to |
GEOID |
character. If |
year |
the decade to request if passing a |
Value
A modified redist_plans object containing the reference plan. Includes summary statistics if the original redist_plans object had them as well.
Examples
# requires Harvard Dataverse API key
map <- alarm_50state_map("WY")
pl <- alarm_50state_plans("WY")
pl_new <- alarm_add_plan(pl, ref_plan = c(1), map, name = "example")
# download and load a comparison plan
url <- paste0("https://github.com/PlanScore/Redistrict2020/raw/main/files/",
"NM-2021-10/Congressional_Concept_A.zip")
tf <- tempfile(fileext = ".zip")
utils::download.file(url, tf)
utils::unzip(tf, exdir = dirname(tf))
baf <- readr::read_csv(file = paste0(dirname(tf), "/Congressional Concept A.csv"),
col_types = "ci")
names(baf) <- c("GEOID", "concept_a")
# Add it to the plans object
map_nm <- alarm_50state_map("NM")
plans_nm <- alarm_50state_plans("NM", stats = FALSE)
alarm_add_plan(plans_nm, baf, map = map_nm, name = "concept_a")
Work with the the alarmdata cache
Description
Functions to inspect and clear the cache. If the cache is not enabled, uses a temporary directory.
Usage
alarm_cache_size()
alarm_cache_clear(force = FALSE)
alarm_cache_path()
Arguments
force |
FALSE by default. Asks the user to confirm if interactive. Does not clear cache if force is FALSE and not interactive. |
Value
For alarm_cache_size(), the size in bytes, invisibly
For alarm_cache_clear(), the path to the cache, invisibly.
For alarm_cache_path(), the path to the cache
Examples
alarm_cache_size()
alarm_cache_clear()
alarm_cache_path()
Download Joined VEST and Census Data
Description
Downloads Census data joined with VEST's election data. All are re-tabulated from precincts collected by VEST to 2020 Census geographies.
Usage
alarm_census_vest(state, geometry = FALSE, epsg = alarm_epsg(state))
Arguments
state |
A state name, abbreviation, FIPS code, or ANSI code. |
geometry |
If |
epsg |
A numeric EPSG code to use as the coordinate system. Default is |
Value
tibble with Census and election data
Examples
alarm_census_vest("DE", geometry = FALSE)
Suggested EPSG Codes
Description
Provides suggested EPSG codes for each of the 50 states. One of the NAD83 (HARN) coordinate systems for each state.
Usage
alarm_epsg(state)
Arguments
state |
A state name, abbreviation, FIPS code, or ANSI code. |
Value
A numeric EPSG code
Examples
alarm_epsg("NY")
Download maps and plans from the Japan 47-Prefecture Simulation Project
Description
These functions will download redist_map and
redist_plans objects for the Japan 47-Prefecture Simulation
Project from the ALARM Project's Dataverse. alarm_japan_doc() will
download documentation for a particular prefecture and show it in a browser.
alarm_japan_stats will download just the summary statistics for a prefecture
Usage
alarm_japan_map(pref, year = 2022, refresh = FALSE)
alarm_japan_plans(
pref,
stats = TRUE,
year = 2022,
refresh = FALSE,
compress = "xz"
)
alarm_japan_stats(pref, year = 2022, refresh = FALSE)
alarm_japan_doc(pref, year = 2022)
Arguments
pref |
A prefecture name |
year |
The redistricting cycle to download. Currently only |
refresh |
If |
stats |
If |
compress |
The compression level used for caching redist_plans objects. |
Details
The goal of the 47-Prefecture Simulation Project is to generate and analyze redistricting plans for the single-member districts of the House of Representatives of Japan using a redistricting simulation algorithm. In this project, we analyzed the partisan bias of the 2022 redistricting for 25 prefectures subject to redistricting. Our simulations are designed to comply with the that the Council abides by.
Value
For alarm_japan_map(), a redist_map. For
alarm_japan_plans(), a redist_plans. For
alarm_japan_doc(), invisibly returns the path to the HTML documentation,
and also loads an HTML file into the viewer or web browser.
For alarm_japan_stats(), a tibble.
Examples
# requires Harvard Dataverse API key
alarm_japan_map("miyagi")
alarm_japan_plans("miyagi", stats = FALSE)
alarm_japan_stats("miyagi")
alarm_japan_doc("miyagi")
map <- alarm_japan_map("miyagi")
pl <- alarm_japan_plans("miyagi")