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.