Description Usage Arguments Value Author(s) References Examples
Preps data for BISG estimation via WRU package
1 2 3 4 5 6 |
df |
data.frame() object, containing voter file information with FIPS code information extracted using unit_comb_extract() function, which brings in relevant columns |
voterid |
String of voterid column name. Default = NULL. Probably want this. |
precinct |
String of precinct column name. Default = NULL. Probably want this. |
surname_char |
String of surname_char column name. This column is passed to wru package. |
state |
String of two digit state abbreviation, e.g., "NY", or "CA". |
census.geo |
String of geographic level used for BISG. Default is Census "block". An optional character vector specifying what level of geography to use to merge in U.S. Census 2010 geographic data. Currently "county", "tract", "block", and "place" are supported. Note: sufficient information must be in user-defined voter.file object. If census.geo = "county", then voter.file must have column named county. If census.geo = "tract", then voter.file must have columns named county and tract. And if census.geo = "block", then voter.file must have columns named county, tract, and block. If census.geo = "place", then voter.file must have column named place. Specifying census.geo will call census_helper function to merge Census geographic data at specified level of geography. |
census.key |
A character object specifying user's Census API key. Required if census.geo is specified, because a valid Census API key is required to download Census geographic data. |
census.data |
A list indexed by two-letter state abbreviations, which contains pre-saved Census geographic data. Can be generated using get_census_data function from wru package. |
census.surname |
A TRUE/FALSE object. If TRUE, function will call merge_surnames to merge in Pr(Race | Surname) from U.S. Census Surname List (2000 or 2010) and Spanish Surname List. If FALSE, voter.file 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. |
surname.year |
A number to specify the year of the census surname statistics. These surname statistics is stored in the data, and will be automatically loaded. The default value is 2010, which means the surname statistics from the 2010 census will be used. Currently, the other available choice is 2000. |
age |
An optional TRUE/FALSE object specifying whether to condition race predictions on age (in addition to surname and geolocation). Default is FALSE. Must be same as age in census.data object. May only be set to TRUE if census.geo option is specified. If TRUE, voter.file should include a numerical variable age. |
sex |
optional TRUE/FALSE object specifying whether to condition race predictions on sex (in addition to surname and geolocation). Default is FALSE. Must be same as sex in census.data object. May only be set to TRUE if census.geo option is specified. If TRUE, voter.file should include a numerical variable sex, where sex is coded as 0 for males and 1 for females. |
party |
An optional character object specifying party registration field in voter.file, 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 voter.file, it should be coded as 1 for Democrat, 2 for Republican, and 0 for Other. |
retry |
The number of retries at the census website if network interruption occurs. Default = 0. |
List object of of two data.frames. List item 1 is initial voter file data.frame. List object 2 (named bisg) includes race predictions.
Loren Collingwood <loren.collingwood@ucr.edu>
wru R package. Kabir Khanna, Kosuke Imai, Hubert Jin. Imai and Khanna (2015) "Improving Ecological Inference by Predicting Individual Ethnicity from Voter Registration Records" <DOI:10.1093/pan/mpw001>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# EXAMPLE: NOT RUN #
# NOTE: You need to have a census key to run this #
data(ny_voter)
head(ny_voter)
# Load ny_census object #
# load ( system.file("extdata/ny_census.RData",package="eiCompare") )
# Now load your Census key #
# [add in here where you would do that]
# key_census = ""
####################################################
# Prep Data & Perform Bayesian Surname Geolocation #
####################################################
# Extract second list object (called bisg, note $bisg)
#bisg <- bisg_prep_race_predict(df=ny_voter,
# voterid = "Voter.ID",
# precinct = "SD..Poll",
# surname_char = "Last.Name",
# state = "NY",
# census.key = key_census,
# census.data = ny_census)$bisg
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.