Learn R Programming

⚠️There's a newer version (3.0.4) of this package.Take me there.

eiCompare

eiCompare is an R package built to help practitioners and academics quantify racially polarized voting (RPV) with ease and confidence. It builds on top of several existing packages, augmenting their utility for measuring racially polarized voting in elections. Underlying packages include ei, eiPack, wru, and censusxy.

eiCompare was built with several types of users in mind:

  • Expert witnesses in voting rights litigation who need to accurately quantify vote dilution in an area and present the results convincingly to a judge or jury.
  • National voting rights advocacy organizations trying to identify elections across the country where vote dilution might be at play.
  • Grassroots organizations looking for data-driven tools to fuel their fight against vote dilution at the local level.
  • Academics who study the causes and consequences of vote dilution and racially polarized voting.

News

3.0 Update:

The Voting Rights Team of the 2020 University of Washington Data Science for Social Good Fellowship program worked throughout the summer to develop the latest iteration of the package. Highlights from the update include:

  • Functions for geocoding addresses on voter files.
  • Improved accuracy of BISG estimation through surname preprocessing.
  • Refactored code for ecological inference functions.
  • Parallel processing to speed up ecological inference and geocoding.
  • New built-in visualizations of EI results and estimation diagnostics.
  • Performance analysis tools for comparing different election maps.
  • Functions for preprocessing address data, surname data, data for ecological inference.

See here for a full list of new features.

Installation

From CRAN

CRAN submission is currently underway. Check back soon for instructions on installation from CRAN.

From Github (development version)

Install latest development version with:

remotes::install_github('RPVote/eiCompare')

Usage

The name eiCompare highlights the utility of this package for comparing different ecological inference estimates. For instance, the following code compares iterative and RxC estimates of racial voting preferences in a stylized version of the 2018 Georgia gubernatorial election:

library(eiCompare)
data("gwinnett_ei")

iter <- ei_iter(
  data = gwinnett_ei,
  cand_cols = c("kemp", "abrams", "metz"),
  race_cols = c("white", "black", "other"),
  totals_col = "turnout",
  name = "Iterative EI",
)

rxc <- ei_rxc(
  data = gwinnett_ei,
  cand_cols = c("kemp", "abrams", "metz"),
  race_cols = c("white", "black", "other"),
  totals_col = "turnout",
  name = "RxC EI",
)

plot(iter, rxc)

The top panel shows that the majority of white voters voted for Brian Kemp, who won this election. The middle panel shows the estiamted preferences of black voters. The estimates indicate that black voters strongly preferred Stacey Abrams over Brian Kemp.

Please refer to the package vignettes for detailed walkthroughs of how this package facilitates ecological inference. To view these in Rstudio, enter browseVignettes("eiCompare") in the console after installing the package.

Learn More

Copy Link

Version

Install

install.packages('eiCompare')

Monthly Downloads

132

Version

3.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

September 18th, 2020

Functions in eiCompare (3.0.0)

corona

Corona 2014 Election Results
ei_iter

Iterative EI Estimation
fips_extract

Extract geographic unit codes from FIPS codes.
ei_rc_congruence

Congruence for 2x2
lac_10

Los Angeles County 2010 Election Results
betas_for_return

Manipulate precinct results to get betas as from ei_est_gen
ga_geo

Voter file information that has been geocoded
check_args

Check for missing essential arguments from an ei function
lambda_two_compare

Lambda Two Compare
bayes_table_make

EI:RxC Bayes Table Make
add_split_comma

Pre-processes voter file by checking zipcode, and any special characters or typos within the address.
ei_rc_good_table

Create EI Comparison Table
latlong2fips

Latitude-Longitude Coordinates to FIPS Geocode
map_interactive

This function allows the user to plot an interactive map of the voter longitude and latitude points.
ei_reg_bayes_conf_int

Creates EI Reg Bayes Tables
get_md_bayes_gen_output

Get md_bayes_gen() output from ei_rxc() output
ei_est_gen

Iterative EI Estimation
ei_rxc

EI Bayesian simultaneous estimation for multiple races and candidates
ei_compare-class

Class "ei_compare"
goodman_generalize

Goodman Regression Generalization
get_multi_barreled_surnames

