Learn R Programming

wru (version 0.1-1)

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, census.data = NA)

Arguments

voters
An object of class data.frame. Must contain a row for each individual being predicted, as well as a field named surname containing each individual's surname. If using geolocation in predictions, voters must contain a field named state, which contains the two-character abbreviation for each individual's state of residence (e.g., "nj" for New Jersey). If using geolocation, voters must also contain at least one of the following fields: county, tract, and/or block. These fields should contain character strings matching U.S. Census categories. County is three characters (e.g., "031" not "31"), tract is six characters, and block is four characters. See below for other optional fields.
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 additional 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. Can be one of "county", "tract", or "block". Function calls census.helper.api to merge in Census data at specified level. If left unspecified, voters must contain additional 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. Required if census is specified, because 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 (in addition to geolocation). Default is FALSE. May only be set to TRUE if census option is specified. If TRUE, voters should include numerical variables age and sex, where sex coded as 0 for males and 1 for females.
party
An optional character object specifying party registration field in voters, e.g., party = "PartyReg". If specified, race/ethnicity predictions will be conditioned on individual's party registration (in addition to geolocation). Whatever the name of the party registration field in voters, it should be coded as 1 for Democrat, 2 for Republican, and 0 for Other.
census.data
A census data object, a list indexed by state names, which contains census data on demo, county, tract and block.

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 probabilistic 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)
## Not run: race.pred(voters = voters, races = c("white", "black", "latino", "asian", "other"), 
# census = "tract", census.data = censusObjs, party = "PID")## End(Not run)

Run the code above in your browser using DataLab