Title: | 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. |
Authors: | Cory McCartan [aut, cre] |
Maintainer: | Cory McCartan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.2 |
Built: | 2024-08-11 03:05:43 UTC |
Source: | https://github.com/alarm-redist/alarmdata |
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.
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)
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)
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. |
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.
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.
# 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")
# 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")
Facilitates comparing an existing (i.e., non-simulated) redistricting plan to a set of simulated plans.
alarm_add_plan( plans, ref_plan, map = NULL, name = NULL, calc_polsby = FALSE, GEOID = "GEOID", year = 2020 )
alarm_add_plan( plans, ref_plan, map = NULL, name = NULL, calc_polsby = FALSE, GEOID = "GEOID", year = 2020 )
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 |
A modified redist_plans
object containing the reference plan. Includes summary statistics if the original redist_plans
object had them as well.
# 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")
# 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")
alarmdata
cacheFunctions to inspect and clear the cache. If the cache is not enabled, uses a temporary directory.
alarm_cache_size() alarm_cache_clear(force = FALSE) alarm_cache_path()
alarm_cache_size() alarm_cache_clear(force = FALSE) alarm_cache_path()
force |
FALSE by default. Asks the user to confirm if interactive. Does not clear cache if force is FALSE and not interactive. |
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
alarm_cache_size() alarm_cache_clear() alarm_cache_path()
alarm_cache_size() alarm_cache_clear() alarm_cache_path()
Downloads Census data joined with VEST's election data. All are re-tabulated from precincts collected by VEST to 2020 Census geographies.
alarm_census_vest(state, geometry = FALSE, epsg = alarm_epsg(state))
alarm_census_vest(state, geometry = FALSE, epsg = alarm_epsg(state))
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 |
tibble with Census and election data
alarm_census_vest("DE", geometry = FALSE)
alarm_census_vest("DE", geometry = FALSE)
Provides suggested EPSG codes for each of the 50 states. One of the NAD83 (HARN) coordinate systems for each state.
alarm_epsg(state)
alarm_epsg(state)
state |
A state name, abbreviation, FIPS code, or ANSI code. |
A numeric EPSG code
alarm_epsg("NY")
alarm_epsg("NY")