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.
stdize_votes(
data,
cols,
totals_col = NULL,
max_dev = 0.1,
avg_dev = 0.025,
new_names = FALSE,
verbose = TRUE,
diagnostic = FALSE
)
A dataframe with proportions corresponding to the turnout of each race/ethnicity group
A dataframe of election results, where each row represents a precinct or geographic voting unit
A character vector with the names of the columns indicating total votes cast by each race, or for each candidate
A character string with the name of the total vote count column in the data. If null, total votes are computed within the function
A numeric object setting the max allowable deviation of a precinct's vote sum from totals
A numeric object setting the max allowable average deviation difference of all precints' vote sums from totals
A boolean indicating whether to return cand and race columns with the same names. If FALSE, names returned with "_prop" added on.
A boolean indicating whether to print status messages
A boolean. When true, an extra column of booleans is returned indicating whether each row had a deviation from totals
Ari Decter-Frain
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.