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, and wru.

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

eiCompare 3.0.4

*Fixed a bug in tests/testthat/test_wru_predict_race_wrapper.R that fails if there isnt internet to access wru repo data

eiCompare 3.0.3

  • Added handling of connection errors from wru, to comply with CRAN policy on graceful failure when accessing internet resources that have changed or become unavailable.

eiCompare 3.0.2

Package changes

  • Removed geocoding helpers from package. These are mostly trivial to code separately and added extra dependencies to the package. Change instigated by update to previous dependency censusxy.

eiCompare 3.0.1

Minor package changes

  • Switched maintainer from Loren Collingwood to Ari Decter-Frain (@aridf)
  • Minor changes to functions dependent on wru to ensure compatibility with new version

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.

Platform dependencies

The following platform dependencies may be required on Ubuntu/Debian based systems: sudo apt install libfftw3-dev fftw-dev

Learn More

Copy Link

Version

Install

install.packages('eiCompare')

Monthly Downloads

132

Version

3.0.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

August 31st, 2023

Functions in eiCompare (3.0.4)

ei_compare-class

Class "ei_compare"
ei_rc_good_table

Create EI Comparison Table
get_ei_iter_se

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

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

Multinomial Dirichlet Bayes Draw Two Candidates
mbd_two_minority

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

EI Bayesian simultaneous estimation for multiple races and candidates
gwinnett_ei

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

Extract geographic unit codes from FIPS codes.
ga_geo

Voter file information that has been geocoded
lac_10

Los Angeles County 2010 Election Results
ersd_maps

East Ramapo School District Proposed Maps
ei_good

EI iterative estimation via Goodman's Regression
get_word_count

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

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

Goodman Regression Generalization
get_multi_barreled_surnames

Gets multi-barreled surnames from a voter file.
md_bayes_gen

MD Bayes Generalize
md_bayes_table

MD Bayes Generalize Table Creation
gwin_fulton_shape

Shape file information for Gwinnett and Fulton counties in Georgia
od_plot_create

od_plot_create
overlay_density_plot

overlay_density_plot
plot.eiCompare

Print a plot comparing the predictions of EI outputs.
gwinnett

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

mean_and_ci
ny_voter

New York Voter File Sample
ny_fips

New York State FIPS codes
rpv_density

rpv_density
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.
resolve_missing_vals

Remove / Impute NAs in an EI dataset
rxc_formula

Make rxc formula
precinct_agg_combine

Aggregates racial estimates across geographic units
rockland_census

Rockland County, NY, Census demographic dataset.
surname_match

Determines which surnames match to the Census list.
surname_summary

Briefly summarizes the surnames in a voter file.
race_cand_cors

Table of bivariate correlations
race_check_2_3

race_check_2_3
sum_over_cols

Sum row-wise over columns in a dataframe
plot_bivariate

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

stdize_votes_all
latlong2fips

Latitude-Longitude Coordinates to FIPS Geocode
md_bayes_draw

MD Bayes Draw
merge_voter_file_to_shape

Merges a voter file to a shape file.
tidy_voter_file_wru

Tidies a voter file for WRU.
summary.eiCompare

Print a summary of an eiCompare object
lambda_two_compare

Lambda Two Compare
%>%

Pipe operator
get_md_bayes_gen_output

Get md_bayes_gen() output from ei_rxc() output
performance_analysis

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

Strips special characters from a voter file.
md_bayes_draw_lambda

MD Bayes Draw Lambda
wru_predict_race_wrapper

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

Computes proportions for returning by clean_race and clean_cand
remove_nas

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

stdize_votes
ramapo2018

East Ramapo School District 2018 Voter File
bayes_table_make

EI:RxC Bayes Table Make
betas_for_return

Manipulate precinct results to get betas as from ei_est_gen
check_args

Check for missing essential arguments from an ei function
corona

Corona 2014 Election Results
dedupe_precincts

Remove or identify duplicated precincts
dedupe_voter_file

De-duplicates a voter file.
check_diffs

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

Compares EI, Goodman, RxC Estimates
cor_06

Corona 2006 Election Results
ei_homog

Homogeneous Precinct Analysis
ei_est_gen

Iterative EI Estimation
ei_iter

Iterative EI Estimation
elect_algebra

Election Algebra for 2x2 Case
empty_ei_df

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

Creates EI Reg Bayes Tables
ei_rc_congruence

Congruence for 2x2
get_special_character_surnames

Gets surnames containing special characters.
get_unique_special_characters

Gets special characters in a column of names.