Learn R Programming

eiCompare (version 3.0.4)

stdize_votes: stdize_votes

Description

Converts raw vote totals from different voter groups / candidates across precincts into proportions, checking for problematic differences between known vote totals and sums across race/ethnicities.

Usage

stdize_votes(
  data,
  cols,
  totals_col = NULL,
  max_dev = 0.1,
  avg_dev = 0.025,
  new_names = FALSE,
  verbose = TRUE,
  diagnostic = FALSE
)

Value

A dataframe with proportions corresponding to the turnout of each race/ethnicity group

Arguments

data

A dataframe of election results, where each row represents a precinct or geographic voting unit

cols

A character vector with the names of the columns indicating total votes cast by each race, or for each candidate

totals_col

A character string with the name of the total vote count column in the data. If null, total votes are computed within the function

max_dev

A numeric object setting the max allowable deviation of a precinct's vote sum from totals

avg_dev

A numeric object setting the max allowable average deviation difference of all precints' vote sums from totals

new_names

A boolean indicating whether to return cand and race columns with the same names. If FALSE, names returned with "_prop" added on.

verbose

A boolean indicating whether to print status messages

diagnostic

A boolean. When true, an extra column of booleans is returned indicating whether each row had a deviation from totals

Author

Ari Decter-Frain

Details

If turnout columns sum row-wise to equal vote_totals, they are returned as proportions.

If turnout columns sum row-wise to sufficiently close to vote_totals, they are returned as proportions of the sums.

If turnout columns sum row-wise exceedingly far from vote_totals, the function stops and returns an error message.