Gets multi-barreled surnames from a voter file.
ny_fips

New York State FIPS codes
map_shape_file

Function for making basic choropleth maps of shape_file using the tigris package and ggplot
elect_algebra

Election Algebra for 2x2 Case
gwin_fulton_shape

Shape file information for Gwinnett and Fulton counties in Georgia
get_unique_special_characters

Gets special characters in a column of names.
ny_voter

New York Voter File Sample
resolve_missing_vals

Remove / Impute NAs in an EI dataset
map_shape_points

Function for making basic choropleth maps of longitude and latitude points using the tigris package and ggplot
concat_streetname

Pre-processes voter file by checking zipcode, and any special characters or typos within the address.
cor_06

Corona 2006 Election Results
get_word_count

Counts the number of words per row in the column of a dataframe.
md_bayes_gen

MD Bayes Generalize
md_bayes_table

MD Bayes Generalize Table Creation
rockland_census

Rockland County, NY, Census demographic dataset.
mean_and_ci

mean_and_ci
merge_voter_file_to_shape

Merges a voter file to a shape file.
dedupe_voter_file

De-duplicates a voter file.
plot.eiCompare

Print a plot comparing the predictions of EI outputs.
empty_ei_df

Create a dataframe with NA values for racial and candidate counts.
sum_over_cols

Sum row-wise over columns in a dataframe
eiCompare-package

Compares EI, Goodman, RxC Estimates
ramapo2018

East Ramapo School District 2018 Voter File
summary.eiCompare

Print a summary of an eiCompare object
get_results_table

Get results dataframe from a list of results as from ei_est_gen
ersd_maps

East Ramapo School District Proposed Maps
get_special_character_surnames

Gets surnames containing special characters.
plot_bivariate

Plot bivariate relationships between all combinations of candidates and race/ethnicities
race_cand_cors

Table of bivariate correlations
race_check_2_3

race_check_2_3
mbd_two

Multinomial Dirichlet Bayes Draw Two Candidates
remove_nas

Remove missing values from dataset and return warning if any removed
standardize_votes

Computes proportions for returning by clean_race and clean_cand
mbd_two_minority

Multinomial Dirichlet Bayes Draw Two Candidates, and White/Minority voters
performance_analysis

Performs a performance analysis using a voter file, census shape, and district shape.
check_diffs

Internal function that checks for adequate closeness between sums of race/candidate columns and provided vote totals.
split_add_nocommas

Pre-processes voter file by checking zipcode, and any special characters or typos within the address.
rxc_formula

Make rxc formula
%>%

Pipe operator
zip_hyphen

Pre-processes voter file by checking zipcode, and any special characters or typos within the address.
precinct_agg_combine

Aggregates racial estimates across geographic units
stdize_votes_all

stdize_votes_all
predict_race_multi_barreled

Predicts, for one row in a voter file, the probability of a voter having a certain race by averaging over each "barrel" of the surname.
strip_special_characters

Strips special characters from a voter file.
ei_good

EI iterative estimation via Goodman's Regression
stdize_votes

stdize_votes
concat_final_address

This function concatenate the final address
ei_homog

Homogeneous Precinct Analysis
georgia_census

Fulton County and Gwinnett County, GA, Census demographic dataset.
get_ei_iter_se

Get 2x2 ei standard errors from ei object Works according to the aggregate formula in King, 1997, section 8.3
md_bayes_draw

MD Bayes Draw
gwinnett

Election results and racial turnout data for Gwinnett County, Georgia, US
gwinnett_ei

Stylized dataset of election results and turnout by race in Gwinnett county, 2018 Georgia gubernatorial election.
md_bayes_draw_lambda

MD Bayes Draw Lambda
od_plot_create

od_plot_create
overlay_density_plot

overlay_density_plot
rpv_density

rpv_density
run_geocoder

Geocoding voter file addresses with coordinates (latitude and longitude) and/or census geographies.
surname_summary

Briefly summarizes the surnames in a voter file.
surname_match

Determines which surnames match to the Census list.
tidy_voter_file_wru

Tidies a voter file for WRU.
wru_predict_race_wrapper

Prepares a voter file for the WRU predict_race function, and then predicts race.
dedupe_precincts

Remove or identify duplicated precincts