Title: | Download, Merge, and Process Redistricting Data |
Version: | 0.2.1 |
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. |
Depends: | R (≥ 3.10) |
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.2.3 |
Language: | en-US |
NeedsCompilation: | no |
Packaged: | 2024-02-27 19:23:24 UTC; cmccartan |
Author: | Cory McCartan |
Maintainer: | Cory McCartan <corymccartan@nyu.edu> |
Repository: | CRAN |
Date/Publication: | 2024-02-28 18:30:08 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.
Author(s)
Maintainer: Cory McCartan corymccartan@nyu.edu (ORCID)
Authors:
Christopher T. Kenny christopherkenny@fas.harvard.edu (ORCID)
Tyler Simko tsimko@g.harvard.edu (ORCID)
Michael Zhao michaelzhao@college.harvard.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 integer vector containing the reference plan or a block assignment file as a |
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. Ignored unless |
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")