Learn R Programming

wru (version 0.0-2)

race.pred: Race prediction function.

Description

race.pred makes probabilistic estimates of individual-level race/ethnicity.

Usage

race.pred(voters, races = c("white", "black", "latino", "asian", "other"), name.clean = TRUE, surname.only = FALSE, census = "", census.key = "", demo = FALSE, party)

Arguments

voters
An object of class data.frame. Must contain a field for surname (surname). Optional fields include Census tract (tract), Census block (block), party registration (party), age (age), and sex (sex).
races
A character vector specifying which racial groups to generate predicted probabilities for. Can include any subset of the default vector, which is c("white", "black", "latino", "asian", "other").
name.clean
A TRUE/FALSE object. If TRUE, function will call name.clean to merge in data from U.S. Census 2000 Surname List and Spanish Surname List. If FALSE, voters object must contain fields specifying Pr(Race | Surname), named as follows: p_whi for Whites, p_bla for Blacks, p_his for Hispanics/Latinos, p_asi for Asians, and/or p_oth for Other. Default is TRUE.
surname.only
A TRUE/FALSE object. If TRUE, race predictions will only use surname data and calculate Pr(Race | Surnname). Default is FALSE
census
An optional character vector specifying what level of geography to use to merge in U.S. Census 2010 data. Currently only tract and "block" are supported. If "tract" or "block" is specified, function will call census.helper.api to merge in tract- or block- level data. If left unspecified, voters must contain fields specifying Pr(Geolocation | Race), including any of the following: r_whi, r_bla, r_his, r_asi, and/or r_oth.
census.key
A character object specifying user's Census API key. Must be specified if census is specified, because the census.helper function requires a Census API key to operate.
demo
An optional TRUE/FALSE object specifying whether to condition race predictions on individual age and sex. If TRUE, voters should include numerical variables age and sex, where sex coded as 0 for males and 1 for females. Default is FALSE. May only be set to TRUE when census is specified.
party
An optional character object specifying party registration field. Party registration should be coded as 1 for Democrat, 2 for Republican, and 0 for Other.

Value

Output will be an object of class data.frame. It will consist of the original user-input data with additional columns that contain predicted probabilities for each race in races.

Details

This function implements the Bayesian race prediction methods outlined in Imai and Khanna (2015). The function produces probabilistics estimates of individual-level race/ethnicity, based on surname, geolocation, and party.

Examples

Run this code
data(voters)
race.pred(voters = voters, races = c("asian"), surname.only = TRUE)
## Not run: race.pred(voters = voters, races = c("white", "black", "latino"), 
# census = "tract", census.key = "...", demo = TRUE)## End(Not run)
## Not run: race.pred(voters = voters, races = c("white", "black", "latino", "asian", "other"), 
# census = "tract", census.key = "...", party = "PID")## End(Not run)

Run the code above in your browser using DataLab